@conduit-client/model 3.7.0 → 3.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/dist/types/v1/index.d.ts +2 -1
  2. package/dist/types/v1/parser/__tests__/test-utils.d.ts +433 -0
  3. package/dist/types/v1/{amf → parser/amf}/AMFAPI.d.ts +3 -5
  4. package/dist/types/v1/{amf → parser/amf}/amf-api-service.d.ts +1 -8
  5. package/dist/types/v1/{amf → parser/amf}/amf-utils.d.ts +1 -1
  6. package/dist/types/v1/{amf → parser/amf}/endpoints/amf-endpoint.d.ts +2 -2
  7. package/dist/types/v1/{amf → parser/amf}/endpoints/amf-operation.d.ts +314 -314
  8. package/dist/types/v1/{amf → parser/amf}/index.d.ts +0 -1
  9. package/dist/types/v1/{amf → parser/amf}/types/AMFAllOfType.d.ts +2 -2
  10. package/dist/types/v1/{amf → parser/amf}/types/AMFAnyType.d.ts +1 -1
  11. package/dist/types/v1/{amf → parser/amf}/types/AMFArrayType.d.ts +1 -1
  12. package/dist/types/v1/{amf → parser/amf}/types/AMFBaseType.d.ts +2 -2
  13. package/dist/types/v1/{amf → parser/amf}/types/AMFDiscriminatedObjectType.d.ts +2 -2
  14. package/dist/types/v1/{amf → parser/amf}/types/AMFEnumType.d.ts +3 -3
  15. package/dist/types/v1/{amf → parser/amf}/types/AMFNilType.d.ts +1 -1
  16. package/dist/types/v1/{amf → parser/amf}/types/AMFNotType.d.ts +3 -3
  17. package/dist/types/v1/{amf → parser/amf}/types/AMFObjectType.d.ts +1 -1
  18. package/dist/types/v1/{amf → parser/amf}/types/AMFOneOfType.d.ts +1 -1
  19. package/dist/types/v1/{amf → parser/amf}/types/AMFRefType.d.ts +1 -1
  20. package/dist/types/v1/{amf → parser/amf}/types/AMFScalarTypes.d.ts +3 -3
  21. package/dist/types/v1/parser/amf/types/__tests__/AMFOneOfType.spec.d.ts +1 -0
  22. package/dist/types/v1/parser/amf/types/__tests__/AMFScalarType.spec.d.ts +1 -0
  23. package/dist/types/v1/{amf → parser/amf}/types/factory.d.ts +2 -2
  24. package/dist/types/v1/{amf → parser/amf}/types/index.d.ts +1 -2
  25. package/dist/types/v1/parser/parser-utils.d.ts +10 -0
  26. package/dist/types/v1/parser/zod-schemas.d.ts +445 -0
  27. package/dist/v1/index.js +1847 -1819
  28. package/dist/v1/index.js.map +1 -1
  29. package/package.json +3 -3
  30. package/dist/types/v1/amf/__tests__/test-utils.d.ts +0 -211
  31. package/dist/types/v1/amf/types/annotations-schemas.d.ts +0 -172
  32. /package/dist/types/v1/{amf/types → parser}/__tests__/annotations-schemas.spec.d.ts +0 -0
  33. /package/dist/types/v1/{amf/__tests__/AMFAPI.spec.d.ts → parser/__tests__/parser-api.spec.d.ts} +0 -0
  34. /package/dist/types/v1/{amf/__tests__/amf-api-service.spec.d.ts → parser/__tests__/parser-utils.spec.d.ts} +0 -0
  35. /package/dist/types/v1/{amf/__tests__/amf-extensions-services.spec.d.ts → parser/__tests__/type-factory.spec.d.ts} +0 -0
  36. /package/dist/types/v1/{amf/__tests__/amf-extensions.spec.d.ts → parser/amf/__tests__/AMFAPI.spec.d.ts} +0 -0
  37. /package/dist/types/v1/{amf/__tests__/amf-utils.spec.d.ts → parser/amf/__tests__/amf-api-service.spec.d.ts} +0 -0
  38. /package/dist/types/v1/{amf/__tests__/parser.spec.d.ts → parser/amf/__tests__/amf-extensions-services.spec.d.ts} +0 -0
  39. /package/dist/types/v1/{amf/__tests__/validation.spec.d.ts → parser/amf/__tests__/amf-extensions.spec.d.ts} +0 -0
  40. /package/dist/types/v1/{amf/__tests__/version.spec.d.ts → parser/amf/__tests__/amf-utils.spec.d.ts} +0 -0
  41. /package/dist/types/v1/{amf/endpoints/__tests__/amf-endpoint.spec.d.ts → parser/amf/__tests__/parser.spec.d.ts} +0 -0
  42. /package/dist/types/v1/{amf/endpoints/__tests__/amf-operation.spec.d.ts → parser/amf/__tests__/validation.spec.d.ts} +0 -0
  43. /package/dist/types/v1/{amf/types/__tests__/AMFAnyType.spec.d.ts → parser/amf/__tests__/version.spec.d.ts} +0 -0
  44. /package/dist/types/v1/{amf → parser/amf}/amf-extensions.d.ts +0 -0
  45. /package/dist/types/v1/{amf/types/__tests__/AMFArrayType.spec.d.ts → parser/amf/endpoints/__tests__/amf-endpoint.spec.d.ts} +0 -0
  46. /package/dist/types/v1/{amf/types/__tests__/AMFBaseType.spec.d.ts → parser/amf/endpoints/__tests__/amf-operation.spec.d.ts} +0 -0
  47. /package/dist/types/v1/{amf → parser/amf}/parser.d.ts +0 -0
  48. /package/dist/types/v1/{amf/types/__tests__/AMFDiscriminatedObjectType.spec.d.ts → parser/amf/types/__tests__/AMFAnyType.spec.d.ts} +0 -0
  49. /package/dist/types/v1/{amf/types/__tests__/AMFEnumType.spec.d.ts → parser/amf/types/__tests__/AMFArrayType.spec.d.ts} +0 -0
  50. /package/dist/types/v1/{amf/types/__tests__/AMFNilType.spec.d.ts → parser/amf/types/__tests__/AMFBaseType.spec.d.ts} +0 -0
  51. /package/dist/types/v1/{amf/types/__tests__/AMFNotType.spec.d.ts → parser/amf/types/__tests__/AMFDiscriminatedObjectType.spec.d.ts} +0 -0
  52. /package/dist/types/v1/{amf/types/__tests__/AMFObjectType.spec.d.ts → parser/amf/types/__tests__/AMFEnumType.spec.d.ts} +0 -0
  53. /package/dist/types/v1/{amf/types/__tests__/AMFOneOfType.spec.d.ts → parser/amf/types/__tests__/AMFNilType.spec.d.ts} +0 -0
  54. /package/dist/types/v1/{amf/types/__tests__/AMFScalarType.spec.d.ts → parser/amf/types/__tests__/AMFNotType.spec.d.ts} +0 -0
  55. /package/dist/types/v1/{amf/types/__tests__/factory.spec.d.ts → parser/amf/types/__tests__/AMFObjectType.spec.d.ts} +0 -0
  56. /package/dist/types/v1/{amf → parser/amf}/validation.d.ts +0 -0
  57. /package/dist/types/v1/{amf → parser/amf}/version.d.ts +0 -0
package/dist/v1/index.js CHANGED
@@ -3,9 +3,9 @@
3
3
  * All rights reserved.
4
4
  * For full license text, see the LICENSE.txt file
5
5
  */
6
- import path from "path";
7
- import amf from "amf-client-js";
8
6
  import * as url from "url";
7
+ import amf from "amf-client-js";
8
+ import path from "path";
9
9
  const BindingTypesEnum = ["wire", "imperative", "imperative-legacy", "mutation"];
10
10
  class BaseTypeRegistry extends Map {
11
11
  nameOf(t) {
@@ -336,7 +336,11 @@ function isTypeUsableAsKey(type, seenTypes = /* @__PURE__ */ new Set()) {
336
336
  return result;
337
337
  }
338
338
  function isNullableType(type) {
339
- const concreteType = getConcreteTypeFromRef(type);
339
+ const concreteTypeResult = getConcreteTypeFromRef(type);
340
+ if (concreteTypeResult.isErr()) {
341
+ return void 0;
342
+ }
343
+ const concreteType = concreteTypeResult.value;
340
344
  if (isNilType(concreteType)) {
341
345
  return true;
342
346
  } else if (isOneOfType(concreteType)) {
@@ -348,10 +352,15 @@ function isNullableType(type) {
348
352
  }
349
353
  function getConcreteTypeFromRef(type) {
350
354
  let concreteType = type;
355
+ let seenTypes = /* @__PURE__ */ new Set();
351
356
  while (isRefType(concreteType)) {
357
+ if (seenTypes.has(concreteType)) {
358
+ return err({ type: concreteType, seenTypes });
359
+ }
360
+ seenTypes.add(concreteType);
352
361
  concreteType = concreteType.$ref;
353
362
  }
354
- return concreteType;
363
+ return ok(concreteType);
355
364
  }
356
365
  class KeySourcesValidator {
357
366
  constructor(types, sources) {
@@ -507,9 +516,29 @@ class KeySourcesValidator {
507
516
  return result ? ok(messages) : err(messages);
508
517
  }
509
518
  validateAccessors(type, propName, accessors) {
510
- const concreteType = getConcreteTypeFromRef(type);
519
+ const concreteTypeResult = getConcreteTypeFromRef(type);
520
+ if (concreteTypeResult.isErr()) {
521
+ return err([
522
+ getFormattedMessage$1(
523
+ type,
524
+ `Unwrapping refs for type "${this.getNameOf(concreteTypeResult.error.type)}" led to the following types in an infinite loop: [${Array.from(
525
+ concreteTypeResult.error.seenTypes
526
+ ).map((t) => this.getNameOf(t)).join(", ")}].`
527
+ )
528
+ ]);
529
+ }
530
+ const concreteType = concreteTypeResult.value;
511
531
  if (isOneOfType(concreteType) || isAllOfType(concreteType) || isDiscriminatedObjectType(concreteType) || isObjectType(concreteType)) {
512
- if (isNullableType(concreteType)) {
532
+ const isNullable = isNullableType(concreteType);
533
+ if (isNullable === void 0) {
534
+ return err([
535
+ getFormattedMessage$1(
536
+ type,
537
+ `Unwrapping refs for type "${this.getNameOf(concreteType)}" led to an infinite loop.`
538
+ )
539
+ ]);
540
+ }
541
+ if (isNullable) {
513
542
  return err([
514
543
  getFormattedMessage$1(
515
544
  concreteType,
@@ -940,58 +969,322 @@ class InvalidationValidator {
940
969
  return null;
941
970
  }
942
971
  }
943
- var util;
944
- (function(util2) {
945
- util2.assertEqual = (val) => val;
946
- function assertIs(_arg) {
947
- }
948
- util2.assertIs = assertIs;
949
- function assertNever(_x) {
950
- throw new Error();
951
- }
952
- util2.assertNever = assertNever;
953
- util2.arrayToEnum = (items) => {
954
- const obj = {};
955
- for (const item of items) {
956
- obj[item] = item;
957
- }
958
- return obj;
972
+ const V1_VERSION = "1.0.0";
973
+ const ANONYMOUS_TYPE_NAME = "<anonymous>";
974
+ function asAPIService(api) {
975
+ const p = Promise.resolve(api);
976
+ return {
977
+ build: () => p,
978
+ api
959
979
  };
960
- util2.getValidEnumValues = (obj) => {
961
- const validKeys = util2.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
962
- const filtered = {};
963
- for (const k of validKeys) {
964
- filtered[k] = obj[k];
980
+ }
981
+ class NoNormalizedTypesValidator {
982
+ constructor(types) {
983
+ this.types = types;
984
+ }
985
+ validate(operation) {
986
+ if (isNormalizedOperation(operation)) {
987
+ return ok([]);
965
988
  }
966
- return util2.objectValues(filtered);
967
- };
968
- util2.objectValues = (obj) => {
969
- return util2.objectKeys(obj).map(function(e) {
970
- return obj[e];
989
+ const identifiableTypes = /* @__PURE__ */ new Set();
990
+ operation.responses.forEach((response) => {
991
+ return response.payloads.forEach((payload) => {
992
+ this.findNestedIdentifiableTypes(payload.data).forEach(
993
+ (type) => identifiableTypes.add(type)
994
+ );
995
+ });
971
996
  });
972
- };
973
- util2.objectKeys = typeof Object.keys === "function" ? (obj) => Object.keys(obj) : (object) => {
974
- const keys = [];
975
- for (const key in object) {
976
- if (Object.prototype.hasOwnProperty.call(object, key)) {
977
- keys.push(key);
997
+ const messages = [];
998
+ if (identifiableTypes.size > 0) {
999
+ identifiableTypes.forEach((type) => {
1000
+ const typeName = this.types.nameOf(type) || ANONYMOUS_TYPE_NAME;
1001
+ messages.push(
1002
+ getFormattedMessage(
1003
+ operation,
1004
+ `Operation ${operation.operationId ? `${operation.operationId} ` : ``}is not normalized but references the normalized type ${typeName} in its response`
1005
+ )
1006
+ );
1007
+ });
1008
+ return messages.length === 0 ? ok([]) : err(messages);
1009
+ }
1010
+ return ok([]);
1011
+ }
1012
+ /**
1013
+ * Completes a breadth-first search of a Type to locate any nested types that are identifiable.
1014
+ *
1015
+ * @returns a Set of all nested types that are identifiable.
1016
+ * @param start
1017
+ * @protected
1018
+ */
1019
+ findNestedIdentifiableTypes(start) {
1020
+ return bfs(
1021
+ [start],
1022
+ (type) => {
1023
+ var _a;
1024
+ return ((_a = type.extensions) == null ? void 0 : _a.type) === "identifiable";
1025
+ },
1026
+ (type) => {
1027
+ const typing = type.type;
1028
+ switch (typing) {
1029
+ case "allOf":
1030
+ return type.allOf;
1031
+ case "array":
1032
+ return [type.items];
1033
+ case "object":
1034
+ return [
1035
+ ...Object.values(type.properties).map((property) => property.type),
1036
+ type.additionalProperties
1037
+ ];
1038
+ case "oneOf":
1039
+ return type.oneOf;
1040
+ case "ref":
1041
+ return [type.$ref];
1042
+ case "discriminatedObject":
1043
+ return [...Object.values(type.mapping), type.baseType];
1044
+ case "any":
1045
+ case "enum":
1046
+ case "boolean":
1047
+ case "double":
1048
+ case "integer":
1049
+ case "number":
1050
+ case "string":
1051
+ case "date":
1052
+ case "datetime":
1053
+ case "datetime-only":
1054
+ case "nil":
1055
+ case "not":
1056
+ case "time":
1057
+ return [];
1058
+ default:
1059
+ throw new Error(
1060
+ `${typing} has not been accounted for when searching for nested identifiable types`
1061
+ );
1062
+ }
978
1063
  }
1064
+ );
1065
+ }
1066
+ }
1067
+ class KeyMatchValidator {
1068
+ constructor(types) {
1069
+ this.types = types;
1070
+ }
1071
+ validate(operation) {
1072
+ if (!isNormalizedOperation(operation)) {
1073
+ return ok([]);
979
1074
  }
980
- return keys;
1075
+ const operationHasKey = !!operation.cacheStrategy.key;
1076
+ let valid = true;
1077
+ const messages = [];
1078
+ operation.responses.forEach((response) => {
1079
+ response.payloads.forEach((payload) => {
1080
+ var _a, _b;
1081
+ if (((_a = payload.data.extensions) == null ? void 0 : _a.type) === "identifiable") {
1082
+ const typeName = this.types.nameOf(payload.data) || ANONYMOUS_TYPE_NAME;
1083
+ if (!operationHasKey) {
1084
+ valid = false;
1085
+ messages.push(
1086
+ getFormattedMessage(
1087
+ operation,
1088
+ `Operation ${operation.operationId ? `${operation.operationId} ` : ``}is missing a key to match against its ${typeName} response type`
1089
+ )
1090
+ );
1091
+ } else if (!((_b = payload.data.extensions.key) == null ? void 0 : _b.fields)) {
1092
+ valid = false;
1093
+ messages.push(
1094
+ getFormattedMessage(
1095
+ operation,
1096
+ `Operation ${operation.operationId ? `${operation.operationId} ` : ``}has a key but its ${typeName} response type doesn't have one to match against`
1097
+ )
1098
+ );
1099
+ } else if (!deepEquals(
1100
+ Object.keys(operation.cacheStrategy.key || {}),
1101
+ Object.keys(payload.data.extensions.key.fields)
1102
+ )) {
1103
+ valid = false;
1104
+ messages.push(
1105
+ getFormattedMessage(
1106
+ operation,
1107
+ `Operation ${operation.operationId ? `${operation.operationId} ` : ``}and its ${typeName} response type have mismatched keys`
1108
+ )
1109
+ );
1110
+ }
1111
+ }
1112
+ });
1113
+ });
1114
+ return valid ? ok(messages) : err(messages);
1115
+ }
1116
+ }
1117
+ class BodyDataValidator {
1118
+ constructor(target, keys, keySourcesValidatorSupplier) {
1119
+ this.target = target;
1120
+ this.keys = keys;
1121
+ this.keySourcesValidatorSupplier = keySourcesValidatorSupplier;
1122
+ }
1123
+ validate(operation) {
1124
+ if (this.keys.length === 0) {
1125
+ return ok([]);
1126
+ }
1127
+ const jsonPayload = this.target.payloads.find((p) => p.mediaType === "application/json");
1128
+ if (jsonPayload === void 0) {
1129
+ return err([
1130
+ getFormattedMessage(
1131
+ operation,
1132
+ `Use of 'body' keys requires a json payload: ${operation.method} ${operation.endpoint.path} has none.`
1133
+ )
1134
+ ]);
1135
+ }
1136
+ const result = this.keySourcesValidatorSupplier(this.keys).validate(jsonPayload.data);
1137
+ if (!result.isOk()) {
1138
+ const message = getFormattedMessage(
1139
+ operation,
1140
+ `Invalid body key(s) specified for ${operation.operationId || `${operation.method} ${operation.endpoint.path}`}`
1141
+ );
1142
+ message.subValidationMessages = result.error;
1143
+ return err([message]);
1144
+ }
1145
+ return ok([]);
1146
+ }
1147
+ }
1148
+ function buildOperationValidator(api) {
1149
+ const bodyDateValidatorSupplier = (target, sources) => {
1150
+ return new BodyDataValidator(target, sources, (keys) => {
1151
+ return new KeySourcesValidator(api.types, keys);
1152
+ });
981
1153
  };
982
- util2.find = (arr, checker) => {
983
- for (const item of arr) {
984
- if (checker(item))
985
- return item;
1154
+ return compose([
1155
+ new InvalidationValidator(api.types, bodyDateValidatorSupplier),
1156
+ new KeySourceValidator(bodyDateValidatorSupplier),
1157
+ new Response200Validator(),
1158
+ new NoNormalizedTypesValidator(api.types),
1159
+ new KeyMatchValidator(api.types)
1160
+ ]);
1161
+ }
1162
+ function buildEndpointValidator(api) {
1163
+ const operationValidator = buildOperationValidator(api);
1164
+ return {
1165
+ validate(subject) {
1166
+ return combineValidationResults(
1167
+ subject.operations.map((operation) => operationValidator.validate(operation))
1168
+ );
986
1169
  }
987
- return void 0;
988
1170
  };
989
- util2.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && isFinite(val) && Math.floor(val) === val;
990
- function joinValues(array, separator = " | ") {
991
- return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
1171
+ }
1172
+ class BindingsValidation {
1173
+ constructor() {
992
1174
  }
993
- util2.joinValues = joinValues;
994
- util2.jsonStringifyReplacer = (_, value) => {
1175
+ validate(api) {
1176
+ const messages = [];
1177
+ const endpoints = api.endpoints;
1178
+ const identToPathAndOperation = /* @__PURE__ */ new Map();
1179
+ for (const endpoint of endpoints) {
1180
+ const { path: path2, operations } = endpoint;
1181
+ for (const operation of operations) {
1182
+ const operationId = operation.operationId || `${operation.method} ${operation.endpoint.path}`;
1183
+ const { bindings } = operation;
1184
+ for (const binding of bindings) {
1185
+ const { identifier } = binding;
1186
+ if (identToPathAndOperation.has(identifier)) {
1187
+ const existing = identToPathAndOperation.get(identifier);
1188
+ messages.push({
1189
+ severity: ValidationSeverity.Error,
1190
+ message: `Binding identifier '${identifier}' in operation '${operationId}' is already used in path '${existing.path}' and operation '${existing.operationId}'`,
1191
+ subject: operation,
1192
+ validationType: ValidationType.Operation
1193
+ });
1194
+ } else {
1195
+ identToPathAndOperation.set(identifier, { path: path2, operationId });
1196
+ }
1197
+ }
1198
+ }
1199
+ }
1200
+ return messages.length > 0 ? err(messages) : ok(messages);
1201
+ }
1202
+ }
1203
+ class ApiValidator {
1204
+ constructor(apiValidators, typeValidator, endpointValidator) {
1205
+ this.apiValidators = apiValidators;
1206
+ this.typeValidator = typeValidator;
1207
+ this.endpointValidator = endpointValidator;
1208
+ }
1209
+ validate(subject) {
1210
+ const results = [
1211
+ this.validateCollection(subject.types.values(), this.typeValidator),
1212
+ this.validateCollection(subject.endpoints, this.endpointValidator),
1213
+ ...this.apiValidators.map((v) => v.validate(subject))
1214
+ ];
1215
+ return combineValidationResults(results);
1216
+ }
1217
+ validateCollection(items, validator) {
1218
+ const results = [];
1219
+ for (const item of items) {
1220
+ results.push(validator.validate(item));
1221
+ }
1222
+ return combineValidationResults(results);
1223
+ }
1224
+ }
1225
+ function buildApiValidatorFor(api) {
1226
+ const typeValidation = buildTypeValidator(api.types);
1227
+ const apiValidators = [new BindingsValidation()];
1228
+ const endpointValidation = buildEndpointValidator(api);
1229
+ return new ApiValidator(apiValidators, typeValidation, endpointValidation);
1230
+ }
1231
+ function validateUniqueBindingIdentfiers(operations) {
1232
+ const operationsBindings = operations.map(({ bindings }) => bindings.map(({ identifier }) => identifier)).flat();
1233
+ const uniqueBindings = new Set(operationsBindings);
1234
+ return operationsBindings.length === uniqueBindings.size;
1235
+ }
1236
+ var util;
1237
+ (function(util2) {
1238
+ util2.assertEqual = (val) => val;
1239
+ function assertIs(_arg) {
1240
+ }
1241
+ util2.assertIs = assertIs;
1242
+ function assertNever(_x) {
1243
+ throw new Error();
1244
+ }
1245
+ util2.assertNever = assertNever;
1246
+ util2.arrayToEnum = (items) => {
1247
+ const obj = {};
1248
+ for (const item of items) {
1249
+ obj[item] = item;
1250
+ }
1251
+ return obj;
1252
+ };
1253
+ util2.getValidEnumValues = (obj) => {
1254
+ const validKeys = util2.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
1255
+ const filtered = {};
1256
+ for (const k of validKeys) {
1257
+ filtered[k] = obj[k];
1258
+ }
1259
+ return util2.objectValues(filtered);
1260
+ };
1261
+ util2.objectValues = (obj) => {
1262
+ return util2.objectKeys(obj).map(function(e) {
1263
+ return obj[e];
1264
+ });
1265
+ };
1266
+ util2.objectKeys = typeof Object.keys === "function" ? (obj) => Object.keys(obj) : (object) => {
1267
+ const keys = [];
1268
+ for (const key in object) {
1269
+ if (Object.prototype.hasOwnProperty.call(object, key)) {
1270
+ keys.push(key);
1271
+ }
1272
+ }
1273
+ return keys;
1274
+ };
1275
+ util2.find = (arr, checker) => {
1276
+ for (const item of arr) {
1277
+ if (checker(item))
1278
+ return item;
1279
+ }
1280
+ return void 0;
1281
+ };
1282
+ util2.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && isFinite(val) && Math.floor(val) === val;
1283
+ function joinValues(array, separator = " | ") {
1284
+ return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
1285
+ }
1286
+ util2.joinValues = joinValues;
1287
+ util2.jsonStringifyReplacer = (_, value) => {
995
1288
  if (typeof value === "bigint") {
996
1289
  return value.toString();
997
1290
  }
@@ -4982,6 +5275,106 @@ var z = /* @__PURE__ */ Object.freeze({
4982
5275
  quotelessJson,
4983
5276
  ZodError
4984
5277
  });
5278
+ const serviceVariantDescriptorSchema = z.object({
5279
+ type: z.string(),
5280
+ version: z.string(),
5281
+ tags: z.record(z.string(), z.string()).optional(),
5282
+ default: z.boolean().optional()
5283
+ }).strict();
5284
+ const servicesCatalogSchema = z.record(z.string(), serviceVariantDescriptorSchema);
5285
+ const operationServiceRefSchema = z.object({
5286
+ ref: z.string()
5287
+ }).strict();
5288
+ const operationServiceInlineSchema = z.object({
5289
+ version: z.string(),
5290
+ tags: z.record(z.string(), z.string()).optional(),
5291
+ // Capture but disallow to provide a clearer error
5292
+ optional: z.boolean().optional()
5293
+ }).strict().superRefine((val, ctx) => {
5294
+ if (val.optional !== void 0) {
5295
+ ctx.addIssue({
5296
+ code: z.ZodIssueCode.custom,
5297
+ path: ["optional"],
5298
+ message: "optional is not allowed for service overrides"
5299
+ });
5300
+ }
5301
+ });
5302
+ const operationServicesSchema = z.record(
5303
+ z.string(),
5304
+ z.union([operationServiceRefSchema, operationServiceInlineSchema])
5305
+ );
5306
+ const componentsOnestoreServicesSchema = z.object({ onestore: z.object({ services: servicesCatalogSchema }).strict() }).strict();
5307
+ const operationOnestoreServicesSchema = z.object({ onestore: z.object({ services: operationServicesSchema }).strict() }).strict();
5308
+ function validateAndNormalizeCatalog(catalog) {
5309
+ const parsed = servicesCatalogSchema.safeParse(catalog);
5310
+ if (!parsed.success) {
5311
+ throw new Error(parsed.error.message);
5312
+ }
5313
+ const defaultsByType = {};
5314
+ for (const [alias, descriptor] of Object.entries(parsed.data)) {
5315
+ if (descriptor.default) {
5316
+ const prior = defaultsByType[descriptor.type];
5317
+ if (prior !== void 0 && prior !== alias) {
5318
+ throw new Error(
5319
+ `Multiple defaults defined for service type '${descriptor.type}': '${prior}' and '${alias}'`
5320
+ );
5321
+ }
5322
+ defaultsByType[descriptor.type] = alias;
5323
+ }
5324
+ }
5325
+ return { catalog: parsed.data, defaultsByType };
5326
+ }
5327
+ function resolveOperationServices(services, catalog) {
5328
+ const result = {};
5329
+ for (const [canonicalName, entry] of Object.entries(services)) {
5330
+ if ("ref" in entry) {
5331
+ const alias = entry.ref;
5332
+ const descriptor = catalog == null ? void 0 : catalog.catalog[alias];
5333
+ if (!descriptor) {
5334
+ throw new Error(`ref '${alias}' does not exist in the catalog`);
5335
+ } else if (descriptor.default) {
5336
+ throw new Error(`ref is not required for default service '${alias}'`);
5337
+ } else if (descriptor.type !== canonicalName) {
5338
+ throw new Error(
5339
+ `Service '${alias}' uses non-canonical type '${descriptor.type}'. Expected canonical type '${canonicalName}'`
5340
+ );
5341
+ }
5342
+ result[canonicalName] = {
5343
+ type: descriptor.type,
5344
+ version: descriptor.version,
5345
+ tags: descriptor.tags
5346
+ };
5347
+ } else {
5348
+ const inline = entry;
5349
+ result[canonicalName] = {
5350
+ type: canonicalName,
5351
+ version: inline.version,
5352
+ tags: inline.tags
5353
+ };
5354
+ }
5355
+ }
5356
+ return result;
5357
+ }
5358
+ function resolveDefaultServiceOverrides(catalog) {
5359
+ const result = {};
5360
+ if (catalog) {
5361
+ for (const [alias, type] of Object.entries(catalog.defaultsByType)) {
5362
+ const entry = catalog.catalog[type];
5363
+ if (entry && !result[entry.type]) {
5364
+ result[entry.type] = {
5365
+ type: entry.type,
5366
+ version: entry.version,
5367
+ tags: entry.tags
5368
+ };
5369
+ } else {
5370
+ throw new Error(
5371
+ `Missing or multiple default service overrides for service ${alias}`
5372
+ );
5373
+ }
5374
+ }
5375
+ }
5376
+ return result;
5377
+ }
4985
5378
  function formatZodError(err2) {
4986
5379
  const formattedIssues = err2.issues.map((iss) => {
4987
5380
  if (iss.code === "invalid_type") {
@@ -5146,6 +5539,15 @@ function buildExtensionScalar(graph) {
5146
5539
  const value = [DOUBLE_DATA_TYPE, INTEGER_DATA_TYPE, NUMBER_DATA_TYPE].includes(rawType) ? Number(rawValue) : rawType === BOOLEAN_DATA_TYPE ? rawValue === "true" : String(rawValue);
5147
5540
  return value;
5148
5541
  }
5542
+ const rootExtensionSchema = z.object({
5543
+ onestore: z.object({
5544
+ version: z.string().refine(stringIsVersion, () => {
5545
+ return {
5546
+ message: "Version must satisfy format major[.minor[.patch]]"
5547
+ };
5548
+ })
5549
+ })
5550
+ });
5149
5551
  const cacheControl = z.discriminatedUnion("type", [
5150
5552
  z.object({
5151
5553
  type: z.literal("max-age"),
@@ -5213,1512 +5615,1425 @@ const typeExtensions = z.object({
5213
5615
  // @todo: .strict();
5214
5616
  "cache-control": cacheControl
5215
5617
  }).strict();
5216
- const annotationSchema = z.object({
5217
- onestore: typeExtensions.optional()
5618
+ const baseExtensionsSchema = z.object({
5619
+ onestore: z.object({
5620
+ defaults: z.object({
5621
+ operations: z.object({
5622
+ "cache-strategy": z.discriminatedUnion("type", [
5623
+ z.object({ type: z.literal("none") }).strict(),
5624
+ z.object({ type: z.literal("resource") }).strict(),
5625
+ z.object({ type: z.literal("normalized") }).strict()
5626
+ ])
5627
+ }),
5628
+ schemas: z.object({
5629
+ "cache-control": cacheControl
5630
+ })
5631
+ }).partial().strict().optional(),
5632
+ // Allow service catalog at root-level for reliability
5633
+ services: servicesCatalogSchema.optional(),
5634
+ namespace: z.string().optional(),
5635
+ version: z.string()
5636
+ }).strict()
5218
5637
  });
5219
- class AMFBaseType {
5220
- constructor(api, shape, typeRegistry, factory, logger, fileParserLogger) {
5221
- var _a;
5222
- this.api = api;
5223
- this.shape = shape;
5224
- this.typeRegistry = typeRegistry;
5225
- this.factory = factory;
5226
- this.logger = logger;
5227
- this.fileParserLogger = fileParserLogger;
5228
- this.resolved = false;
5229
- this.parsedExtensions = { type: "unidentifiable" };
5230
- const { line = 0, column = 0 } = ((_a = this.shape.position) == null ? void 0 : _a.start) || {};
5231
- this.shapePosition = { line, column };
5232
- }
5233
- resolve() {
5234
- var _a;
5235
- if (!this.resolved) {
5236
- this.resolved = true;
5237
- const annotationResult = annotationSchema.safeParse(
5238
- extractExtensions(this.shape.customDomainProperties)
5239
- );
5240
- if (!annotationResult.success) {
5241
- const message = formatZodError(annotationResult.error);
5242
- this.fileParserLogger.error(
5243
- this.shape.position.start,
5244
- `Errors validating type:
5245
- ${message}`
5638
+ const cacheInvalidationEntrySchema = z.object({
5639
+ ref: z.string(),
5640
+ key: z.record(z.string(), z.string())
5641
+ });
5642
+ const cacheInvalidationSchema = z.object({
5643
+ onestore: z.object({
5644
+ invalidate: z.array(cacheInvalidationEntrySchema)
5645
+ })
5646
+ });
5647
+ class OperationSchemaBuilder {
5648
+ constructor(method, operationId, operationCacheStrategyType) {
5649
+ this.method = method;
5650
+ this.operationId = operationId;
5651
+ this.operationCacheStrategyType = operationCacheStrategyType;
5652
+ }
5653
+ buildOperationSchema() {
5654
+ const bindingSchema = z.object({
5655
+ type: z.enum(BindingTypesEnum).default("wire"),
5656
+ identifier: z.string().default("")
5657
+ });
5658
+ const configSchema = z.object({
5659
+ "operation-type": z.enum(["query", "mutation", "graphql"]).default(this.method === "GET" ? "query" : "mutation"),
5660
+ schema: z.enum(["flattened", "default"]).default("default"),
5661
+ bindings: z.array(bindingSchema).default([]),
5662
+ exposeRefresh: z.boolean().default(false),
5663
+ "body-param": z.string().optional()
5664
+ }).default({}).transform((config, ctx) => {
5665
+ const { bindings, "operation-type": operationType } = config;
5666
+ if (bindings.length === 0) {
5667
+ if (!this.operationId) {
5668
+ ctx.addIssue({
5669
+ code: z.ZodIssueCode.custom,
5670
+ message: `operationId is required for adapter name generation when no explicit bindings defined for operation. Add an operationId or expicit bindings annotation.`
5671
+ });
5672
+ return config;
5673
+ }
5674
+ if (operationType === "graphql") {
5675
+ config.bindings = [{ type: "wire", identifier: this.operationId }];
5676
+ return config;
5677
+ } else {
5678
+ const bindingType = operationType === "query" ? "wire" : "imperative";
5679
+ config.bindings = [{ type: bindingType, identifier: this.operationId }];
5680
+ }
5681
+ } else if (bindings.length === 1) {
5682
+ if (!bindings[0].identifier) {
5683
+ if (!this.operationId) {
5684
+ ctx.addIssue({
5685
+ code: z.ZodIssueCode.custom,
5686
+ message: `operationId is required for adapter name generation when one explicit binding is requested without an identifier. Add an operationId or a binding identifier.`
5687
+ });
5688
+ return config;
5689
+ }
5690
+ bindings[0].identifier = this.operationId;
5691
+ }
5692
+ }
5693
+ return config;
5694
+ }).refine(
5695
+ (config) => {
5696
+ const { bindings, "operation-type": operationType } = config;
5697
+ if (operationType === "mutation") {
5698
+ return !bindings.some(
5699
+ (binding) => binding.type === "wire" || binding.type === "imperative-legacy"
5700
+ );
5701
+ }
5702
+ return true;
5703
+ },
5704
+ {
5705
+ message: 'Cannot use "wire" or "imperative-legacy" binding with operation-type "mutation"'
5706
+ }
5707
+ ).refine(
5708
+ (config) => {
5709
+ const { "operation-type": operationType, exposeRefresh } = config;
5710
+ return !(exposeRefresh && operationType === "mutation");
5711
+ },
5712
+ {
5713
+ message: 'Cannot exposeRefresh with operation-type "mutation"'
5714
+ }
5715
+ ).refine(
5716
+ (config) => {
5717
+ const { bindings, exposeRefresh } = config;
5718
+ if (!exposeRefresh) {
5719
+ return true;
5720
+ }
5721
+ return bindings.some(
5722
+ (binding) => binding.type === "wire" || binding.type === "imperative"
5246
5723
  );
5247
- throw new Error();
5724
+ },
5725
+ {
5726
+ message: 'Cannot use exposeRefresh without a "wire" or "imperative" binding'
5248
5727
  }
5249
- if ((_a = annotationResult.data.onestore) == null ? void 0 : _a.key) {
5250
- this.parsedExtensions = {
5251
- type: "identifiable",
5252
- ...annotationResult.data.onestore
5253
- };
5728
+ ).refine(
5729
+ (config) => {
5730
+ const { bindings } = config;
5731
+ if (bindings.length <= 1) {
5732
+ return true;
5733
+ }
5734
+ return bindings.every((binding) => !!binding.identifier);
5735
+ },
5736
+ {
5737
+ message: "Binding identifier is required if more than one binding is provided."
5254
5738
  }
5255
- this.logger.trace("Running this types resolution");
5256
- this.typeResolve();
5257
- } else {
5258
- this.logger.trace("Type was already resolved");
5259
- }
5260
- }
5261
- /*
5262
- Placeholder for type specific resolution
5263
- */
5264
- typeResolve() {
5739
+ ).refine(
5740
+ (config) => {
5741
+ const { bindings } = config;
5742
+ if (bindings.length <= 1) {
5743
+ return true;
5744
+ }
5745
+ const identifiers = bindings.map((binding) => binding.identifier);
5746
+ return new Set(identifiers).size === identifiers.length;
5747
+ },
5748
+ { message: "Binding identifier must be unique" }
5749
+ ).refine(
5750
+ (config) => {
5751
+ const { bindings, "operation-type": operationType } = config;
5752
+ if (operationType !== "graphql") {
5753
+ return !bindings.some((binding) => binding.type === "mutation");
5754
+ }
5755
+ return true;
5756
+ },
5757
+ {
5758
+ message: 'Cannot use "mutation" binding with non-graphql operations'
5759
+ }
5760
+ ).superRefine((config, ctx) => {
5761
+ config.bindings.forEach((binding) => {
5762
+ const tsSafeIdentifier = toTypeScriptSafeIdentifier(binding.identifier);
5763
+ if (binding.identifier !== tsSafeIdentifier) {
5764
+ ctx.addIssue({
5765
+ code: z.ZodIssueCode.custom,
5766
+ message: `Invalid identifier "${binding.identifier}" for adapter binding. This may be derived from operationId. Use a valid TypeScript variable name, e.g. '${tsSafeIdentifier}'.`
5767
+ });
5768
+ }
5769
+ });
5770
+ });
5771
+ return z.object({
5772
+ onestore: z.object({
5773
+ config: configSchema,
5774
+ "cache-strategy": operationCacheStrategy(this.operationCacheStrategyType),
5775
+ "error-strategy": z.discriminatedUnion("type", [
5776
+ z.object({ type: z.literal("stringified") }).strict(),
5777
+ z.object({ type: z.literal("fetchResponse") }).strict()
5778
+ ]).default({ type: "stringified" }),
5779
+ services: operationServicesSchema.optional()
5780
+ }).strict().default({}).transform((extensions) => {
5781
+ var _a;
5782
+ if (((_a = extensions["cache-strategy"]) == null ? void 0 : _a.type) === "normalized" && extensions.config["operation-type"] === "mutation") {
5783
+ if (extensions["cache-strategy"]["cache-control"] === void 0) {
5784
+ extensions["cache-strategy"]["cache-control"] = {
5785
+ type: "no-cache"
5786
+ };
5787
+ }
5788
+ }
5789
+ return extensions;
5790
+ }).refine(
5791
+ (extensions) => {
5792
+ var _a;
5793
+ if (((_a = extensions["cache-strategy"]) == null ? void 0 : _a.type) === "normalized") {
5794
+ const cacheControl2 = extensions["cache-strategy"]["cache-control"];
5795
+ if (extensions.config["operation-type"] === "mutation" && cacheControl2) {
5796
+ return cacheControl2.type === "no-cache";
5797
+ }
5798
+ }
5799
+ return true;
5800
+ },
5801
+ {
5802
+ message: 'Cannot use "cache-control" values other than "no-cache" with operation-type "mutation"'
5803
+ }
5804
+ ).refine(
5805
+ (extensions) => {
5806
+ var _a;
5807
+ if (((_a = extensions["cache-strategy"]) == null ? void 0 : _a.type) === "normalized") {
5808
+ if (extensions.config["operation-type"] === "query") {
5809
+ return extensions["cache-strategy"]["cache-control"] !== void 0;
5810
+ }
5811
+ }
5812
+ return true;
5813
+ },
5814
+ {
5815
+ message: 'Cannot use undefined "cache-control" with operation-type "query"'
5816
+ }
5817
+ ).refine(
5818
+ (extensions) => {
5819
+ var _a;
5820
+ if (extensions.config["operation-type"] === "graphql") {
5821
+ return ((_a = extensions["cache-strategy"]) == null ? void 0 : _a.type) === "normalized";
5822
+ }
5823
+ return true;
5824
+ },
5825
+ {
5826
+ message: "GraphQL operations must use normalized cache strategy"
5827
+ }
5828
+ )
5829
+ });
5265
5830
  }
5266
- get extensions() {
5267
- if (this.parsedExtensions.type === "identifiable") {
5268
- const CACHE_CONTROL = "cache-control";
5269
- const defaults = this.api.defaults.typeCacheControl;
5831
+ buildHttpOperationSchema() {
5832
+ return this.buildOperationSchema().transform((config, _ctx) => {
5833
+ let bodyParam = config.onestore.config["body-param"] === void 0 ? "inputPayload" : config.onestore.config["body-param"];
5270
5834
  return {
5271
- ...this.parsedExtensions,
5272
- [CACHE_CONTROL]: {
5273
- ...defaults,
5274
- ...this.parsedExtensions[CACHE_CONTROL]
5835
+ onestore: {
5836
+ config: {
5837
+ ...config.onestore.config,
5838
+ "body-param": bodyParam
5839
+ }
5275
5840
  }
5276
5841
  };
5277
- } else {
5278
- return this.parsedExtensions;
5279
- }
5842
+ });
5280
5843
  }
5281
- }
5282
- class AMFAnyTypeImpl extends AMFBaseType {
5283
- constructor() {
5284
- super(...arguments);
5285
- this.type = "any";
5844
+ buildAuraOperationSchema() {
5845
+ return this.buildOperationSchema().and(
5846
+ z.object({
5847
+ onestore: z.object({
5848
+ config: z.object({
5849
+ aura: z.object({
5850
+ method: z.string()
5851
+ })
5852
+ })
5853
+ })
5854
+ })
5855
+ );
5286
5856
  }
5287
- }
5288
- class AMFObjectTypeImpl extends AMFBaseType {
5289
- constructor() {
5290
- super(...arguments);
5291
- this.type = "object";
5292
- this.properties = {};
5293
- this.resolved = false;
5294
- this.additionalProperties = { type: "any" };
5857
+ buildAuraOperationWithBodySchema() {
5858
+ return this.buildAuraOperationSchema().and(
5859
+ z.object({
5860
+ onestore: z.object({
5861
+ config: z.object({
5862
+ aura: z.object({
5863
+ "body-param": z.string().optional()
5864
+ })
5865
+ })
5866
+ })
5867
+ })
5868
+ ).transform((config, ctx) => {
5869
+ let topLevelParam = config.onestore.config["body-param"];
5870
+ let auraParam = config.onestore.config.aura["body-param"];
5871
+ if (topLevelParam === void 0 && auraParam === void 0) {
5872
+ ctx.addIssue({
5873
+ code: z.ZodIssueCode.custom,
5874
+ message: "Missing body-param in both x-onestore.config and x-onestore.config.aura."
5875
+ });
5876
+ return z.NEVER;
5877
+ }
5878
+ if (topLevelParam !== void 0 && auraParam !== void 0) {
5879
+ return config;
5880
+ }
5881
+ if (topLevelParam === void 0) {
5882
+ topLevelParam = auraParam;
5883
+ }
5884
+ if (auraParam === void 0) {
5885
+ auraParam = topLevelParam;
5886
+ }
5887
+ return {
5888
+ onestore: {
5889
+ config: {
5890
+ ...config.onestore.config,
5891
+ "body-param": topLevelParam,
5892
+ aura: {
5893
+ ...config.onestore.config.aura,
5894
+ "body-param": auraParam
5895
+ }
5896
+ }
5897
+ }
5898
+ };
5899
+ });
5295
5900
  }
5296
- typeResolve() {
5297
- var _a;
5298
- if (((_a = this.shape.values) == null ? void 0 : _a.length) > 0) {
5901
+ buildGraphQLOperationSchema() {
5902
+ return this.buildOperationSchema().and(
5903
+ z.object({
5904
+ onestore: z.object({
5905
+ config: z.object({
5906
+ graphql: z.object({
5907
+ schema: z.string(),
5908
+ "type-metadata": z.array(
5909
+ z.object({
5910
+ typename: z.string(),
5911
+ "cache-control": cacheControl
5912
+ })
5913
+ ).default([])
5914
+ })
5915
+ })
5916
+ })
5917
+ })
5918
+ );
5919
+ }
5920
+ }
5921
+ class AmfBaseOperation {
5922
+ constructor(amfOperation, amfTypeFactory2, typeRegistry, logger, fileParserLogger, endpoint, server) {
5923
+ this.amfOperation = amfOperation;
5924
+ this.amfTypeFactory = amfTypeFactory2;
5925
+ this.typeRegistry = typeRegistry;
5926
+ this.logger = logger;
5927
+ this.fileParserLogger = fileParserLogger;
5928
+ this.endpoint = endpoint;
5929
+ this.server = server;
5930
+ this.defaults = endpoint.api.defaults;
5931
+ this.method = this.amfOperation.method.value().toUpperCase();
5932
+ this.position = {
5933
+ line: this.amfOperation.position.lineFrom.valueOf(),
5934
+ column: this.amfOperation.position.columnFrom.valueOf()
5935
+ };
5936
+ const extensionsRaw = extractExtensions(this.amfOperation.customDomainProperties);
5937
+ this.operationId = this.amfOperation.operationId.value() || this.amfOperation.name.value();
5938
+ this.operationSchemaBuilder = new OperationSchemaBuilder(
5939
+ this.method,
5940
+ this.operationId,
5941
+ this.defaults.operationCacheStrategy
5942
+ );
5943
+ const extensionsResult = this.operationSchemaBuilder.buildOperationSchema().default({}).safeParse(extensionsRaw);
5944
+ if (!extensionsResult.success) {
5945
+ const message = formatZodError(extensionsResult.error);
5299
5946
  this.fileParserLogger.error(
5300
- this.shapePosition,
5301
- `Type Error (${this.shape.name.value()}). Object type may not specify enum property.`
5947
+ this.amfOperation.position.start,
5948
+ `Error validating operation:
5949
+ ${message}`
5302
5950
  );
5303
- throw new Error();
5951
+ throw new Error(`Error validating operation:
5952
+ ${message}`);
5304
5953
  }
5305
- this.logger.trace("Resolving properties");
5306
- this.resolveProperties();
5307
- this.logger.trace("Resolving additional properties");
5308
- this.resolveAdditionalProperties();
5309
- }
5310
- resolveProperties() {
5311
- for (const property of this.shape.properties) {
5312
- const propertyName = property.name.value();
5313
- const type = this.factory(
5314
- this.api,
5315
- property.range,
5316
- this.typeRegistry,
5317
- this.logger,
5318
- this.fileParserLogger,
5319
- true
5954
+ const extensions = extensionsResult.data;
5955
+ this.operationType = extensions.onestore.config["operation-type"];
5956
+ this.configSchemaType = extensions.onestore.config.schema;
5957
+ this.bindings = extensions.onestore.config.bindings;
5958
+ this.exposeRefresh = extensions.onestore.config.exposeRefresh;
5959
+ this.parsedCacheStrategy = extensions.onestore["cache-strategy"];
5960
+ this.errorStrategy = extensions.onestore["error-strategy"];
5961
+ this.basePath = this.endpoint.api.basePath;
5962
+ if (extensions.onestore.services) {
5963
+ this.serviceOverrides = resolveOperationServices(
5964
+ extensions.onestore.services,
5965
+ this.endpoint.api.serviceOverrides
5320
5966
  );
5321
- type.resolve();
5322
- const propertyType = {
5323
- type,
5324
- required: property.minCount.value() !== 0
5325
- };
5326
- this.properties[propertyName] = propertyType;
5967
+ } else {
5968
+ this.serviceOverrides = {};
5327
5969
  }
5970
+ this.requests = this.amfOperation.requests.map((request) => {
5971
+ return {
5972
+ queryParameters: this.buildParams(request.queryParameters),
5973
+ uriParameters: this.buildParams(request.uriParameters),
5974
+ payloads: this.buildPayloads(request),
5975
+ cookies: this.buildParams(request.cookieParameters),
5976
+ headers: this.buildParams(request.headers)
5977
+ };
5978
+ });
5979
+ this.responses = this.amfOperation.responses.map((response) => {
5980
+ const extensionsRaw2 = extractExtensions(response.customDomainProperties);
5981
+ if (extensionsRaw2.onestore !== void 0) {
5982
+ const extensionsResult2 = cacheInvalidationSchema.safeParse(extensionsRaw2);
5983
+ if (!extensionsResult2.success) {
5984
+ const message = formatZodError(extensionsResult2.error);
5985
+ this.fileParserLogger.error(
5986
+ this.amfOperation.position.start,
5987
+ `Error validating operation invalidation annotation:
5988
+ ${message}`
5989
+ );
5990
+ throw new Error(
5991
+ `Error validating operation invalidation annotation:
5992
+ ${message}`
5993
+ );
5994
+ }
5995
+ const extensions2 = extensionsResult2.data;
5996
+ if (Object.keys(extensions2.onestore.invalidate).length > 0 && this.operationType === "query") {
5997
+ this.fileParserLogger.error(
5998
+ this.position,
5999
+ `Cannot use an invalidate extension on a query type adapter`
6000
+ );
6001
+ throw new Error();
6002
+ }
6003
+ return {
6004
+ statusCode: response.statusCode.value(),
6005
+ headers: this.buildParams(response.headers),
6006
+ payloads: this.buildPayloads(response),
6007
+ invalidation: extensions2.onestore.invalidate
6008
+ };
6009
+ }
6010
+ return {
6011
+ statusCode: response.statusCode.value(),
6012
+ headers: this.buildParams(response.headers),
6013
+ payloads: this.buildPayloads(response)
6014
+ };
6015
+ });
5328
6016
  }
5329
- resolveAdditionalProperties() {
5330
- if (this.shape.closed.value()) {
5331
- this.additionalProperties = {
5332
- type: "not",
5333
- not: { type: "any" }
6017
+ get cacheStrategy() {
6018
+ return this.parsedCacheStrategy;
6019
+ }
6020
+ buildPayloads(r) {
6021
+ return r.payloads.map((payload) => {
6022
+ return {
6023
+ mediaType: payload.mediaType.value(),
6024
+ data: this.amfTypeFactory(
6025
+ {},
6026
+ payload.schema,
6027
+ this.typeRegistry,
6028
+ this.logger,
6029
+ this.fileParserLogger,
6030
+ true
6031
+ )
5334
6032
  };
5335
- } else if (this.shape.additionalPropertiesSchema) {
5336
- this.additionalProperties = this.factory(
5337
- this.api,
5338
- this.shape.additionalPropertiesSchema,
5339
- this.typeRegistry,
5340
- this.logger,
5341
- this.fileParserLogger,
5342
- true
5343
- );
6033
+ });
6034
+ }
6035
+ getDefaultValue(param) {
6036
+ var _a, _b;
6037
+ const defaultValue = (_a = param.schema) == null ? void 0 : _a.defaultValue;
6038
+ if (defaultValue) {
6039
+ return (_b = defaultValue.value) == null ? void 0 : _b.value();
5344
6040
  }
5345
6041
  }
6042
+ buildParams(p) {
6043
+ const params = {};
6044
+ p.forEach((param) => {
6045
+ params[`${param.name.value()}`] = {
6046
+ required: param.required.value(),
6047
+ type: this.amfTypeFactory(
6048
+ {},
6049
+ param.schema,
6050
+ this.typeRegistry,
6051
+ this.logger,
6052
+ this.fileParserLogger,
6053
+ true
6054
+ ),
6055
+ explode: param.explode.value(),
6056
+ defaultValue: this.getDefaultValue(param)
6057
+ };
6058
+ });
6059
+ return params;
6060
+ }
5346
6061
  }
5347
- class AMFNilTypeImpl extends AMFBaseType {
6062
+ class AmfHttpOperation extends AmfBaseOperation {
5348
6063
  constructor() {
5349
6064
  super(...arguments);
5350
- this.type = "nil";
6065
+ this.type = "http";
5351
6066
  }
5352
6067
  }
5353
- class AMFNotTypeImpl extends AMFBaseType {
5354
- constructor(api, shape, typeRegistry, factory, logger, fileParserLogger) {
5355
- super(api, shape, typeRegistry, factory, logger, fileParserLogger);
5356
- this.shape = shape;
5357
- this.typeRegistry = typeRegistry;
5358
- this.factory = factory;
5359
- this.logger = logger;
5360
- this.fileParserLogger = fileParserLogger;
5361
- this.type = "not";
5362
- const amfType = this.factory(
5363
- this.api,
5364
- this.shape.not,
5365
- this.typeRegistry,
5366
- this.logger,
5367
- this.fileParserLogger
5368
- );
5369
- amfType.resolve();
5370
- this.not = amfType;
5371
- }
5372
- }
5373
- class AMFAllOfTypeImpl extends AMFBaseType {
5374
- constructor() {
5375
- super(...arguments);
5376
- this.type = "allOf";
5377
- this.allOf = [];
5378
- }
5379
- typeResolve() {
5380
- this.logger.trace("Running resolution for inherited and composed shapes");
5381
- const allOfTypes = [...this.shape.inherits, ...this.shape.and].map(
5382
- (inheritedShape) => {
5383
- return this.factory(
5384
- this.api,
5385
- inheritedShape,
5386
- this.typeRegistry,
5387
- this.logger,
5388
- this.fileParserLogger,
5389
- true
5390
- );
5391
- }
5392
- );
5393
- const rootType = this.factory(
5394
- this.api,
5395
- this.shape,
5396
- this.typeRegistry,
5397
- this.logger,
5398
- this.fileParserLogger,
5399
- true,
5400
- /* @__PURE__ */ new Set([
5401
- "any",
5402
- "ref",
5403
- "array",
5404
- "boolean",
5405
- "date",
5406
- "number",
5407
- "datetime",
5408
- "datetime-only",
5409
- "double",
5410
- "integer",
5411
- "nil",
5412
- "not",
5413
- "number",
5414
- "object",
5415
- "string",
5416
- "time"
5417
- ]),
5418
- true
6068
+ class AmfHttpOperationWithRequestBody extends AmfBaseOperation {
6069
+ constructor(amfOperation, amfTypeFactory2, typeRegistry, logger, fileParserLogger, endpoint, server) {
6070
+ super(
6071
+ amfOperation,
6072
+ amfTypeFactory2,
6073
+ typeRegistry,
6074
+ logger,
6075
+ fileParserLogger,
6076
+ endpoint,
6077
+ server
5419
6078
  );
5420
- this.allOf = [rootType, ...allOfTypes];
5421
- if (isOneOfShape(this.shape)) {
5422
- const OneOf = this.factory(
5423
- this.api,
5424
- this.shape,
5425
- this.typeRegistry,
5426
- this.logger,
5427
- this.fileParserLogger,
5428
- true,
5429
- /* @__PURE__ */ new Set(["oneOf"]),
5430
- true
5431
- );
5432
- this.allOf.push(OneOf);
6079
+ this.type = "http";
6080
+ const hasRequestBody = amfOperation.requests.some((request) => request.payloads.length > 0);
6081
+ if (!hasRequestBody) {
6082
+ throw new Error("Operation must have a request body defined");
5433
6083
  }
5434
- if (isEnumShape(this.shape)) {
5435
- const enumType2 = this.factory(
5436
- this.api,
5437
- this.shape,
5438
- this.typeRegistry,
5439
- this.logger,
5440
- this.fileParserLogger,
5441
- true,
5442
- /* @__PURE__ */ new Set(["enum"]),
5443
- true
6084
+ this.method = amfOperation.method.value().toUpperCase();
6085
+ const extensionsRaw = extractExtensions(amfOperation.customDomainProperties);
6086
+ const extensionsResult = this.operationSchemaBuilder.buildHttpOperationSchema().default({}).safeParse(extensionsRaw);
6087
+ if (!extensionsResult.success) {
6088
+ const message = formatZodError(extensionsResult.error);
6089
+ this.fileParserLogger.error(
6090
+ this.amfOperation.position.start,
6091
+ `Error validating aura operation:
6092
+ ${message}`
5444
6093
  );
5445
- this.allOf.push(enumType2);
6094
+ throw new Error();
5446
6095
  }
5447
- this.validateDiscriminators();
5448
- }
5449
- includes(t) {
5450
- return this.allOf.some((parent) => {
5451
- const canonicalizedParent = canonicalizeType(parent);
5452
- if (canonicalizedParent === t) {
5453
- return true;
5454
- }
5455
- return canonicalizedParent.type === "allOf" && canonicalizedParent.includes(t);
5456
- });
6096
+ const extensions = extensionsResult.data;
6097
+ if (!extensions.onestore.config["body-param"]) {
6098
+ throw new Error("Missing body-param");
6099
+ }
6100
+ this.configBodyParam = extensions.onestore.config["body-param"];
5457
6101
  }
5458
- get discriminatedParent() {
5459
- var _a;
5460
- const discriminatedParents = [
5461
- ...bfs(
5462
- [this],
5463
- (type) => {
5464
- return isDiscriminatedObjectType(type);
5465
- },
5466
- (type) => {
5467
- return type.type === "allOf" ? type.allOf : type.type === "ref" ? [type.$ref] : [];
5468
- }
5469
- ).values()
5470
- ];
5471
- if (discriminatedParents.length === 0) {
5472
- return;
6102
+ }
6103
+ class AmfAuraOperation extends AmfBaseOperation {
6104
+ constructor(amfOperation, amfTypeFactory2, typeRegistry, logger, fileParserLogger, endpoint, server) {
6105
+ super(
6106
+ amfOperation,
6107
+ amfTypeFactory2,
6108
+ typeRegistry,
6109
+ logger,
6110
+ fileParserLogger,
6111
+ endpoint,
6112
+ server
6113
+ );
6114
+ this.type = "aura";
6115
+ const hasRequestBody = amfOperation.requests.some((request) => request.payloads.length > 0);
6116
+ if (hasRequestBody) {
6117
+ throw new Error("Operation must not have a request body defined");
5473
6118
  }
5474
- if (discriminatedParents.length > 1) {
5475
- const { line = 0, column = 0 } = ((_a = this.shape.position) == null ? void 0 : _a.start) || {};
6119
+ this.method = amfOperation.method.value().toUpperCase();
6120
+ const extensionsRaw = extractExtensions(amfOperation.customDomainProperties);
6121
+ const extensionsResult = this.operationSchemaBuilder.buildAuraOperationSchema().safeParse(extensionsRaw);
6122
+ if (!extensionsResult.success) {
6123
+ const message = formatZodError(extensionsResult.error);
5476
6124
  this.fileParserLogger.error(
5477
- { line, column },
5478
- `Type ${this.typeRegistry.nameOf(
5479
- this
5480
- )} cannot inherit from multiple discriminated objects. Inherits from ${discriminatedParents.map(
5481
- (parent) => this.typeRegistry.nameOf(parent)
5482
- )}.`
6125
+ this.amfOperation.position.start,
6126
+ `Error validating aura operation:
6127
+ ${message}`
5483
6128
  );
5484
6129
  throw new Error();
5485
6130
  }
5486
- return discriminatedParents[0];
5487
- }
5488
- validateDiscriminators() {
5489
- this.discriminatedParent;
5490
- }
5491
- get extensions() {
5492
- var _a, _b;
5493
- if (super.extensions.type === "identifiable") {
5494
- return super.extensions;
5495
- }
5496
- if (((_b = (_a = this.discriminatedParent) == null ? void 0 : _a.extensions) == null ? void 0 : _b.type) === "identifiable") {
5497
- return this.discriminatedParent.extensions;
5498
- }
5499
- return super.extensions;
6131
+ const extensions = extensionsResult.data;
6132
+ this.aura = { methodName: extensions.onestore.config.aura.method };
5500
6133
  }
5501
6134
  }
5502
- class AMFEnumerableScalarType extends AMFBaseType {
5503
- typeResolve() {
5504
- var _a;
5505
- if (((_a = this.shape.values) == null ? void 0 : _a.length) > 0) {
5506
- this.values = getEnumValuesFromShape(this.shape);
6135
+ class AmfAuraOperationWithRequestBody extends AmfBaseOperation {
6136
+ constructor(amfOperation, amfTypeFactory2, typeRegistry, logger, fileParserLogger, endpoint, server) {
6137
+ super(
6138
+ amfOperation,
6139
+ amfTypeFactory2,
6140
+ typeRegistry,
6141
+ logger,
6142
+ fileParserLogger,
6143
+ endpoint,
6144
+ server
6145
+ );
6146
+ this.type = "aura";
6147
+ const hasRequestBody = amfOperation.requests.some((request) => request.payloads.length > 0);
6148
+ if (!hasRequestBody) {
6149
+ throw new Error("Operation must have a request body defined");
5507
6150
  }
5508
- if (this.parsedExtensions.type === "identifiable") {
6151
+ this.method = amfOperation.method.value().toUpperCase();
6152
+ const extensionsRaw = extractExtensions(amfOperation.customDomainProperties);
6153
+ const extensionsResult = this.operationSchemaBuilder.buildAuraOperationWithBodySchema().safeParse(extensionsRaw);
6154
+ if (!extensionsResult.success) {
6155
+ const message = formatZodError(extensionsResult.error);
5509
6156
  this.fileParserLogger.error(
5510
- this.shape.position.start,
5511
- `${this.shape.name} is scalar and thus cannot be made identifiable by specifying a key`
6157
+ this.amfOperation.position.start,
6158
+ `Error validating aura operation:
6159
+ ${message}`
5512
6160
  );
5513
6161
  throw new Error();
5514
6162
  }
6163
+ const extensions = extensionsResult.data;
6164
+ if (extensions.onestore.config["body-param"] === void 0) {
6165
+ throw new Error("Missing body param");
6166
+ }
6167
+ if (extensions.onestore.config.aura["body-param"] === void 0) {
6168
+ throw new Error("Missing aura body param");
6169
+ }
6170
+ this.configBodyParam = extensions.onestore.config["body-param"];
6171
+ this.aura = {
6172
+ methodName: extensions.onestore.config.aura.method,
6173
+ bodyParam: extensions.onestore.config.aura["body-param"]
6174
+ };
5515
6175
  }
5516
6176
  }
5517
- class AMFBooleanTypeImpl extends AMFEnumerableScalarType {
5518
- constructor() {
5519
- super(...arguments);
5520
- this.type = "boolean";
5521
- }
6177
+ function AmfGraphQLOperationMixin(Base) {
6178
+ return class AmfGraphQLOperation extends Base {
6179
+ constructor(...args) {
6180
+ super(...args);
6181
+ this.operationType = "graphql";
6182
+ this.graphqlConfig = this.setupGraphQLConfig();
6183
+ }
6184
+ setupGraphQLConfig() {
6185
+ const extensionsRaw = extractExtensions(this.amfOperation.customDomainProperties);
6186
+ const extensionsResult = this.operationSchemaBuilder.buildGraphQLOperationSchema().safeParse(extensionsRaw);
6187
+ if (!extensionsResult.success) {
6188
+ const message = formatZodError(extensionsResult.error);
6189
+ this.fileParserLogger.error(
6190
+ this.amfOperation.position.start,
6191
+ `Error validating graphql operation:
6192
+ ${message}`
6193
+ );
6194
+ throw new Error(message);
6195
+ }
6196
+ const extensions = extensionsResult.data;
6197
+ const config = {
6198
+ schemaFilePath: extensions.onestore.config.graphql.schema,
6199
+ "type-metadata": extensions.onestore.config.graphql["type-metadata"]
6200
+ };
6201
+ return config;
6202
+ }
6203
+ };
5522
6204
  }
5523
- class AMFDoubleTypeImpl extends AMFEnumerableScalarType {
5524
- constructor() {
5525
- super(...arguments);
5526
- this.type = "double";
5527
- }
5528
- }
5529
- class AMFIntegerTypeImpl extends AMFEnumerableScalarType {
5530
- constructor() {
5531
- super(...arguments);
5532
- this.type = "integer";
5533
- }
5534
- }
5535
- class AMFNumberTypeImpl extends AMFEnumerableScalarType {
5536
- constructor() {
5537
- super(...arguments);
5538
- this.type = "number";
5539
- }
5540
- }
5541
- class AMFStringTypeImpl extends AMFEnumerableScalarType {
5542
- constructor() {
5543
- super(...arguments);
5544
- this.type = "string";
5545
- }
5546
- }
5547
- class AMFDateTypeImpl extends AMFEnumerableScalarType {
5548
- constructor() {
5549
- super(...arguments);
5550
- this.type = "date";
5551
- }
5552
- }
5553
- const DATE = "date";
5554
- const DATE_TIME = "date-time";
5555
- class AMFDateTimeImpl extends AMFEnumerableScalarType {
5556
- constructor(api, shape, typeRegistry, factory, logger, fileParserLogger) {
5557
- super(api, shape, typeRegistry, factory, logger, fileParserLogger);
5558
- this.shape = shape;
5559
- this.type = "datetime";
5560
- const formatValue = shape.format.value();
5561
- this.format = formatValue === DATE ? DATE : DATE_TIME;
5562
- }
5563
- }
5564
- class AMFOneOfTypeImpl extends AMFBaseType {
5565
- constructor() {
5566
- super(...arguments);
5567
- this.type = "oneOf";
5568
- this.oneOf = [];
5569
- }
5570
- typeResolve() {
5571
- var _a;
5572
- let { anyOf = [], xone = [] } = this.shape;
5573
- this.oneOf = [...anyOf, ...xone].map((subTypeShape) => {
5574
- const subType = this.factory(
5575
- this.api,
5576
- subTypeShape,
5577
- this.typeRegistry,
5578
- this.logger,
5579
- this.fileParserLogger
6205
+ const endpointSchema = z.object({
6206
+ onestore: z.discriminatedUnion("endpoint-type", [
6207
+ z.object({
6208
+ "endpoint-type": z.literal("http")
6209
+ }).strict(),
6210
+ z.object({
6211
+ "endpoint-type": z.literal("aura"),
6212
+ config: z.object({
6213
+ aura: z.object({
6214
+ controller: z.string()
6215
+ })
6216
+ }),
6217
+ "network-preference": z.enum(["aura", "http"]).default("aura")
6218
+ }).strict()
6219
+ ]).optional()
6220
+ });
6221
+ const partialOperationSchema = z.object({
6222
+ onestore: z.object({
6223
+ config: z.object({
6224
+ "operation-type": z.enum(["query", "mutation", "graphql"]).optional()
6225
+ }).passthrough().optional()
6226
+ }).passthrough().optional()
6227
+ });
6228
+ function createAmfAuraEndpoint(amfEndpoint, amfTypeFactory2, typeRegistry, logger, fileParserLogger, server, api, networkPreference) {
6229
+ const endpoint = new AmfAuraEndpoint(
6230
+ amfEndpoint,
6231
+ [],
6232
+ amfTypeFactory2,
6233
+ typeRegistry,
6234
+ logger,
6235
+ fileParserLogger,
6236
+ api,
6237
+ networkPreference
6238
+ );
6239
+ const operations = amfEndpoint.operations.map((operation) => {
6240
+ var _a, _b;
6241
+ const extensionsRaw = extractExtensions(operation.customDomainProperties);
6242
+ const operationConfigValidationResult = partialOperationSchema.safeParse(extensionsRaw);
6243
+ if (!operationConfigValidationResult.success) {
6244
+ const message = formatZodError(operationConfigValidationResult.error);
6245
+ fileParserLogger.error(
6246
+ operation.position.start,
6247
+ `Errors validating operation:
6248
+ ${message}`
5580
6249
  );
5581
- subType.resolve();
5582
- return subType;
5583
- });
5584
- if (((_a = this.shape.values) == null ? void 0 : _a.length) > 0) {
5585
- this.values = getEnumValuesFromShape(this.shape);
5586
- }
5587
- this.preserveIdentifiableExtensionsFromNullablePattern();
5588
- }
5589
- /**
5590
- * When AMF encounters 'nullable: true' on an object with identifiable extensions,
5591
- * it converts it to a oneOf with [object, null]. This method detects this pattern
5592
- * and preserves the identifiable extensions from the object member on the union.
5593
- */
5594
- preserveIdentifiableExtensionsFromNullablePattern() {
5595
- var _a;
5596
- if (this.oneOf.length !== 2) {
5597
- return;
5598
- }
5599
- const nullMember = this.oneOf.find((member) => member.type === "nil");
5600
- const objectMember = this.oneOf.find((member) => member.type === "object");
5601
- if (!nullMember || !objectMember) {
5602
- return;
5603
- }
5604
- if (((_a = objectMember.extensions) == null ? void 0 : _a.type) === "identifiable") {
5605
- this.parsedExtensions = { ...objectMember.extensions };
5606
- }
5607
- }
5608
- }
5609
- class AMFEnumTypeImpl extends AMFBaseType {
5610
- constructor(api, shape, typeRegistry, factory, logger, fileParserLogger) {
5611
- super(api, shape, typeRegistry, factory, logger, fileParserLogger);
5612
- this.shape = shape;
5613
- this.typeRegistry = typeRegistry;
5614
- this.factory = factory;
5615
- this.logger = logger;
5616
- this.fileParserLogger = fileParserLogger;
5617
- this.type = "enum";
5618
- this.values = [];
5619
- this.values = getEnumValuesFromShape(shape);
5620
- }
5621
- }
5622
- class AMFRefTypeImpl extends AMFBaseType {
5623
- constructor() {
5624
- super(...arguments);
5625
- this.type = "ref";
5626
- this.$ref = {
5627
- type: "not",
5628
- not: { type: "any" }
5629
- };
5630
- this.resolved = false;
5631
- }
5632
- typeResolve() {
5633
- this.logger.trace(`Resolving $ref at ${this.shape.id.split("#")[1]}`);
5634
- if (this.shape.isLink && this.shape.linkTarget) {
5635
- const inheritedType = this.typeRegistry.get(this.shape.linkLabel.toString());
5636
- if (inheritedType) {
5637
- this.logger.trace(`Found ${inheritedType.shape.name} for $ref`);
5638
- inheritedType.resolve();
5639
- this.$ref = inheritedType;
5640
- } else {
5641
- const errorMessage = `Failed to resolve $ref: ${this.shape.linkLabel.toString()} from ${this.shape.id}`;
5642
- this.fileParserLogger.error(this.shapePosition, errorMessage);
5643
- throw new Error(errorMessage);
5644
- }
6250
+ throw new Error();
5645
6251
  }
5646
- }
6252
+ const hasRequestBody = operation.requests.some((request) => request.payloads.length > 0);
6253
+ const isGraphQLOperation = ((_b = (_a = operationConfigValidationResult.data.onestore) == null ? void 0 : _a.config) == null ? void 0 : _b["operation-type"]) === "graphql";
6254
+ let baseClass = isGraphQLOperation ? AmfGraphQLOperationMixin(
6255
+ hasRequestBody ? AmfAuraOperationWithRequestBody : AmfAuraOperation
6256
+ ) : hasRequestBody ? AmfAuraOperationWithRequestBody : AmfAuraOperation;
6257
+ return new baseClass(
6258
+ operation,
6259
+ amfTypeFactory2,
6260
+ typeRegistry,
6261
+ logger,
6262
+ fileParserLogger,
6263
+ endpoint,
6264
+ server
6265
+ );
6266
+ });
6267
+ endpoint.operations = operations;
6268
+ return endpoint;
5647
6269
  }
5648
- class AMFDiscriminatedObjectTypeImpl extends AMFBaseType {
5649
- constructor(api, shape, typeRegistry, factory, logger, fileParserLogger) {
5650
- super(api, shape, typeRegistry, factory, logger, fileParserLogger);
5651
- this.shape = shape;
5652
- this.typeRegistry = typeRegistry;
5653
- this.factory = factory;
5654
- this.logger = logger;
5655
- this.fileParserLogger = fileParserLogger;
5656
- this.type = "discriminatedObject";
5657
- this._mapping = void 0;
5658
- if (this.shape.discriminator.isNullOrEmpty) {
5659
- this.fileParserLogger.error(
5660
- this.shapePosition,
5661
- "Supplied shape does not provide a discriminator"
5662
- );
5663
- throw new Error();
6270
+ function createAmfHttpEndpoint(amfEndpoint, amfTypeFactory2, typeRegistry, logger, fileParserLogger, server, api) {
6271
+ const endpoint = new AmfHttpEndPoint(
6272
+ amfEndpoint,
6273
+ [],
6274
+ amfTypeFactory2,
6275
+ typeRegistry,
6276
+ logger,
6277
+ fileParserLogger,
6278
+ api
6279
+ );
6280
+ const operations = amfEndpoint.operations.map((operation) => {
6281
+ var _a, _b;
6282
+ const operationConfigValidationResult = partialOperationSchema.safeParse(
6283
+ extractExtensions(operation.customDomainProperties)
6284
+ );
6285
+ if (!operationConfigValidationResult.success) {
6286
+ const message = formatZodError(operationConfigValidationResult.error);
6287
+ const errorMessage = `Error validating operation:
6288
+ ${message}`;
6289
+ fileParserLogger.error(operation.position.start, errorMessage);
6290
+ throw new Error(errorMessage);
5664
6291
  }
5665
- this.discriminator = this.shape.discriminator.value();
5666
- this.baseType = factory(
5667
- api,
5668
- shape,
6292
+ const hasRequestBody = operation.requests.some((request) => request.payloads.length > 0);
6293
+ const isGraphQLOperation = ((_b = (_a = operationConfigValidationResult.data.onestore) == null ? void 0 : _a.config) == null ? void 0 : _b["operation-type"]) === "graphql";
6294
+ let baseClass = isGraphQLOperation ? AmfGraphQLOperationMixin(
6295
+ hasRequestBody ? AmfHttpOperationWithRequestBody : AmfHttpOperation
6296
+ ) : hasRequestBody ? AmfHttpOperationWithRequestBody : AmfHttpOperation;
6297
+ return new baseClass(
6298
+ operation,
6299
+ amfTypeFactory2,
5669
6300
  typeRegistry,
5670
6301
  logger,
5671
6302
  fileParserLogger,
5672
- false,
5673
- /* @__PURE__ */ new Set(["object"])
6303
+ endpoint,
6304
+ server
5674
6305
  );
6306
+ });
6307
+ endpoint.operations = operations;
6308
+ return endpoint;
6309
+ }
6310
+ function amfEndpointFactory(amfEndpoint, amfTypeFactory2, typeRegistry, logger, fileParserLogger, server, api) {
6311
+ const endpointConfigValidationResult = endpointSchema.safeParse(
6312
+ extractExtensions(amfEndpoint.customDomainProperties)
6313
+ );
6314
+ if (!endpointConfigValidationResult.success) {
6315
+ const message = formatZodError(endpointConfigValidationResult.error);
6316
+ const errorMessage = `Error validating endpoint:
6317
+ ${message}`;
6318
+ fileParserLogger.error(amfEndpoint.position.start, errorMessage);
6319
+ throw new Error(errorMessage);
5675
6320
  }
5676
- typeResolve() {
5677
- this.baseType.resolve();
5678
- if (this.typeRegistry.nameOf(this) === void 0) {
5679
- this.fileParserLogger.error(
5680
- this.shapePosition,
5681
- "Cannot use discriminator on inline types."
5682
- );
5683
- throw new Error();
5684
- }
5685
- }
5686
- get mapping() {
5687
- if (this._mapping === void 0) {
5688
- this._mapping = {};
5689
- this.resolveDiscriminator();
5690
- }
5691
- return this._mapping;
5692
- }
5693
- resolveDiscriminator() {
5694
- this.buildExplicitMapping();
5695
- this.buildImplicitMapping();
5696
- }
5697
- /**
5698
- * Adds implicit discriminator values (i.e., type names) as mappings to types
5699
- *
5700
- * @private
5701
- */
5702
- buildImplicitMapping() {
5703
- const oneOfNames = this.shape.xone.reduce((result, shape) => {
5704
- if (shape.isLink) {
5705
- result.push(shape.linkLabel.value());
5706
- }
5707
- return result;
5708
- }, []);
5709
- this.typeRegistry.forEach((type, name) => {
5710
- type.resolve();
5711
- if ((type.type === "allOf" && type.includes(this) || oneOfNames.includes(name)) && !Object.values(this._mapping).includes(type)) {
5712
- this._mapping[name] = type;
5713
- }
5714
- });
5715
- }
5716
- /**
5717
- * Adds explicit discriminator values as mappings to types
5718
- *
5719
- * @private
5720
- */
5721
- buildExplicitMapping() {
5722
- this.shape.discriminatorMapping.forEach((el) => {
5723
- const value = el.templateVariable.value();
5724
- const linkExpressionSplit = el.linkExpression.value().split("/");
5725
- const typeName = linkExpressionSplit[linkExpressionSplit.length - 1];
5726
- const type = this.typeRegistry.get(typeName);
5727
- if (type === void 0) {
5728
- this.fileParserLogger.error(this.shapePosition, `Cannot find type ${typeName}`);
5729
- throw new Error();
5730
- }
5731
- this._mapping[value] = type;
5732
- });
5733
- }
5734
- }
5735
- function amfTypeFactory(api, shape, typeRegistry, logger, fileParserLogger, resolve = false, allowedTypes = void 0, skipRegistry = false) {
5736
- var _a;
5737
- if (!skipRegistry) {
5738
- for (const [_, type] of typeRegistry.entries()) {
5739
- if (shape.id === type.shape.id) {
5740
- return type;
5741
- }
5742
- }
5743
- }
5744
- const { line = 0, column = 0 } = ((_a = shape.position) == null ? void 0 : _a.start) || {};
5745
- let ctor;
5746
- if (isAnyOfShape(shape)) {
5747
- fileParserLogger.error(
5748
- { line, column },
5749
- `anyOf is not suppoort, found in type ${shape.name.value()}`
5750
- );
5751
- throw new Error();
5752
- }
5753
- if (isRefShape(shape)) {
5754
- ctor = AMFRefTypeImpl;
5755
- } else if ((!allowedTypes || allowedTypes.has("allOf")) && isAllOfShape(shape)) {
5756
- ctor = AMFAllOfTypeImpl;
5757
- } else if ((!allowedTypes || allowedTypes.has("oneOf")) && isOneOfShape(shape)) {
5758
- ctor = AMFOneOfTypeImpl;
5759
- } else if ((!allowedTypes || allowedTypes.has("enum")) && isEnumShape(shape)) {
5760
- ctor = AMFEnumTypeImpl;
5761
- } else if ((!allowedTypes || allowedTypes.has("nil")) && isNilShape(shape)) {
5762
- ctor = AMFNilTypeImpl;
5763
- } else if (isScalarShape(shape) && shape.dataType.value() in DATATYPE_TO_SCALAR_TYPE && (!allowedTypes || allowedTypes.has(DATATYPE_TO_SCALAR_TYPE[shape.dataType.value()]))) {
5764
- const scalarType = DATATYPE_TO_SCALAR_TYPE[shape.dataType.value()];
5765
- switch (scalarType) {
5766
- case "string":
5767
- ctor = AMFStringTypeImpl;
5768
- break;
5769
- case "number":
5770
- ctor = AMFNumberTypeImpl;
5771
- break;
5772
- case "boolean":
5773
- ctor = AMFBooleanTypeImpl;
5774
- break;
5775
- case "double":
5776
- ctor = AMFDoubleTypeImpl;
5777
- break;
5778
- case "integer":
5779
- ctor = AMFIntegerTypeImpl;
5780
- break;
5781
- case "date":
5782
- ctor = AMFDateTypeImpl;
5783
- break;
5784
- case "datetime":
5785
- ctor = AMFDateTimeImpl;
5786
- break;
5787
- default:
5788
- fileParserLogger.error(
5789
- { line, column },
5790
- `type of shape ${shape.name.value()} not recognized`
5791
- );
5792
- throw new Error();
5793
- }
5794
- } else if ((!allowedTypes || allowedTypes.has("discriminatedObject")) && isNodeShape(shape) && !shape.discriminator.isNullOrEmpty) {
5795
- ctor = AMFDiscriminatedObjectTypeImpl;
5796
- } else if ((!allowedTypes || allowedTypes.has("object")) && isNodeShape(shape)) {
5797
- ctor = AMFObjectTypeImpl;
5798
- } else if ((!allowedTypes || allowedTypes.has("array")) && isArrayShape(shape)) {
5799
- ctor = AMFArrayTypeImpl;
5800
- } else if ((!allowedTypes || allowedTypes.has("not")) && isNotShape(shape)) {
5801
- ctor = AMFNotTypeImpl;
5802
- } else if ((!allowedTypes || allowedTypes.has("any")) && isAnyShape(shape)) {
5803
- ctor = AMFAnyTypeImpl;
5804
- } else {
5805
- fileParserLogger.error(
5806
- { line, column },
5807
- `type of shape ${shape.name.value()} not recognized`
5808
- );
5809
- throw new Error();
5810
- }
5811
- const result = new ctor(api, shape, typeRegistry, amfTypeFactory, logger, fileParserLogger);
5812
- if (resolve) {
5813
- result.resolve();
5814
- }
5815
- return result;
5816
- }
5817
- class AMFArrayTypeImpl extends AMFBaseType {
5818
- constructor() {
5819
- super(...arguments);
5820
- this.type = "array";
5821
- this.items = { type: "any" };
6321
+ const config = endpointConfigValidationResult.data;
6322
+ if (config.onestore === void 0) {
6323
+ return void 0;
5822
6324
  }
5823
- typeResolve() {
5824
- if (this.shape.items) {
5825
- const items = amfTypeFactory(
5826
- this.api,
5827
- this.shape.items,
5828
- this.typeRegistry,
5829
- this.logger,
5830
- this.fileParserLogger
5831
- );
5832
- items.resolve();
5833
- this.items = items;
5834
- }
6325
+ const endpoint = config.onestore["endpoint-type"] === "aura" ? createAmfAuraEndpoint(
6326
+ amfEndpoint,
6327
+ amfTypeFactory2,
6328
+ typeRegistry,
6329
+ logger,
6330
+ fileParserLogger,
6331
+ server,
6332
+ api,
6333
+ config.onestore["network-preference"]
6334
+ ) : createAmfHttpEndpoint(
6335
+ amfEndpoint,
6336
+ amfTypeFactory2,
6337
+ typeRegistry,
6338
+ logger,
6339
+ fileParserLogger,
6340
+ server,
6341
+ api
6342
+ );
6343
+ if (!validateUniqueBindingIdentfiers(endpoint.operations)) {
6344
+ const errorMessage = `All operations must have unique bindings`;
6345
+ fileParserLogger.error(amfEndpoint.position.start, errorMessage);
6346
+ throw new Error(errorMessage);
5835
6347
  }
6348
+ return endpoint;
5836
6349
  }
5837
- const serviceVariantDescriptorSchema = z.object({
5838
- type: z.string(),
5839
- version: z.string(),
5840
- tags: z.record(z.string(), z.string()).optional(),
5841
- default: z.boolean().optional()
5842
- }).strict();
5843
- const servicesCatalogSchema = z.record(z.string(), serviceVariantDescriptorSchema);
5844
- const operationServiceRefSchema = z.object({
5845
- ref: z.string()
5846
- }).strict();
5847
- const operationServiceInlineSchema = z.object({
5848
- version: z.string(),
5849
- tags: z.record(z.string(), z.string()).optional(),
5850
- // Capture but disallow to provide a clearer error
5851
- optional: z.boolean().optional()
5852
- }).strict().superRefine((val, ctx) => {
5853
- if (val.optional !== void 0) {
5854
- ctx.addIssue({
5855
- code: z.ZodIssueCode.custom,
5856
- path: ["optional"],
5857
- message: "optional is not allowed for service overrides"
6350
+ class AmfBaseEndpoint {
6351
+ constructor(amfEndpoint, operations, amfTypeFactory2, typeRegistry, logger, fileParserLogger, api) {
6352
+ this.amfEndpoint = amfEndpoint;
6353
+ this.operations = operations;
6354
+ this.logger = logger;
6355
+ this.fileParserLogger = fileParserLogger;
6356
+ this.api = api;
6357
+ this.path = this.amfEndpoint.path.value();
6358
+ this.uriParameters = {};
6359
+ this.amfEndpoint.parameters.forEach((param) => {
6360
+ this.uriParameters[`${param.name}`] = {
6361
+ required: param.required.value(),
6362
+ type: amfTypeFactory2(
6363
+ this.api,
6364
+ param.schema,
6365
+ typeRegistry,
6366
+ logger,
6367
+ fileParserLogger,
6368
+ true
6369
+ ),
6370
+ explode: param.explode.value()
6371
+ };
5858
6372
  });
5859
6373
  }
5860
- });
5861
- const operationServicesSchema = z.record(
5862
- z.string(),
5863
- z.union([operationServiceRefSchema, operationServiceInlineSchema])
5864
- );
5865
- const componentsOnestoreServicesSchema = z.object({ onestore: z.object({ services: servicesCatalogSchema }).strict() }).strict();
5866
- const operationOnestoreServicesSchema = z.object({ onestore: z.object({ services: operationServicesSchema }).strict() }).strict();
5867
- function validateAndNormalizeCatalog(catalog) {
5868
- const parsed = servicesCatalogSchema.safeParse(catalog);
5869
- if (!parsed.success) {
5870
- throw new Error(parsed.error.message);
5871
- }
5872
- const defaultsByType = {};
5873
- for (const [alias, descriptor] of Object.entries(parsed.data)) {
5874
- if (descriptor.default) {
5875
- const prior = defaultsByType[descriptor.type];
5876
- if (prior !== void 0 && prior !== alias) {
5877
- throw new Error(
5878
- `Multiple defaults defined for service type '${descriptor.type}': '${prior}' and '${alias}'`
5879
- );
5880
- }
5881
- defaultsByType[descriptor.type] = alias;
5882
- }
5883
- }
5884
- return { catalog: parsed.data, defaultsByType };
5885
- }
5886
- function resolveOperationServices(services, catalog) {
5887
- const result = {};
5888
- for (const [canonicalName, entry] of Object.entries(services)) {
5889
- if ("ref" in entry) {
5890
- const alias = entry.ref;
5891
- const descriptor = catalog == null ? void 0 : catalog.catalog[alias];
5892
- if (!descriptor) {
5893
- throw new Error(`ref '${alias}' does not exist in the catalog`);
5894
- } else if (descriptor.default) {
5895
- throw new Error(`ref is not required for default service '${alias}'`);
5896
- } else if (descriptor.type !== canonicalName) {
5897
- throw new Error(
5898
- `Service '${alias}' uses non-canonical type '${descriptor.type}'. Expected canonical type '${canonicalName}'`
5899
- );
5900
- }
5901
- result[canonicalName] = {
5902
- type: descriptor.type,
5903
- version: descriptor.version,
5904
- tags: descriptor.tags
5905
- };
5906
- } else {
5907
- const inline = entry;
5908
- result[canonicalName] = {
5909
- type: canonicalName,
5910
- version: inline.version,
5911
- tags: inline.tags
5912
- };
5913
- }
5914
- }
5915
- return result;
5916
- }
5917
- function resolveDefaultServiceOverrides(catalog) {
5918
- const result = {};
5919
- if (catalog) {
5920
- for (const [alias, type] of Object.entries(catalog.defaultsByType)) {
5921
- const entry = catalog.catalog[type];
5922
- if (entry && !result[entry.type]) {
5923
- result[entry.type] = {
5924
- type: entry.type,
5925
- version: entry.version,
5926
- tags: entry.tags
5927
- };
5928
- } else {
5929
- throw new Error(
5930
- `Missing or multiple default service overrides for service ${alias}`
5931
- );
5932
- }
5933
- }
5934
- }
5935
- return result;
5936
- }
5937
- const cacheInvalidationEntrySchema = z.object({
5938
- ref: z.string(),
5939
- key: z.record(z.string(), z.string())
5940
- });
5941
- const cacheInvalidationSchema = z.object({
5942
- onestore: z.object({
5943
- invalidate: z.array(cacheInvalidationEntrySchema)
5944
- })
5945
- });
5946
- class OperationSchemaBuilder {
5947
- constructor(method, operationId, operationCacheStrategyType) {
5948
- this.method = method;
5949
- this.operationId = operationId;
5950
- this.operationCacheStrategyType = operationCacheStrategyType;
5951
- }
5952
- buildOperationSchema() {
5953
- const bindingSchema = z.object({
5954
- type: z.enum(BindingTypesEnum).default("wire"),
5955
- identifier: z.string().default("")
5956
- });
5957
- const configSchema = z.object({
5958
- "operation-type": z.enum(["query", "mutation", "graphql"]).default(this.method === "GET" ? "query" : "mutation"),
5959
- schema: z.enum(["flattened", "default"]).default("default"),
5960
- bindings: z.array(bindingSchema).default([]),
5961
- exposeRefresh: z.boolean().default(false),
5962
- "body-param": z.string().optional()
5963
- }).default({}).transform((config, ctx) => {
5964
- const { bindings, "operation-type": operationType } = config;
5965
- if (bindings.length === 0) {
5966
- if (!this.operationId) {
5967
- ctx.addIssue({
5968
- code: z.ZodIssueCode.custom,
5969
- message: `operationId is required for adapter name generation when no explicit bindings defined for operation. Add an operationId or expicit bindings annotation.`
5970
- });
5971
- return config;
5972
- }
5973
- if (operationType === "graphql") {
5974
- config.bindings = [{ type: "wire", identifier: this.operationId }];
5975
- return config;
5976
- } else {
5977
- const bindingType = operationType === "query" ? "wire" : "imperative";
5978
- config.bindings = [{ type: bindingType, identifier: this.operationId }];
5979
- }
5980
- } else if (bindings.length === 1) {
5981
- if (!bindings[0].identifier) {
5982
- if (!this.operationId) {
5983
- ctx.addIssue({
5984
- code: z.ZodIssueCode.custom,
5985
- message: `operationId is required for adapter name generation when one explicit binding is requested without an identifier. Add an operationId or a binding identifier.`
5986
- });
5987
- return config;
5988
- }
5989
- bindings[0].identifier = this.operationId;
5990
- }
5991
- }
5992
- return config;
5993
- }).refine(
5994
- (config) => {
5995
- const { bindings, "operation-type": operationType } = config;
5996
- if (operationType === "mutation") {
5997
- return !bindings.some(
5998
- (binding) => binding.type === "wire" || binding.type === "imperative-legacy"
5999
- );
6000
- }
6001
- return true;
6002
- },
6003
- {
6004
- message: 'Cannot use "wire" or "imperative-legacy" binding with operation-type "mutation"'
6005
- }
6006
- ).refine(
6007
- (config) => {
6008
- const { "operation-type": operationType, exposeRefresh } = config;
6009
- return !(exposeRefresh && operationType === "mutation");
6010
- },
6011
- {
6012
- message: 'Cannot exposeRefresh with operation-type "mutation"'
6013
- }
6014
- ).refine(
6015
- (config) => {
6016
- const { bindings, exposeRefresh } = config;
6017
- if (exposeRefresh) {
6018
- return !bindings.some((binding) => binding.type === "imperative-legacy");
6019
- }
6020
- return true;
6021
- },
6022
- {
6023
- message: 'Cannot exposeRefresh with "imperative-legacy" binding'
6024
- }
6025
- ).refine(
6026
- (config) => {
6027
- const { bindings } = config;
6028
- if (bindings.length <= 1) {
6029
- return true;
6030
- }
6031
- return bindings.every((binding) => !!binding.identifier);
6032
- },
6033
- {
6034
- message: "Binding identifier is required if more than one binding is provided."
6035
- }
6036
- ).refine(
6037
- (config) => {
6038
- const { bindings } = config;
6039
- if (bindings.length <= 1) {
6040
- return true;
6041
- }
6042
- const identifiers = bindings.map((binding) => binding.identifier);
6043
- return new Set(identifiers).size === identifiers.length;
6044
- },
6045
- { message: "Binding identifier must be unique" }
6046
- ).refine(
6047
- (config) => {
6048
- const { bindings, "operation-type": operationType } = config;
6049
- if (operationType !== "graphql") {
6050
- return !bindings.some((binding) => binding.type === "mutation");
6051
- }
6052
- return true;
6053
- },
6054
- {
6055
- message: 'Cannot use "mutation" binding with non-graphql operations'
6056
- }
6057
- ).superRefine((config, ctx) => {
6058
- config.bindings.forEach((binding) => {
6059
- const tsSafeIdentifier = toTypeScriptSafeIdentifier(binding.identifier);
6060
- if (binding.identifier !== tsSafeIdentifier) {
6061
- ctx.addIssue({
6062
- code: z.ZodIssueCode.custom,
6063
- message: `Invalid identifier "${binding.identifier}" for adapter binding. This may be derived from operationId. Use a valid TypeScript variable name, e.g. '${tsSafeIdentifier}'.`
6064
- });
6065
- }
6066
- });
6067
- });
6068
- return z.object({
6069
- onestore: z.object({
6070
- config: configSchema,
6071
- "cache-strategy": operationCacheStrategy(this.operationCacheStrategyType),
6072
- "error-strategy": z.discriminatedUnion("type", [
6073
- z.object({ type: z.literal("stringified") }).strict(),
6074
- z.object({ type: z.literal("fetchResponse") }).strict()
6075
- ]).default({ type: "stringified" }),
6076
- services: operationServicesSchema.optional()
6077
- }).strict().default({}).transform((extensions) => {
6078
- var _a;
6079
- if (((_a = extensions["cache-strategy"]) == null ? void 0 : _a.type) === "normalized" && extensions.config["operation-type"] === "mutation") {
6080
- if (extensions["cache-strategy"]["cache-control"] === void 0) {
6081
- extensions["cache-strategy"]["cache-control"] = {
6082
- type: "no-cache"
6083
- };
6084
- }
6085
- }
6086
- return extensions;
6087
- }).refine(
6088
- (extensions) => {
6089
- var _a;
6090
- if (((_a = extensions["cache-strategy"]) == null ? void 0 : _a.type) === "normalized") {
6091
- const cacheControl2 = extensions["cache-strategy"]["cache-control"];
6092
- if (extensions.config["operation-type"] === "mutation" && cacheControl2) {
6093
- return cacheControl2.type === "no-cache";
6094
- }
6095
- }
6096
- return true;
6097
- },
6098
- {
6099
- message: 'Cannot use "cache-control" values other than "no-cache" with operation-type "mutation"'
6100
- }
6101
- ).refine(
6102
- (extensions) => {
6103
- var _a;
6104
- if (((_a = extensions["cache-strategy"]) == null ? void 0 : _a.type) === "normalized") {
6105
- if (extensions.config["operation-type"] === "query") {
6106
- return extensions["cache-strategy"]["cache-control"] !== void 0;
6107
- }
6108
- }
6109
- return true;
6110
- },
6111
- {
6112
- message: 'Cannot use undefined "cache-control" with operation-type "query"'
6113
- }
6114
- ).refine(
6115
- (extensions) => {
6116
- var _a;
6117
- if (extensions.config["operation-type"] === "graphql") {
6118
- return ((_a = extensions["cache-strategy"]) == null ? void 0 : _a.type) === "normalized";
6119
- }
6120
- return true;
6121
- },
6122
- {
6123
- message: "GraphQL operations must use normalized cache strategy"
6124
- }
6125
- )
6126
- });
6127
- }
6128
- buildHttpOperationSchema() {
6129
- return this.buildOperationSchema().transform((config, _ctx) => {
6130
- let bodyParam = config.onestore.config["body-param"] === void 0 ? "inputPayload" : config.onestore.config["body-param"];
6131
- return {
6132
- onestore: {
6133
- config: {
6134
- ...config.onestore.config,
6135
- "body-param": bodyParam
6136
- }
6137
- }
6138
- };
6139
- });
6140
- }
6141
- buildAuraOperationSchema() {
6142
- return this.buildOperationSchema().and(
6143
- z.object({
6144
- onestore: z.object({
6145
- config: z.object({
6146
- aura: z.object({
6147
- method: z.string()
6148
- })
6149
- })
6150
- })
6151
- })
6152
- );
6153
- }
6154
- buildAuraOperationWithBodySchema() {
6155
- return this.buildAuraOperationSchema().and(
6156
- z.object({
6157
- onestore: z.object({
6158
- config: z.object({
6159
- aura: z.object({
6160
- "body-param": z.string().optional()
6161
- })
6162
- })
6163
- })
6164
- })
6165
- ).transform((config, ctx) => {
6166
- let topLevelParam = config.onestore.config["body-param"];
6167
- let auraParam = config.onestore.config.aura["body-param"];
6168
- if (topLevelParam === void 0 && auraParam === void 0) {
6169
- ctx.addIssue({
6170
- code: z.ZodIssueCode.custom,
6171
- message: "Missing body-param in both x-onestore.config and x-onestore.config.aura."
6172
- });
6173
- return z.NEVER;
6174
- }
6175
- if (topLevelParam !== void 0 && auraParam !== void 0) {
6176
- return config;
6177
- }
6178
- if (topLevelParam === void 0) {
6179
- topLevelParam = auraParam;
6180
- }
6181
- if (auraParam === void 0) {
6182
- auraParam = topLevelParam;
6183
- }
6184
- return {
6185
- onestore: {
6186
- config: {
6187
- ...config.onestore.config,
6188
- "body-param": topLevelParam,
6189
- aura: {
6190
- ...config.onestore.config.aura,
6191
- "body-param": auraParam
6192
- }
6193
- }
6194
- }
6195
- };
6196
- });
6374
+ }
6375
+ class AmfHttpEndPoint extends AmfBaseEndpoint {
6376
+ constructor() {
6377
+ super(...arguments);
6378
+ this.type = "http";
6197
6379
  }
6198
- buildGraphQLOperationSchema() {
6199
- return this.buildOperationSchema().and(
6200
- z.object({
6201
- onestore: z.object({
6202
- config: z.object({
6203
- graphql: z.object({
6204
- schema: z.string(),
6205
- "type-metadata": z.array(
6206
- z.object({
6207
- typename: z.string(),
6208
- "cache-control": cacheControl
6209
- })
6210
- ).default([])
6211
- })
6212
- })
6213
- })
6214
- })
6380
+ }
6381
+ class AmfAuraEndpoint extends AmfBaseEndpoint {
6382
+ constructor(amfEndPoint, operations, amfTypeFactory2, typeRegistry, logger, fileParserLogger, api, networkPreference) {
6383
+ super(amfEndPoint, operations, amfTypeFactory2, typeRegistry, logger, fileParserLogger, api);
6384
+ this.logger = logger;
6385
+ this.fileParserLogger = fileParserLogger;
6386
+ this.api = api;
6387
+ this.networkPreference = networkPreference;
6388
+ this.type = "aura";
6389
+ this.auraController = this.buildAuraController();
6390
+ }
6391
+ buildAuraController() {
6392
+ const configResult = endpointSchema.safeParse(
6393
+ extractExtensions(this.amfEndpoint.customDomainProperties)
6215
6394
  );
6395
+ if (!configResult.success) {
6396
+ const message = formatZodError(configResult.error);
6397
+ const errorMessage = `Error validating aura endpoint:
6398
+ ${message}`;
6399
+ this.fileParserLogger.error(this.amfEndpoint.position.start, errorMessage);
6400
+ throw new Error(errorMessage);
6401
+ }
6402
+ const config = configResult.data;
6403
+ if (!config.onestore || config.onestore["endpoint-type"] !== "aura") {
6404
+ throw new Error("invalid config");
6405
+ }
6406
+ const name = config.onestore.config.aura.controller;
6407
+ if (name === void 0) {
6408
+ throw new Error("Aura controller name must be defined for an Aura endpoint.");
6409
+ }
6410
+ return { name };
6216
6411
  }
6217
6412
  }
6218
- class AmfBaseOperation {
6219
- constructor(amfOperation, amfTypeFactory2, typeRegistry, logger, fileParserLogger, endpoint, server) {
6220
- this.amfOperation = amfOperation;
6221
- this.amfTypeFactory = amfTypeFactory2;
6413
+ const annotationSchema = z.object({
6414
+ onestore: typeExtensions.optional()
6415
+ });
6416
+ class AMFBaseType {
6417
+ constructor(api, shape, typeRegistry, factory, logger, fileParserLogger) {
6418
+ var _a;
6419
+ this.api = api;
6420
+ this.shape = shape;
6222
6421
  this.typeRegistry = typeRegistry;
6422
+ this.factory = factory;
6223
6423
  this.logger = logger;
6224
6424
  this.fileParserLogger = fileParserLogger;
6225
- this.endpoint = endpoint;
6226
- this.server = server;
6227
- this.defaults = endpoint.api.defaults;
6228
- this.method = this.amfOperation.method.value().toUpperCase();
6229
- this.position = {
6230
- line: this.amfOperation.position.lineFrom.valueOf(),
6231
- column: this.amfOperation.position.columnFrom.valueOf()
6232
- };
6233
- const extensionsRaw = extractExtensions(this.amfOperation.customDomainProperties);
6234
- this.operationId = this.amfOperation.operationId.value() || this.amfOperation.name.value();
6235
- this.operationSchemaBuilder = new OperationSchemaBuilder(
6236
- this.method,
6237
- this.operationId,
6238
- this.defaults.operationCacheStrategy
6239
- );
6240
- const extensionsResult = this.operationSchemaBuilder.buildOperationSchema().default({}).safeParse(extensionsRaw);
6241
- if (!extensionsResult.success) {
6242
- const message = formatZodError(extensionsResult.error);
6243
- this.fileParserLogger.error(
6244
- this.amfOperation.position.start,
6245
- `Error validating operation:
6246
- ${message}`
6247
- );
6248
- throw new Error(`Error validating operation:
6249
- ${message}`);
6250
- }
6251
- const extensions = extensionsResult.data;
6252
- this.operationType = extensions.onestore.config["operation-type"];
6253
- this.configSchemaType = extensions.onestore.config.schema;
6254
- this.bindings = extensions.onestore.config.bindings;
6255
- this.exposeRefresh = extensions.onestore.config.exposeRefresh;
6256
- this.parsedCacheStrategy = extensions.onestore["cache-strategy"];
6257
- this.errorStrategy = extensions.onestore["error-strategy"];
6258
- this.basePath = this.endpoint.api.basePath;
6259
- if (extensions.onestore.services) {
6260
- this.serviceOverrides = resolveOperationServices(
6261
- extensions.onestore.services,
6262
- this.endpoint.api.serviceOverrides
6425
+ this.resolved = false;
6426
+ this.parsedExtensions = { type: "unidentifiable" };
6427
+ const { line = 0, column = 0 } = ((_a = this.shape.position) == null ? void 0 : _a.start) || {};
6428
+ this.shapePosition = { line, column };
6429
+ }
6430
+ resolve() {
6431
+ var _a;
6432
+ if (!this.resolved) {
6433
+ this.resolved = true;
6434
+ const annotationResult = annotationSchema.safeParse(
6435
+ extractExtensions(this.shape.customDomainProperties)
6263
6436
  );
6264
- } else {
6265
- this.serviceOverrides = {};
6266
- }
6267
- this.requests = this.amfOperation.requests.map((request) => {
6268
- return {
6269
- queryParameters: this.buildParams(request.queryParameters),
6270
- uriParameters: this.buildParams(request.uriParameters),
6271
- payloads: this.buildPayloads(request),
6272
- cookies: this.buildParams(request.cookieParameters),
6273
- headers: this.buildParams(request.headers)
6274
- };
6275
- });
6276
- this.responses = this.amfOperation.responses.map((response) => {
6277
- const extensionsRaw2 = extractExtensions(response.customDomainProperties);
6278
- if (extensionsRaw2.onestore !== void 0) {
6279
- const extensionsResult2 = cacheInvalidationSchema.safeParse(extensionsRaw2);
6280
- if (!extensionsResult2.success) {
6281
- const message = formatZodError(extensionsResult2.error);
6282
- this.fileParserLogger.error(
6283
- this.amfOperation.position.start,
6284
- `Error validating operation invalidation annotation:
6285
- ${message}`
6286
- );
6287
- throw new Error(
6288
- `Error validating operation invalidation annotation:
6437
+ if (!annotationResult.success) {
6438
+ const message = formatZodError(annotationResult.error);
6439
+ this.fileParserLogger.error(
6440
+ this.shape.position.start,
6441
+ `Errors validating type:
6289
6442
  ${message}`
6290
- );
6291
- }
6292
- const extensions2 = extensionsResult2.data;
6293
- if (Object.keys(extensions2.onestore.invalidate).length > 0 && this.operationType === "query") {
6294
- this.fileParserLogger.error(
6295
- this.position,
6296
- `Cannot use an invalidate extension on a query type adapter`
6297
- );
6298
- throw new Error();
6299
- }
6300
- return {
6301
- statusCode: response.statusCode.value(),
6302
- headers: this.buildParams(response.headers),
6303
- payloads: this.buildPayloads(response),
6304
- invalidation: extensions2.onestore.invalidate
6443
+ );
6444
+ throw new Error();
6445
+ }
6446
+ if ((_a = annotationResult.data.onestore) == null ? void 0 : _a.key) {
6447
+ this.parsedExtensions = {
6448
+ type: "identifiable",
6449
+ ...annotationResult.data.onestore
6305
6450
  };
6306
6451
  }
6307
- return {
6308
- statusCode: response.statusCode.value(),
6309
- headers: this.buildParams(response.headers),
6310
- payloads: this.buildPayloads(response)
6311
- };
6312
- });
6452
+ this.logger.trace("Running this types resolution");
6453
+ this.typeResolve();
6454
+ } else {
6455
+ this.logger.trace("Type was already resolved");
6456
+ }
6313
6457
  }
6314
- get cacheStrategy() {
6315
- return this.parsedCacheStrategy;
6458
+ /*
6459
+ Placeholder for type specific resolution
6460
+ */
6461
+ typeResolve() {
6316
6462
  }
6317
- buildPayloads(r) {
6318
- return r.payloads.map((payload) => {
6463
+ get extensions() {
6464
+ if (this.parsedExtensions.type === "identifiable") {
6465
+ const CACHE_CONTROL = "cache-control";
6466
+ const defaults = this.api.defaults.typeCacheControl;
6319
6467
  return {
6320
- mediaType: payload.mediaType.value(),
6321
- data: this.amfTypeFactory(
6322
- {},
6323
- payload.schema,
6324
- this.typeRegistry,
6325
- this.logger,
6326
- this.fileParserLogger,
6327
- true
6328
- )
6468
+ ...this.parsedExtensions,
6469
+ [CACHE_CONTROL]: {
6470
+ ...defaults,
6471
+ ...this.parsedExtensions[CACHE_CONTROL]
6472
+ }
6329
6473
  };
6330
- });
6474
+ } else {
6475
+ return this.parsedExtensions;
6476
+ }
6331
6477
  }
6332
- getDefaultValue(param) {
6333
- var _a, _b;
6334
- const defaultValue = (_a = param.schema) == null ? void 0 : _a.defaultValue;
6335
- if (defaultValue) {
6336
- return (_b = defaultValue.value) == null ? void 0 : _b.value();
6478
+ }
6479
+ class AMFAnyTypeImpl extends AMFBaseType {
6480
+ constructor() {
6481
+ super(...arguments);
6482
+ this.type = "any";
6483
+ }
6484
+ }
6485
+ class AMFObjectTypeImpl extends AMFBaseType {
6486
+ constructor() {
6487
+ super(...arguments);
6488
+ this.type = "object";
6489
+ this.properties = {};
6490
+ this.resolved = false;
6491
+ this.additionalProperties = { type: "any" };
6492
+ }
6493
+ typeResolve() {
6494
+ var _a;
6495
+ if (((_a = this.shape.values) == null ? void 0 : _a.length) > 0) {
6496
+ this.fileParserLogger.error(
6497
+ this.shapePosition,
6498
+ `Type Error (${this.shape.name.value()}). Object type may not specify enum property.`
6499
+ );
6500
+ throw new Error();
6501
+ }
6502
+ this.logger.trace("Resolving properties");
6503
+ this.resolveProperties();
6504
+ this.logger.trace("Resolving additional properties");
6505
+ this.resolveAdditionalProperties();
6506
+ }
6507
+ resolveProperties() {
6508
+ for (const property of this.shape.properties) {
6509
+ const propertyName = property.name.value();
6510
+ const type = this.factory(
6511
+ this.api,
6512
+ property.range,
6513
+ this.typeRegistry,
6514
+ this.logger,
6515
+ this.fileParserLogger,
6516
+ true
6517
+ );
6518
+ type.resolve();
6519
+ const propertyType = {
6520
+ type,
6521
+ required: property.minCount.value() !== 0
6522
+ };
6523
+ this.properties[propertyName] = propertyType;
6337
6524
  }
6338
6525
  }
6339
- buildParams(p) {
6340
- const params = {};
6341
- p.forEach((param) => {
6342
- params[`${param.name.value()}`] = {
6343
- required: param.required.value(),
6344
- type: this.amfTypeFactory(
6345
- {},
6346
- param.schema,
6347
- this.typeRegistry,
6348
- this.logger,
6349
- this.fileParserLogger,
6350
- true
6351
- ),
6352
- explode: param.explode.value(),
6353
- defaultValue: this.getDefaultValue(param)
6526
+ resolveAdditionalProperties() {
6527
+ if (this.shape.closed.value()) {
6528
+ this.additionalProperties = {
6529
+ type: "not",
6530
+ not: { type: "any" }
6354
6531
  };
6355
- });
6356
- return params;
6532
+ } else if (this.shape.additionalPropertiesSchema) {
6533
+ this.additionalProperties = this.factory(
6534
+ this.api,
6535
+ this.shape.additionalPropertiesSchema,
6536
+ this.typeRegistry,
6537
+ this.logger,
6538
+ this.fileParserLogger,
6539
+ true
6540
+ );
6541
+ }
6357
6542
  }
6358
6543
  }
6359
- class AmfHttpOperation extends AmfBaseOperation {
6544
+ class AMFNilTypeImpl extends AMFBaseType {
6360
6545
  constructor() {
6361
6546
  super(...arguments);
6362
- this.type = "http";
6547
+ this.type = "nil";
6363
6548
  }
6364
6549
  }
6365
- class AmfHttpOperationWithRequestBody extends AmfBaseOperation {
6366
- constructor(amfOperation, amfTypeFactory2, typeRegistry, logger, fileParserLogger, endpoint, server) {
6367
- super(
6368
- amfOperation,
6369
- amfTypeFactory2,
6370
- typeRegistry,
6371
- logger,
6372
- fileParserLogger,
6373
- endpoint,
6374
- server
6550
+ class AMFNotTypeImpl extends AMFBaseType {
6551
+ constructor(api, shape, typeRegistry, factory, logger, fileParserLogger) {
6552
+ super(api, shape, typeRegistry, factory, logger, fileParserLogger);
6553
+ this.shape = shape;
6554
+ this.typeRegistry = typeRegistry;
6555
+ this.factory = factory;
6556
+ this.logger = logger;
6557
+ this.fileParserLogger = fileParserLogger;
6558
+ this.type = "not";
6559
+ const amfType = this.factory(
6560
+ this.api,
6561
+ this.shape.not,
6562
+ this.typeRegistry,
6563
+ this.logger,
6564
+ this.fileParserLogger
6375
6565
  );
6376
- this.type = "http";
6377
- const hasRequestBody = amfOperation.requests.some((request) => request.payloads.length > 0);
6378
- if (!hasRequestBody) {
6379
- throw new Error("Operation must have a request body defined");
6380
- }
6381
- this.method = amfOperation.method.value().toUpperCase();
6382
- const extensionsRaw = extractExtensions(amfOperation.customDomainProperties);
6383
- const extensionsResult = this.operationSchemaBuilder.buildHttpOperationSchema().default({}).safeParse(extensionsRaw);
6384
- if (!extensionsResult.success) {
6385
- const message = formatZodError(extensionsResult.error);
6386
- this.fileParserLogger.error(
6387
- this.amfOperation.position.start,
6388
- `Error validating aura operation:
6389
- ${message}`
6390
- );
6391
- throw new Error();
6392
- }
6393
- const extensions = extensionsResult.data;
6394
- if (!extensions.onestore.config["body-param"]) {
6395
- throw new Error("Missing body-param");
6396
- }
6397
- this.configBodyParam = extensions.onestore.config["body-param"];
6566
+ amfType.resolve();
6567
+ this.not = amfType;
6398
6568
  }
6399
6569
  }
6400
- class AmfAuraOperation extends AmfBaseOperation {
6401
- constructor(amfOperation, amfTypeFactory2, typeRegistry, logger, fileParserLogger, endpoint, server) {
6402
- super(
6403
- amfOperation,
6404
- amfTypeFactory2,
6405
- typeRegistry,
6406
- logger,
6407
- fileParserLogger,
6408
- endpoint,
6409
- server
6570
+ class AMFAllOfTypeImpl extends AMFBaseType {
6571
+ constructor() {
6572
+ super(...arguments);
6573
+ this.type = "allOf";
6574
+ this.allOf = [];
6575
+ }
6576
+ typeResolve() {
6577
+ this.logger.trace("Running resolution for inherited and composed shapes");
6578
+ const allOfTypes = [...this.shape.inherits, ...this.shape.and].map(
6579
+ (inheritedShape) => {
6580
+ return this.factory(
6581
+ this.api,
6582
+ inheritedShape,
6583
+ this.typeRegistry,
6584
+ this.logger,
6585
+ this.fileParserLogger,
6586
+ true
6587
+ );
6588
+ }
6410
6589
  );
6411
- this.type = "aura";
6412
- const hasRequestBody = amfOperation.requests.some((request) => request.payloads.length > 0);
6413
- if (hasRequestBody) {
6414
- throw new Error("Operation must not have a request body defined");
6590
+ const rootType = this.factory(
6591
+ this.api,
6592
+ this.shape,
6593
+ this.typeRegistry,
6594
+ this.logger,
6595
+ this.fileParserLogger,
6596
+ true,
6597
+ /* @__PURE__ */ new Set([
6598
+ "any",
6599
+ "ref",
6600
+ "array",
6601
+ "boolean",
6602
+ "date",
6603
+ "number",
6604
+ "datetime",
6605
+ "datetime-only",
6606
+ "double",
6607
+ "integer",
6608
+ "nil",
6609
+ "not",
6610
+ "number",
6611
+ "object",
6612
+ "string",
6613
+ "time"
6614
+ ]),
6615
+ true
6616
+ );
6617
+ this.allOf = [rootType, ...allOfTypes];
6618
+ if (isOneOfShape(this.shape)) {
6619
+ const OneOf = this.factory(
6620
+ this.api,
6621
+ this.shape,
6622
+ this.typeRegistry,
6623
+ this.logger,
6624
+ this.fileParserLogger,
6625
+ true,
6626
+ /* @__PURE__ */ new Set(["oneOf"]),
6627
+ true
6628
+ );
6629
+ this.allOf.push(OneOf);
6415
6630
  }
6416
- this.method = amfOperation.method.value().toUpperCase();
6417
- const extensionsRaw = extractExtensions(amfOperation.customDomainProperties);
6418
- const extensionsResult = this.operationSchemaBuilder.buildAuraOperationSchema().safeParse(extensionsRaw);
6419
- if (!extensionsResult.success) {
6420
- const message = formatZodError(extensionsResult.error);
6421
- this.fileParserLogger.error(
6422
- this.amfOperation.position.start,
6423
- `Error validating aura operation:
6424
- ${message}`
6631
+ if (isEnumShape(this.shape)) {
6632
+ const enumType2 = this.factory(
6633
+ this.api,
6634
+ this.shape,
6635
+ this.typeRegistry,
6636
+ this.logger,
6637
+ this.fileParserLogger,
6638
+ true,
6639
+ /* @__PURE__ */ new Set(["enum"]),
6640
+ true
6425
6641
  );
6426
- throw new Error();
6642
+ this.allOf.push(enumType2);
6427
6643
  }
6428
- const extensions = extensionsResult.data;
6429
- this.aura = { methodName: extensions.onestore.config.aura.method };
6644
+ this.validateDiscriminators();
6430
6645
  }
6431
- }
6432
- class AmfAuraOperationWithRequestBody extends AmfBaseOperation {
6433
- constructor(amfOperation, amfTypeFactory2, typeRegistry, logger, fileParserLogger, endpoint, server) {
6434
- super(
6435
- amfOperation,
6436
- amfTypeFactory2,
6437
- typeRegistry,
6438
- logger,
6439
- fileParserLogger,
6440
- endpoint,
6441
- server
6442
- );
6443
- this.type = "aura";
6444
- const hasRequestBody = amfOperation.requests.some((request) => request.payloads.length > 0);
6445
- if (!hasRequestBody) {
6446
- throw new Error("Operation must have a request body defined");
6646
+ includes(t) {
6647
+ return this.allOf.some((parent) => {
6648
+ const canonicalizedParent = canonicalizeType(parent);
6649
+ if (canonicalizedParent === t) {
6650
+ return true;
6651
+ }
6652
+ return canonicalizedParent.type === "allOf" && canonicalizedParent.includes(t);
6653
+ });
6654
+ }
6655
+ get discriminatedParent() {
6656
+ var _a;
6657
+ const discriminatedParents = [
6658
+ ...bfs(
6659
+ [this],
6660
+ (type) => {
6661
+ return isDiscriminatedObjectType(type);
6662
+ },
6663
+ (type) => {
6664
+ return type.type === "allOf" ? type.allOf : type.type === "ref" ? [type.$ref] : [];
6665
+ }
6666
+ ).values()
6667
+ ];
6668
+ if (discriminatedParents.length === 0) {
6669
+ return;
6447
6670
  }
6448
- this.method = amfOperation.method.value().toUpperCase();
6449
- const extensionsRaw = extractExtensions(amfOperation.customDomainProperties);
6450
- const extensionsResult = this.operationSchemaBuilder.buildAuraOperationWithBodySchema().safeParse(extensionsRaw);
6451
- if (!extensionsResult.success) {
6452
- const message = formatZodError(extensionsResult.error);
6671
+ if (discriminatedParents.length > 1) {
6672
+ const { line = 0, column = 0 } = ((_a = this.shape.position) == null ? void 0 : _a.start) || {};
6453
6673
  this.fileParserLogger.error(
6454
- this.amfOperation.position.start,
6455
- `Error validating aura operation:
6456
- ${message}`
6674
+ { line, column },
6675
+ `Type ${this.typeRegistry.nameOf(
6676
+ this
6677
+ )} cannot inherit from multiple discriminated objects. Inherits from ${discriminatedParents.map(
6678
+ (parent) => this.typeRegistry.nameOf(parent)
6679
+ )}.`
6457
6680
  );
6458
6681
  throw new Error();
6459
6682
  }
6460
- const extensions = extensionsResult.data;
6461
- if (extensions.onestore.config["body-param"] === void 0) {
6462
- throw new Error("Missing body param");
6463
- }
6464
- if (extensions.onestore.config.aura["body-param"] === void 0) {
6465
- throw new Error("Missing aura body param");
6466
- }
6467
- this.configBodyParam = extensions.onestore.config["body-param"];
6468
- this.aura = {
6469
- methodName: extensions.onestore.config.aura.method,
6470
- bodyParam: extensions.onestore.config.aura["body-param"]
6471
- };
6683
+ return discriminatedParents[0];
6684
+ }
6685
+ validateDiscriminators() {
6686
+ this.discriminatedParent;
6472
6687
  }
6473
- }
6474
- function AmfGraphQLOperationMixin(Base) {
6475
- return class AmfGraphQLOperation extends Base {
6476
- constructor(...args) {
6477
- super(...args);
6478
- this.operationType = "graphql";
6479
- this.graphqlConfig = this.setupGraphQLConfig();
6688
+ get extensions() {
6689
+ var _a, _b;
6690
+ if (super.extensions.type === "identifiable") {
6691
+ return super.extensions;
6480
6692
  }
6481
- setupGraphQLConfig() {
6482
- const extensionsRaw = extractExtensions(this.amfOperation.customDomainProperties);
6483
- const extensionsResult = this.operationSchemaBuilder.buildGraphQLOperationSchema().safeParse(extensionsRaw);
6484
- if (!extensionsResult.success) {
6485
- const message = formatZodError(extensionsResult.error);
6486
- this.fileParserLogger.error(
6487
- this.amfOperation.position.start,
6488
- `Error validating graphql operation:
6489
- ${message}`
6490
- );
6491
- throw new Error(message);
6492
- }
6493
- const extensions = extensionsResult.data;
6494
- const config = {
6495
- schemaFilePath: extensions.onestore.config.graphql.schema,
6496
- "type-metadata": extensions.onestore.config.graphql["type-metadata"]
6497
- };
6498
- return config;
6693
+ if (((_b = (_a = this.discriminatedParent) == null ? void 0 : _a.extensions) == null ? void 0 : _b.type) === "identifiable") {
6694
+ return this.discriminatedParent.extensions;
6499
6695
  }
6500
- };
6696
+ return super.extensions;
6697
+ }
6501
6698
  }
6502
- const endpointSchema = z.object({
6503
- onestore: z.discriminatedUnion("endpoint-type", [
6504
- z.object({
6505
- "endpoint-type": z.literal("http")
6506
- }).strict(),
6507
- z.object({
6508
- "endpoint-type": z.literal("aura"),
6509
- config: z.object({
6510
- aura: z.object({
6511
- controller: z.string()
6512
- })
6513
- }),
6514
- "network-preference": z.enum(["aura", "http"]).default("aura")
6515
- }).strict()
6516
- ]).optional()
6517
- });
6518
- const partialOperationSchema = z.object({
6519
- onestore: z.object({
6520
- config: z.object({
6521
- "operation-type": z.enum(["query", "mutation", "graphql"]).optional()
6522
- }).passthrough().optional()
6523
- }).passthrough().optional()
6524
- });
6525
- function createAmfAuraEndpoint(amfEndpoint, amfTypeFactory2, typeRegistry, logger, fileParserLogger, server, api, networkPreference) {
6526
- const endpoint = new AmfAuraEndpoint(
6527
- amfEndpoint,
6528
- [],
6529
- amfTypeFactory2,
6530
- typeRegistry,
6531
- logger,
6532
- fileParserLogger,
6533
- api,
6534
- networkPreference
6535
- );
6536
- const operations = amfEndpoint.operations.map((operation) => {
6537
- var _a, _b;
6538
- const extensionsRaw = extractExtensions(operation.customDomainProperties);
6539
- const operationConfigValidationResult = partialOperationSchema.safeParse(extensionsRaw);
6540
- if (!operationConfigValidationResult.success) {
6541
- const message = formatZodError(operationConfigValidationResult.error);
6542
- fileParserLogger.error(
6543
- operation.position.start,
6544
- `Errors validating operation:
6545
- ${message}`
6699
+ class AMFEnumerableScalarType extends AMFBaseType {
6700
+ typeResolve() {
6701
+ var _a;
6702
+ if (((_a = this.shape.values) == null ? void 0 : _a.length) > 0) {
6703
+ this.values = getEnumValuesFromShape(this.shape);
6704
+ }
6705
+ if (this.parsedExtensions.type === "identifiable") {
6706
+ this.fileParserLogger.error(
6707
+ this.shape.position.start,
6708
+ `${this.shape.name} is scalar and thus cannot be made identifiable by specifying a key`
6546
6709
  );
6547
6710
  throw new Error();
6548
6711
  }
6549
- const hasRequestBody = operation.requests.some((request) => request.payloads.length > 0);
6550
- const isGraphQLOperation = ((_b = (_a = operationConfigValidationResult.data.onestore) == null ? void 0 : _a.config) == null ? void 0 : _b["operation-type"]) === "graphql";
6551
- let baseClass = isGraphQLOperation ? AmfGraphQLOperationMixin(
6552
- hasRequestBody ? AmfAuraOperationWithRequestBody : AmfAuraOperation
6553
- ) : hasRequestBody ? AmfAuraOperationWithRequestBody : AmfAuraOperation;
6554
- return new baseClass(
6555
- operation,
6556
- amfTypeFactory2,
6557
- typeRegistry,
6558
- logger,
6559
- fileParserLogger,
6560
- endpoint,
6561
- server
6562
- );
6563
- });
6564
- endpoint.operations = operations;
6565
- return endpoint;
6712
+ }
6566
6713
  }
6567
- function createAmfHttpEndpoint(amfEndpoint, amfTypeFactory2, typeRegistry, logger, fileParserLogger, server, api) {
6568
- const endpoint = new AmfHttpEndPoint(
6569
- amfEndpoint,
6570
- [],
6571
- amfTypeFactory2,
6572
- typeRegistry,
6573
- logger,
6574
- fileParserLogger,
6575
- api
6576
- );
6577
- const operations = amfEndpoint.operations.map((operation) => {
6578
- var _a, _b;
6579
- const operationConfigValidationResult = partialOperationSchema.safeParse(
6580
- extractExtensions(operation.customDomainProperties)
6581
- );
6582
- if (!operationConfigValidationResult.success) {
6583
- const message = formatZodError(operationConfigValidationResult.error);
6584
- const errorMessage = `Error validating operation:
6585
- ${message}`;
6586
- fileParserLogger.error(operation.position.start, errorMessage);
6587
- throw new Error(errorMessage);
6588
- }
6589
- const hasRequestBody = operation.requests.some((request) => request.payloads.length > 0);
6590
- const isGraphQLOperation = ((_b = (_a = operationConfigValidationResult.data.onestore) == null ? void 0 : _a.config) == null ? void 0 : _b["operation-type"]) === "graphql";
6591
- let baseClass = isGraphQLOperation ? AmfGraphQLOperationMixin(
6592
- hasRequestBody ? AmfHttpOperationWithRequestBody : AmfHttpOperation
6593
- ) : hasRequestBody ? AmfHttpOperationWithRequestBody : AmfHttpOperation;
6594
- return new baseClass(
6595
- operation,
6596
- amfTypeFactory2,
6597
- typeRegistry,
6598
- logger,
6599
- fileParserLogger,
6600
- endpoint,
6601
- server
6602
- );
6603
- });
6604
- endpoint.operations = operations;
6605
- return endpoint;
6714
+ class AMFBooleanTypeImpl extends AMFEnumerableScalarType {
6715
+ constructor() {
6716
+ super(...arguments);
6717
+ this.type = "boolean";
6718
+ }
6606
6719
  }
6607
- function amfEndpointFactory(amfEndpoint, amfTypeFactory2, typeRegistry, logger, fileParserLogger, server, api) {
6608
- const endpointConfigValidationResult = endpointSchema.safeParse(
6609
- extractExtensions(amfEndpoint.customDomainProperties)
6610
- );
6611
- if (!endpointConfigValidationResult.success) {
6612
- const message = formatZodError(endpointConfigValidationResult.error);
6613
- const errorMessage = `Error validating endpoint:
6614
- ${message}`;
6615
- fileParserLogger.error(amfEndpoint.position.start, errorMessage);
6616
- throw new Error(errorMessage);
6720
+ class AMFDoubleTypeImpl extends AMFEnumerableScalarType {
6721
+ constructor() {
6722
+ super(...arguments);
6723
+ this.type = "double";
6617
6724
  }
6618
- const config = endpointConfigValidationResult.data;
6619
- if (config.onestore === void 0) {
6620
- return void 0;
6725
+ }
6726
+ class AMFIntegerTypeImpl extends AMFEnumerableScalarType {
6727
+ constructor() {
6728
+ super(...arguments);
6729
+ this.type = "integer";
6621
6730
  }
6622
- const endpoint = config.onestore["endpoint-type"] === "aura" ? createAmfAuraEndpoint(
6623
- amfEndpoint,
6624
- amfTypeFactory2,
6625
- typeRegistry,
6626
- logger,
6627
- fileParserLogger,
6628
- server,
6629
- api,
6630
- config.onestore["network-preference"]
6631
- ) : createAmfHttpEndpoint(
6632
- amfEndpoint,
6633
- amfTypeFactory2,
6634
- typeRegistry,
6635
- logger,
6636
- fileParserLogger,
6637
- server,
6638
- api
6639
- );
6640
- if (!validateUniqueBindingIdentfiers(endpoint.operations)) {
6641
- const errorMessage = `All operations must have unique bindings`;
6642
- fileParserLogger.error(amfEndpoint.position.start, errorMessage);
6643
- throw new Error(errorMessage);
6731
+ }
6732
+ class AMFNumberTypeImpl extends AMFEnumerableScalarType {
6733
+ constructor() {
6734
+ super(...arguments);
6735
+ this.type = "number";
6736
+ }
6737
+ }
6738
+ class AMFStringTypeImpl extends AMFEnumerableScalarType {
6739
+ constructor() {
6740
+ super(...arguments);
6741
+ this.type = "string";
6742
+ }
6743
+ }
6744
+ class AMFDateTypeImpl extends AMFEnumerableScalarType {
6745
+ constructor() {
6746
+ super(...arguments);
6747
+ this.type = "date";
6748
+ }
6749
+ }
6750
+ const DATE = "date";
6751
+ const DATE_TIME = "date-time";
6752
+ class AMFDateTimeImpl extends AMFEnumerableScalarType {
6753
+ constructor(api, shape, typeRegistry, factory, logger, fileParserLogger) {
6754
+ super(api, shape, typeRegistry, factory, logger, fileParserLogger);
6755
+ this.shape = shape;
6756
+ this.type = "datetime";
6757
+ const formatValue = shape.format.value();
6758
+ this.format = formatValue === DATE ? DATE : DATE_TIME;
6759
+ }
6760
+ }
6761
+ class AMFOneOfTypeImpl extends AMFBaseType {
6762
+ constructor() {
6763
+ super(...arguments);
6764
+ this.type = "oneOf";
6765
+ this.oneOf = [];
6766
+ }
6767
+ typeResolve() {
6768
+ var _a;
6769
+ let { anyOf = [], xone = [] } = this.shape;
6770
+ this.oneOf = [...anyOf, ...xone].map((subTypeShape) => {
6771
+ const subType = this.factory(
6772
+ this.api,
6773
+ subTypeShape,
6774
+ this.typeRegistry,
6775
+ this.logger,
6776
+ this.fileParserLogger
6777
+ );
6778
+ subType.resolve();
6779
+ return subType;
6780
+ });
6781
+ if (((_a = this.shape.values) == null ? void 0 : _a.length) > 0) {
6782
+ this.values = getEnumValuesFromShape(this.shape);
6783
+ }
6784
+ this.preserveIdentifiableExtensionsFromNullablePattern();
6785
+ }
6786
+ /**
6787
+ * When AMF encounters 'nullable: true' on an object with identifiable extensions,
6788
+ * it converts it to a oneOf with [object, null]. This method detects this pattern
6789
+ * and preserves the identifiable extensions from the object member on the union.
6790
+ */
6791
+ preserveIdentifiableExtensionsFromNullablePattern() {
6792
+ var _a;
6793
+ if (this.oneOf.length !== 2) {
6794
+ return;
6795
+ }
6796
+ const nullMember = this.oneOf.find((member) => member.type === "nil");
6797
+ const objectMember = this.oneOf.find((member) => member.type === "object");
6798
+ if (!nullMember || !objectMember) {
6799
+ return;
6800
+ }
6801
+ if (((_a = objectMember.extensions) == null ? void 0 : _a.type) === "identifiable") {
6802
+ this.parsedExtensions = { ...objectMember.extensions };
6803
+ }
6644
6804
  }
6645
- return endpoint;
6646
6805
  }
6647
- class AmfBaseEndpoint {
6648
- constructor(amfEndpoint, operations, amfTypeFactory2, typeRegistry, logger, fileParserLogger, api) {
6649
- this.amfEndpoint = amfEndpoint;
6650
- this.operations = operations;
6806
+ class AMFEnumTypeImpl extends AMFBaseType {
6807
+ constructor(api, shape, typeRegistry, factory, logger, fileParserLogger) {
6808
+ super(api, shape, typeRegistry, factory, logger, fileParserLogger);
6809
+ this.shape = shape;
6810
+ this.typeRegistry = typeRegistry;
6811
+ this.factory = factory;
6651
6812
  this.logger = logger;
6652
6813
  this.fileParserLogger = fileParserLogger;
6653
- this.api = api;
6654
- this.path = this.amfEndpoint.path.value();
6655
- this.uriParameters = {};
6656
- this.amfEndpoint.parameters.forEach((param) => {
6657
- this.uriParameters[`${param.name}`] = {
6658
- required: param.required.value(),
6659
- type: amfTypeFactory2(
6660
- this.api,
6661
- param.schema,
6662
- typeRegistry,
6663
- logger,
6664
- fileParserLogger,
6665
- true
6666
- ),
6667
- explode: param.explode.value()
6668
- };
6669
- });
6814
+ this.type = "enum";
6815
+ this.values = [];
6816
+ this.values = getEnumValuesFromShape(shape);
6670
6817
  }
6671
6818
  }
6672
- class AmfHttpEndPoint extends AmfBaseEndpoint {
6819
+ class AMFRefTypeImpl extends AMFBaseType {
6673
6820
  constructor() {
6674
6821
  super(...arguments);
6675
- this.type = "http";
6822
+ this.type = "ref";
6823
+ this.$ref = {
6824
+ type: "not",
6825
+ not: { type: "any" }
6826
+ };
6827
+ this.resolved = false;
6828
+ }
6829
+ typeResolve() {
6830
+ this.logger.trace(`Resolving $ref at ${this.shape.id.split("#")[1]}`);
6831
+ if (this.shape.isLink && this.shape.linkTarget) {
6832
+ const inheritedType = this.typeRegistry.get(this.shape.linkLabel.toString());
6833
+ if (inheritedType) {
6834
+ this.logger.trace(`Found ${inheritedType.shape.name} for $ref`);
6835
+ inheritedType.resolve();
6836
+ this.$ref = inheritedType;
6837
+ } else {
6838
+ const errorMessage = `Failed to resolve $ref: ${this.shape.linkLabel.toString()} from ${this.shape.id}`;
6839
+ this.fileParserLogger.error(this.shapePosition, errorMessage);
6840
+ throw new Error(errorMessage);
6841
+ }
6842
+ }
6676
6843
  }
6677
6844
  }
6678
- class AmfAuraEndpoint extends AmfBaseEndpoint {
6679
- constructor(amfEndPoint, operations, amfTypeFactory2, typeRegistry, logger, fileParserLogger, api, networkPreference) {
6680
- super(amfEndPoint, operations, amfTypeFactory2, typeRegistry, logger, fileParserLogger, api);
6845
+ class AMFDiscriminatedObjectTypeImpl extends AMFBaseType {
6846
+ constructor(api, shape, typeRegistry, factory, logger, fileParserLogger) {
6847
+ super(api, shape, typeRegistry, factory, logger, fileParserLogger);
6848
+ this.shape = shape;
6849
+ this.typeRegistry = typeRegistry;
6850
+ this.factory = factory;
6681
6851
  this.logger = logger;
6682
6852
  this.fileParserLogger = fileParserLogger;
6683
- this.api = api;
6684
- this.networkPreference = networkPreference;
6685
- this.type = "aura";
6686
- this.auraController = this.buildAuraController();
6687
- }
6688
- buildAuraController() {
6689
- const configResult = endpointSchema.safeParse(
6690
- extractExtensions(this.amfEndpoint.customDomainProperties)
6853
+ this.type = "discriminatedObject";
6854
+ this._mapping = void 0;
6855
+ if (this.shape.discriminator.isNullOrEmpty) {
6856
+ this.fileParserLogger.error(
6857
+ this.shapePosition,
6858
+ "Supplied shape does not provide a discriminator"
6859
+ );
6860
+ throw new Error();
6861
+ }
6862
+ this.discriminator = this.shape.discriminator.value();
6863
+ this.baseType = factory(
6864
+ api,
6865
+ shape,
6866
+ typeRegistry,
6867
+ logger,
6868
+ fileParserLogger,
6869
+ false,
6870
+ /* @__PURE__ */ new Set(["object"])
6691
6871
  );
6692
- if (!configResult.success) {
6693
- const message = formatZodError(configResult.error);
6694
- const errorMessage = `Error validating aura endpoint:
6695
- ${message}`;
6696
- this.fileParserLogger.error(this.amfEndpoint.position.start, errorMessage);
6697
- throw new Error(errorMessage);
6872
+ }
6873
+ typeResolve() {
6874
+ this.baseType.resolve();
6875
+ if (this.typeRegistry.nameOf(this) === void 0) {
6876
+ this.fileParserLogger.error(
6877
+ this.shapePosition,
6878
+ "Cannot use discriminator on inline types."
6879
+ );
6880
+ throw new Error();
6698
6881
  }
6699
- const config = configResult.data;
6700
- if (!config.onestore || config.onestore["endpoint-type"] !== "aura") {
6701
- throw new Error("invalid config");
6882
+ }
6883
+ get mapping() {
6884
+ if (this._mapping === void 0) {
6885
+ this._mapping = {};
6886
+ this.resolveDiscriminator();
6702
6887
  }
6703
- const name = config.onestore.config.aura.controller;
6704
- if (name === void 0) {
6705
- throw new Error("Aura controller name must be defined for an Aura endpoint.");
6888
+ return this._mapping;
6889
+ }
6890
+ resolveDiscriminator() {
6891
+ this.buildExplicitMapping();
6892
+ this.buildImplicitMapping();
6893
+ }
6894
+ /**
6895
+ * Adds implicit discriminator values (i.e., type names) as mappings to types
6896
+ *
6897
+ * @private
6898
+ */
6899
+ buildImplicitMapping() {
6900
+ const oneOfNames = this.shape.xone.reduce((result, shape) => {
6901
+ if (shape.isLink) {
6902
+ result.push(shape.linkLabel.value());
6903
+ }
6904
+ return result;
6905
+ }, []);
6906
+ this.typeRegistry.forEach((type, name) => {
6907
+ type.resolve();
6908
+ if ((type.type === "allOf" && type.includes(this) || oneOfNames.includes(name)) && !Object.values(this._mapping).includes(type)) {
6909
+ this._mapping[name] = type;
6910
+ }
6911
+ });
6912
+ }
6913
+ /**
6914
+ * Adds explicit discriminator values as mappings to types
6915
+ *
6916
+ * @private
6917
+ */
6918
+ buildExplicitMapping() {
6919
+ this.shape.discriminatorMapping.forEach((el) => {
6920
+ const value = el.templateVariable.value();
6921
+ const linkExpressionSplit = el.linkExpression.value().split("/");
6922
+ const typeName = linkExpressionSplit[linkExpressionSplit.length - 1];
6923
+ const type = this.typeRegistry.get(typeName);
6924
+ if (type === void 0) {
6925
+ this.fileParserLogger.error(this.shapePosition, `Cannot find type ${typeName}`);
6926
+ throw new Error();
6927
+ }
6928
+ this._mapping[value] = type;
6929
+ });
6930
+ }
6931
+ }
6932
+ function amfTypeFactory(api, shape, typeRegistry, logger, fileParserLogger, resolve = false, allowedTypes = void 0, skipRegistry = false) {
6933
+ var _a;
6934
+ if (!skipRegistry) {
6935
+ for (const [_, type] of typeRegistry.entries()) {
6936
+ if (shape.id === type.shape.id) {
6937
+ return type;
6938
+ }
6939
+ }
6940
+ }
6941
+ const { line = 0, column = 0 } = ((_a = shape.position) == null ? void 0 : _a.start) || {};
6942
+ let ctor;
6943
+ if (isAnyOfShape(shape)) {
6944
+ fileParserLogger.error(
6945
+ { line, column },
6946
+ `anyOf is not suppoort, found in type ${shape.name.value()}`
6947
+ );
6948
+ throw new Error();
6949
+ }
6950
+ if (isRefShape(shape)) {
6951
+ ctor = AMFRefTypeImpl;
6952
+ } else if ((!allowedTypes || allowedTypes.has("allOf")) && isAllOfShape(shape)) {
6953
+ ctor = AMFAllOfTypeImpl;
6954
+ } else if ((!allowedTypes || allowedTypes.has("oneOf")) && isOneOfShape(shape)) {
6955
+ ctor = AMFOneOfTypeImpl;
6956
+ } else if ((!allowedTypes || allowedTypes.has("enum")) && isEnumShape(shape)) {
6957
+ ctor = AMFEnumTypeImpl;
6958
+ } else if ((!allowedTypes || allowedTypes.has("nil")) && isNilShape(shape)) {
6959
+ ctor = AMFNilTypeImpl;
6960
+ } else if (isScalarShape(shape) && shape.dataType.value() in DATATYPE_TO_SCALAR_TYPE && (!allowedTypes || allowedTypes.has(DATATYPE_TO_SCALAR_TYPE[shape.dataType.value()]))) {
6961
+ const scalarType = DATATYPE_TO_SCALAR_TYPE[shape.dataType.value()];
6962
+ switch (scalarType) {
6963
+ case "string":
6964
+ ctor = AMFStringTypeImpl;
6965
+ break;
6966
+ case "number":
6967
+ ctor = AMFNumberTypeImpl;
6968
+ break;
6969
+ case "boolean":
6970
+ ctor = AMFBooleanTypeImpl;
6971
+ break;
6972
+ case "double":
6973
+ ctor = AMFDoubleTypeImpl;
6974
+ break;
6975
+ case "integer":
6976
+ ctor = AMFIntegerTypeImpl;
6977
+ break;
6978
+ case "date":
6979
+ ctor = AMFDateTypeImpl;
6980
+ break;
6981
+ case "datetime":
6982
+ ctor = AMFDateTimeImpl;
6983
+ break;
6984
+ default:
6985
+ fileParserLogger.error(
6986
+ { line, column },
6987
+ `type of shape ${shape.name.value()} not recognized`
6988
+ );
6989
+ throw new Error();
6990
+ }
6991
+ } else if ((!allowedTypes || allowedTypes.has("discriminatedObject")) && isNodeShape(shape) && !shape.discriminator.isNullOrEmpty) {
6992
+ ctor = AMFDiscriminatedObjectTypeImpl;
6993
+ } else if ((!allowedTypes || allowedTypes.has("object")) && isNodeShape(shape)) {
6994
+ ctor = AMFObjectTypeImpl;
6995
+ } else if ((!allowedTypes || allowedTypes.has("array")) && isArrayShape(shape)) {
6996
+ ctor = AMFArrayTypeImpl;
6997
+ } else if ((!allowedTypes || allowedTypes.has("not")) && isNotShape(shape)) {
6998
+ ctor = AMFNotTypeImpl;
6999
+ } else if ((!allowedTypes || allowedTypes.has("any")) && isAnyShape(shape)) {
7000
+ ctor = AMFAnyTypeImpl;
7001
+ } else {
7002
+ fileParserLogger.error(
7003
+ { line, column },
7004
+ `type of shape ${shape.name.value()} not recognized`
7005
+ );
7006
+ throw new Error();
7007
+ }
7008
+ const result = new ctor(api, shape, typeRegistry, amfTypeFactory, logger, fileParserLogger);
7009
+ if (resolve) {
7010
+ result.resolve();
7011
+ }
7012
+ return result;
7013
+ }
7014
+ class AMFArrayTypeImpl extends AMFBaseType {
7015
+ constructor() {
7016
+ super(...arguments);
7017
+ this.type = "array";
7018
+ this.items = { type: "any" };
7019
+ }
7020
+ typeResolve() {
7021
+ if (this.shape.items) {
7022
+ const items = amfTypeFactory(
7023
+ this.api,
7024
+ this.shape.items,
7025
+ this.typeRegistry,
7026
+ this.logger,
7027
+ this.fileParserLogger
7028
+ );
7029
+ items.resolve();
7030
+ this.items = items;
6706
7031
  }
6707
- return { name };
6708
7032
  }
6709
7033
  }
6710
- const rootSchema = z.object({
6711
- onestore: z.object({
6712
- version: z.string().refine(stringIsVersion, () => {
6713
- return {
6714
- message: "Version must satisfy format major[.minor[.patch]]"
6715
- };
6716
- })
6717
- })
6718
- });
6719
7034
  function getAmfAnnotationVersion(webApi) {
6720
7035
  const configRaw = extractExtensions(webApi.customDomainProperties);
6721
- const config = rootSchema.safeParse(configRaw);
7036
+ const config = rootExtensionSchema.safeParse(configRaw);
6722
7037
  if (!config.success) {
6723
7038
  const validationMessage = formatZodError(config.error);
6724
7039
  throw new Error(`Error validating root x-onestore extension:
@@ -6773,28 +7088,6 @@ ${formattedValidation}`;
6773
7088
  }
6774
7089
  return isValid2;
6775
7090
  }
6776
- const V1_VERSION = "1.0.0";
6777
- const oneStoreExtensionsSchema = z.object({
6778
- onestore: z.object({
6779
- defaults: z.object({
6780
- operations: z.object({
6781
- "cache-strategy": z.discriminatedUnion("type", [
6782
- z.object({ type: z.literal("none") }).strict(),
6783
- z.object({ type: z.literal("resource") }).strict(),
6784
- z.object({ type: z.literal("normalized") }).strict()
6785
- ])
6786
- }),
6787
- schemas: z.object({
6788
- "cache-control": cacheControl
6789
- })
6790
- }).partial().strict().optional(),
6791
- // Allow service catalog at root-level for reliability
6792
- services: servicesCatalogSchema.optional(),
6793
- namespace: z.string().optional(),
6794
- version: z.string()
6795
- }).strict()
6796
- });
6797
- const ANONYMOUS_TYPE_NAME = "<anonymous>";
6798
7091
  class AMFAPI {
6799
7092
  constructor(document, services, fileParserlogger) {
6800
7093
  this.document = document;
@@ -6840,381 +7133,126 @@ class AMFAPI {
6840
7133
  if (this.webApi.servers.length === 0) {
6841
7134
  this.fileParserlogger.error(
6842
7135
  { line: this.webApi.position.lineFrom, column: this.webApi.position.columnFrom },
6843
- `At least one server must be specified in your OpenAPI file. e.g.:
6844
- servers:
6845
- - url: http://localhost:3000
6846
- description: Local development server`
6847
- );
6848
- throw new Error();
6849
- }
6850
- this._servers = this.webApi.servers.map((s) => {
6851
- const uriParameters = {};
6852
- s.variables.forEach((param) => {
6853
- uriParameters[`${param.name.value()}`] = {
6854
- required: param.required.value(),
6855
- type: amfTypeFactory(
6856
- this,
6857
- param.schema,
6858
- this.types,
6859
- this.services.logger,
6860
- this.fileParserlogger
6861
- ),
6862
- explode: param.explode.value()
6863
- };
6864
- });
6865
- return {
6866
- url: s.url.value(),
6867
- uriParameters
6868
- };
6869
- });
6870
- }
6871
- buildTypes() {
6872
- this.services.logger.debug("AMFAPI - Building the type registry");
6873
- const typeRegistry = this.typeRegistry = new BaseTypeRegistry();
6874
- this.document.declares.filter(isTypeShape).forEach((shape) => {
6875
- const name = shape.name.value();
6876
- this.services.logger.debug(`AMFAPI - Building AMF Type for ${name}`);
6877
- const amfType = amfTypeFactory(
6878
- this,
6879
- shape,
6880
- typeRegistry,
6881
- this.services.logger,
6882
- this.fileParserlogger
6883
- );
6884
- this.services.logger.debug(`AMFAPI - Setting ${name} in type registry`);
6885
- typeRegistry.set(shape.name.value(), amfType);
6886
- });
6887
- typeRegistry.forEach((type, name) => {
6888
- this.services.logger.debug(`AMFAPI - Resolving type ${name}`);
6889
- type.resolve();
6890
- });
6891
- }
6892
- get webApi() {
6893
- return this.document.encodes;
6894
- }
6895
- get endpoints() {
6896
- this.build();
6897
- return this._endpoints;
6898
- }
6899
- get defaults() {
6900
- const operationCacheStrategy2 = this.parsedDefaultOperationCacheStrategyType ?? { type: "none" };
6901
- const typeCacheControl = this.parsedDefaultTypeCacheControl;
6902
- const services = resolveDefaultServiceOverrides(this.serviceOverrides);
6903
- return {
6904
- operationCacheStrategy: operationCacheStrategy2,
6905
- typeCacheControl,
6906
- services
6907
- };
6908
- }
6909
- get servers() {
6910
- this.build();
6911
- return this._servers;
6912
- }
6913
- get types() {
6914
- this.build();
6915
- return this.typeRegistry;
6916
- }
6917
- get namespace() {
6918
- if (this.parsedNamespace === void 0) {
6919
- return this.defaultedNamespace;
6920
- }
6921
- return this.parsedNamespace;
6922
- }
6923
- checkAnnotationsVersion() {
6924
- const version = getAmfAnnotationVersion(this.webApi);
6925
- if (!satisfies(V1_VERSION, version)) {
6926
- throw new Error(
6927
- `Version ${version} requested cannot be satisfied by version ${V1_VERSION} of the AMF API.`
6928
- );
6929
- }
6930
- }
6931
- setRootLevelAnnotations() {
6932
- var _a, _b, _c, _d;
6933
- const extensionsRaw = extractExtensions(this.webApi.customDomainProperties);
6934
- const oneStoreExtensionsResult = oneStoreExtensionsSchema.safeParse(extensionsRaw);
6935
- if (!oneStoreExtensionsResult.success) {
6936
- const message = formatZodError(oneStoreExtensionsResult.error);
6937
- throw new Error(message);
6938
- }
6939
- const onestore = oneStoreExtensionsResult.data.onestore;
6940
- this.parsedDefaultOperationCacheStrategyType = (_b = (_a = onestore == null ? void 0 : onestore.defaults) == null ? void 0 : _a.operations) == null ? void 0 : _b["cache-strategy"];
6941
- this.parsedDefaultTypeCacheControl = (_d = (_c = onestore == null ? void 0 : onestore.defaults) == null ? void 0 : _c.schemas) == null ? void 0 : _d["cache-control"];
6942
- this.parsedNamespace = onestore == null ? void 0 : onestore.namespace;
6943
- if (this.parsedNamespace === void 0) {
6944
- this.services.logger.warn(
6945
- `AMFAPI - namespace is missing, will be defaulted "${this.defaultedNamespace}".`
6946
- );
6947
- }
6948
- if (onestore == null ? void 0 : onestore.services) {
6949
- this.serviceOverrides = validateAndNormalizeCatalog(onestore.services);
6950
- }
6951
- }
6952
- /**
6953
- * Validates all endpoints and types. A validation error will be thrown if any are invalid.
6954
- *
6955
- * @protected
6956
- */
6957
- validate() {
6958
- if (!isValidAmfAPI(this, this.fileParserlogger)) {
6959
- throw new Error("API OneStore configuration failed validation");
6960
- }
6961
- }
6962
- }
6963
- class NoNormalizedTypesValidator {
6964
- constructor(types) {
6965
- this.types = types;
6966
- }
6967
- validate(operation) {
6968
- if (isNormalizedOperation(operation)) {
6969
- return ok([]);
6970
- }
6971
- const identifiableTypes = /* @__PURE__ */ new Set();
6972
- operation.responses.forEach((response) => {
6973
- return response.payloads.forEach((payload) => {
6974
- this.findNestedIdentifiableTypes(payload.data).forEach(
6975
- (type) => identifiableTypes.add(type)
6976
- );
6977
- });
6978
- });
6979
- const messages = [];
6980
- if (identifiableTypes.size > 0) {
6981
- identifiableTypes.forEach((type) => {
6982
- const typeName = this.types.nameOf(type) || ANONYMOUS_TYPE_NAME;
6983
- messages.push(
6984
- getFormattedMessage(
6985
- operation,
6986
- `Operation ${operation.operationId ? `${operation.operationId} ` : ``}is not normalized but references the normalized type ${typeName} in its response`
6987
- )
6988
- );
6989
- });
6990
- return messages.length === 0 ? ok([]) : err(messages);
6991
- }
6992
- return ok([]);
6993
- }
6994
- /**
6995
- * Completes a breadth-first search of a Type to locate any nested types that are identifiable.
6996
- *
6997
- * @returns a Set of all nested types that are identifiable.
6998
- * @param start
6999
- * @protected
7000
- */
7001
- findNestedIdentifiableTypes(start) {
7002
- return bfs(
7003
- [start],
7004
- (type) => {
7005
- var _a;
7006
- return ((_a = type.extensions) == null ? void 0 : _a.type) === "identifiable";
7007
- },
7008
- (type) => {
7009
- const typing = type.type;
7010
- switch (typing) {
7011
- case "allOf":
7012
- return type.allOf;
7013
- case "array":
7014
- return [type.items];
7015
- case "object":
7016
- return [
7017
- ...Object.values(type.properties).map((property) => property.type),
7018
- type.additionalProperties
7019
- ];
7020
- case "oneOf":
7021
- return type.oneOf;
7022
- case "ref":
7023
- return [type.$ref];
7024
- case "discriminatedObject":
7025
- return [...Object.values(type.mapping), type.baseType];
7026
- case "any":
7027
- case "enum":
7028
- case "boolean":
7029
- case "double":
7030
- case "integer":
7031
- case "number":
7032
- case "string":
7033
- case "date":
7034
- case "datetime":
7035
- case "datetime-only":
7036
- case "nil":
7037
- case "not":
7038
- case "time":
7039
- return [];
7040
- default:
7041
- throw new Error(
7042
- `${typing} has not been accounted for when searching for nested identifiable types`
7043
- );
7044
- }
7045
- }
7046
- );
7047
- }
7048
- }
7049
- class KeyMatchValidator {
7050
- constructor(types) {
7051
- this.types = types;
7052
- }
7053
- validate(operation) {
7054
- if (!isNormalizedOperation(operation)) {
7055
- return ok([]);
7136
+ `At least one server must be specified in your OpenAPI file. e.g.:
7137
+ servers:
7138
+ - url: http://localhost:3000
7139
+ description: Local development server`
7140
+ );
7141
+ throw new Error();
7056
7142
  }
7057
- const operationHasKey = !!operation.cacheStrategy.key;
7058
- let valid = true;
7059
- const messages = [];
7060
- operation.responses.forEach((response) => {
7061
- response.payloads.forEach((payload) => {
7062
- var _a, _b;
7063
- if (((_a = payload.data.extensions) == null ? void 0 : _a.type) === "identifiable") {
7064
- const typeName = this.types.nameOf(payload.data) || ANONYMOUS_TYPE_NAME;
7065
- if (!operationHasKey) {
7066
- valid = false;
7067
- messages.push(
7068
- getFormattedMessage(
7069
- operation,
7070
- `Operation ${operation.operationId ? `${operation.operationId} ` : ``}is missing a key to match against its ${typeName} response type`
7071
- )
7072
- );
7073
- } else if (!((_b = payload.data.extensions.key) == null ? void 0 : _b.fields)) {
7074
- valid = false;
7075
- messages.push(
7076
- getFormattedMessage(
7077
- operation,
7078
- `Operation ${operation.operationId ? `${operation.operationId} ` : ``}has a key but its ${typeName} response type doesn't have one to match against`
7079
- )
7080
- );
7081
- } else if (!deepEquals(
7082
- Object.keys(operation.cacheStrategy.key || {}),
7083
- Object.keys(payload.data.extensions.key.fields)
7084
- )) {
7085
- valid = false;
7086
- messages.push(
7087
- getFormattedMessage(
7088
- operation,
7089
- `Operation ${operation.operationId ? `${operation.operationId} ` : ``}and its ${typeName} response type have mismatched keys`
7090
- )
7091
- );
7092
- }
7093
- }
7143
+ this._servers = this.webApi.servers.map((s) => {
7144
+ const uriParameters = {};
7145
+ s.variables.forEach((param) => {
7146
+ uriParameters[`${param.name.value()}`] = {
7147
+ required: param.required.value(),
7148
+ type: amfTypeFactory(
7149
+ this,
7150
+ param.schema,
7151
+ this.types,
7152
+ this.services.logger,
7153
+ this.fileParserlogger
7154
+ ),
7155
+ explode: param.explode.value()
7156
+ };
7094
7157
  });
7158
+ return {
7159
+ url: s.url.value(),
7160
+ uriParameters
7161
+ };
7095
7162
  });
7096
- return valid ? ok(messages) : err(messages);
7097
7163
  }
7098
- }
7099
- class BodyDataValidator {
7100
- constructor(target, keys, keySourcesValidatorSupplier) {
7101
- this.target = target;
7102
- this.keys = keys;
7103
- this.keySourcesValidatorSupplier = keySourcesValidatorSupplier;
7164
+ buildTypes() {
7165
+ this.services.logger.debug("AMFAPI - Building the type registry");
7166
+ const typeRegistry = this.typeRegistry = new BaseTypeRegistry();
7167
+ this.document.declares.filter(isTypeShape).forEach((shape) => {
7168
+ const name = shape.name.value();
7169
+ this.services.logger.debug(`AMFAPI - Building AMF Type for ${name}`);
7170
+ const amfType = amfTypeFactory(
7171
+ this,
7172
+ shape,
7173
+ typeRegistry,
7174
+ this.services.logger,
7175
+ this.fileParserlogger
7176
+ );
7177
+ this.services.logger.debug(`AMFAPI - Setting ${name} in type registry`);
7178
+ typeRegistry.set(shape.name.value(), amfType);
7179
+ });
7180
+ typeRegistry.forEach((type, name) => {
7181
+ this.services.logger.debug(`AMFAPI - Resolving type ${name}`);
7182
+ type.resolve();
7183
+ });
7104
7184
  }
7105
- validate(operation) {
7106
- if (this.keys.length === 0) {
7107
- return ok([]);
7108
- }
7109
- const jsonPayload = this.target.payloads.find((p) => p.mediaType === "application/json");
7110
- if (jsonPayload === void 0) {
7111
- return err([
7112
- getFormattedMessage(
7113
- operation,
7114
- `Use of 'body' keys requires a json payload: ${operation.method} ${operation.endpoint.path} has none.`
7115
- )
7116
- ]);
7185
+ get webApi() {
7186
+ return this.document.encodes;
7187
+ }
7188
+ get endpoints() {
7189
+ this.build();
7190
+ return this._endpoints;
7191
+ }
7192
+ get defaults() {
7193
+ const operationCacheStrategy2 = this.parsedDefaultOperationCacheStrategyType ?? { type: "none" };
7194
+ const typeCacheControl = this.parsedDefaultTypeCacheControl;
7195
+ const services = resolveDefaultServiceOverrides(this.serviceOverrides);
7196
+ return {
7197
+ operationCacheStrategy: operationCacheStrategy2,
7198
+ typeCacheControl,
7199
+ services
7200
+ };
7201
+ }
7202
+ get servers() {
7203
+ this.build();
7204
+ return this._servers;
7205
+ }
7206
+ get types() {
7207
+ this.build();
7208
+ return this.typeRegistry;
7209
+ }
7210
+ get namespace() {
7211
+ if (this.parsedNamespace === void 0) {
7212
+ return this.defaultedNamespace;
7117
7213
  }
7118
- const result = this.keySourcesValidatorSupplier(this.keys).validate(jsonPayload.data);
7119
- if (!result.isOk()) {
7120
- const message = getFormattedMessage(
7121
- operation,
7122
- `Invalid body key(s) specified for ${operation.operationId || `${operation.method} ${operation.endpoint.path}`}`
7214
+ return this.parsedNamespace;
7215
+ }
7216
+ checkAnnotationsVersion() {
7217
+ const version = getAmfAnnotationVersion(this.webApi);
7218
+ if (!satisfies(V1_VERSION, version)) {
7219
+ throw new Error(
7220
+ `Version ${version} requested cannot be satisfied by version ${V1_VERSION} of the AMF API.`
7123
7221
  );
7124
- message.subValidationMessages = result.error;
7125
- return err([message]);
7126
7222
  }
7127
- return ok([]);
7128
7223
  }
7129
- }
7130
- function buildOperationValidator(api) {
7131
- const bodyDateValidatorSupplier = (target, sources) => {
7132
- return new BodyDataValidator(target, sources, (keys) => {
7133
- return new KeySourcesValidator(api.types, keys);
7134
- });
7135
- };
7136
- return compose([
7137
- new InvalidationValidator(api.types, bodyDateValidatorSupplier),
7138
- new KeySourceValidator(bodyDateValidatorSupplier),
7139
- new Response200Validator(),
7140
- new NoNormalizedTypesValidator(api.types),
7141
- new KeyMatchValidator(api.types)
7142
- ]);
7143
- }
7144
- function buildEndpointValidator(api) {
7145
- const operationValidator = buildOperationValidator(api);
7146
- return {
7147
- validate(subject) {
7148
- return combineValidationResults(
7149
- subject.operations.map((operation) => operationValidator.validate(operation))
7224
+ setRootLevelAnnotations() {
7225
+ var _a, _b, _c, _d;
7226
+ const extensionsRaw = extractExtensions(this.webApi.customDomainProperties);
7227
+ const oneStoreExtensionsResult = baseExtensionsSchema.safeParse(extensionsRaw);
7228
+ if (!oneStoreExtensionsResult.success) {
7229
+ const message = formatZodError(oneStoreExtensionsResult.error);
7230
+ throw new Error(message);
7231
+ }
7232
+ const onestore = oneStoreExtensionsResult.data.onestore;
7233
+ this.parsedDefaultOperationCacheStrategyType = (_b = (_a = onestore == null ? void 0 : onestore.defaults) == null ? void 0 : _a.operations) == null ? void 0 : _b["cache-strategy"];
7234
+ this.parsedDefaultTypeCacheControl = (_d = (_c = onestore == null ? void 0 : onestore.defaults) == null ? void 0 : _c.schemas) == null ? void 0 : _d["cache-control"];
7235
+ this.parsedNamespace = onestore == null ? void 0 : onestore.namespace;
7236
+ if (this.parsedNamespace === void 0) {
7237
+ this.services.logger.warn(
7238
+ `AMFAPI - namespace is missing, will be defaulted "${this.defaultedNamespace}".`
7150
7239
  );
7151
7240
  }
7152
- };
7153
- }
7154
- class BindingsValidation {
7155
- constructor() {
7156
- }
7157
- validate(api) {
7158
- const messages = [];
7159
- const endpoints = api.endpoints;
7160
- const identToPathAndOperation = /* @__PURE__ */ new Map();
7161
- for (const endpoint of endpoints) {
7162
- const { path: path2, operations } = endpoint;
7163
- for (const operation of operations) {
7164
- const operationId = operation.operationId || `${operation.method} ${operation.endpoint.path}`;
7165
- const { bindings } = operation;
7166
- for (const binding of bindings) {
7167
- const { identifier } = binding;
7168
- if (identToPathAndOperation.has(identifier)) {
7169
- const existing = identToPathAndOperation.get(identifier);
7170
- messages.push({
7171
- severity: ValidationSeverity.Error,
7172
- message: `Binding identifier '${identifier}' in operation '${operationId}' is already used in path '${existing.path}' and operation '${existing.operationId}'`,
7173
- subject: operation,
7174
- validationType: ValidationType.Operation
7175
- });
7176
- } else {
7177
- identToPathAndOperation.set(identifier, { path: path2, operationId });
7178
- }
7179
- }
7180
- }
7241
+ if (onestore == null ? void 0 : onestore.services) {
7242
+ this.serviceOverrides = validateAndNormalizeCatalog(onestore.services);
7181
7243
  }
7182
- return messages.length > 0 ? err(messages) : ok(messages);
7183
- }
7184
- }
7185
- class ApiValidator {
7186
- constructor(apiValidators, typeValidator, endpointValidator) {
7187
- this.apiValidators = apiValidators;
7188
- this.typeValidator = typeValidator;
7189
- this.endpointValidator = endpointValidator;
7190
- }
7191
- validate(subject) {
7192
- const results = [
7193
- this.validateCollection(subject.types.values(), this.typeValidator),
7194
- this.validateCollection(subject.endpoints, this.endpointValidator),
7195
- ...this.apiValidators.map((v) => v.validate(subject))
7196
- ];
7197
- return combineValidationResults(results);
7198
7244
  }
7199
- validateCollection(items, validator) {
7200
- const results = [];
7201
- for (const item of items) {
7202
- results.push(validator.validate(item));
7245
+ /**
7246
+ * Validates all endpoints and types. A validation error will be thrown if any are invalid.
7247
+ *
7248
+ * @protected
7249
+ */
7250
+ validate() {
7251
+ if (!isValidAmfAPI(this, this.fileParserlogger)) {
7252
+ throw new Error("API OneStore configuration failed validation");
7203
7253
  }
7204
- return combineValidationResults(results);
7205
7254
  }
7206
7255
  }
7207
- function buildApiValidatorFor(api) {
7208
- const typeValidation = buildTypeValidator(api.types);
7209
- const apiValidators = [new BindingsValidation()];
7210
- const endpointValidation = buildEndpointValidator(api);
7211
- return new ApiValidator(apiValidators, typeValidation, endpointValidation);
7212
- }
7213
- function validateUniqueBindingIdentfiers(operations) {
7214
- const operationsBindings = operations.map(({ bindings }) => bindings.map(({ identifier }) => identifier)).flat();
7215
- const uniqueBindings = new Set(operationsBindings);
7216
- return operationsBindings.length === uniqueBindings.size;
7217
- }
7218
7256
  async function parseAmfDocument(source, logger) {
7219
7257
  const parseResult = await amf.APIConfiguration.API().baseUnitClient().parse(source.toString());
7220
7258
  parseResult.results.forEach((result) => logResult(result, logger));
@@ -7271,13 +7309,6 @@ class AMFAPIService {
7271
7309
  function amfAPIService(services) {
7272
7310
  return new AMFAPIService(services);
7273
7311
  }
7274
- function asAPIService(api) {
7275
- const p = Promise.resolve(api);
7276
- return {
7277
- build: () => p,
7278
- api
7279
- };
7280
- }
7281
7312
  export {
7282
7313
  AMFAnyTypeImpl,
7283
7314
  AMFArrayTypeImpl,
@@ -7292,6 +7323,7 @@ export {
7292
7323
  AMFObjectTypeImpl,
7293
7324
  AMFOneOfTypeImpl,
7294
7325
  AMFStringTypeImpl,
7326
+ ANONYMOUS_TYPE_NAME,
7295
7327
  BaseTypeRegistry,
7296
7328
  BindingTypesEnum,
7297
7329
  V1_VERSION,
@@ -7300,7 +7332,6 @@ export {
7300
7332
  asAPIService,
7301
7333
  buildApiValidatorFor,
7302
7334
  buildTypeValidator,
7303
- cacheControl,
7304
7335
  canonicalizeType,
7305
7336
  componentsOnestoreServicesSchema,
7306
7337
  getAmfAnnotationVersion,
@@ -7327,7 +7358,6 @@ export {
7327
7358
  isScalar$1 as isScalar,
7328
7359
  isStringType,
7329
7360
  isTimeType,
7330
- operationCacheStrategy,
7331
7361
  operationOnestoreServicesSchema,
7332
7362
  operationServiceInlineSchema,
7333
7363
  operationServiceRefSchema,
@@ -7336,10 +7366,8 @@ export {
7336
7366
  parseUrl,
7337
7367
  resolveDefaultServiceOverrides,
7338
7368
  resolveOperationServices,
7339
- resourceCacheControl,
7340
7369
  serviceVariantDescriptorSchema,
7341
7370
  servicesCatalogSchema,
7342
- typeExtensions,
7343
7371
  typesEqual,
7344
7372
  validateAndNormalizeCatalog
7345
7373
  };