@ankhorage/data-sources 1.0.1 → 2.0.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 (120) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +6 -41
  3. package/dist/ankh.provider.js +1 -1
  4. package/dist/ankh.provider.js.map +1 -1
  5. package/dist/discovery/http.d.ts +10 -0
  6. package/dist/discovery/http.d.ts.map +1 -0
  7. package/dist/discovery/http.js +35 -0
  8. package/dist/discovery/http.js.map +1 -0
  9. package/dist/discovery/index.d.ts +9 -9
  10. package/dist/discovery/index.d.ts.map +1 -1
  11. package/dist/discovery/index.js +27 -55
  12. package/dist/discovery/index.js.map +1 -1
  13. package/dist/graphql/index.d.ts +8 -76
  14. package/dist/graphql/index.d.ts.map +1 -1
  15. package/dist/graphql/index.js +17 -197
  16. package/dist/graphql/index.js.map +1 -1
  17. package/dist/graphql/introspection.d.ts +5 -0
  18. package/dist/graphql/introspection.d.ts.map +1 -0
  19. package/dist/graphql/introspection.js +136 -0
  20. package/dist/graphql/introspection.js.map +1 -0
  21. package/dist/graphql/operation.d.ts +5 -0
  22. package/dist/graphql/operation.d.ts.map +1 -0
  23. package/dist/graphql/operation.js +39 -0
  24. package/dist/graphql/operation.js.map +1 -0
  25. package/dist/graphql/types.d.ts +71 -0
  26. package/dist/graphql/types.d.ts.map +1 -0
  27. package/dist/graphql/types.js +2 -0
  28. package/dist/graphql/types.js.map +1 -0
  29. package/dist/index.d.ts +1 -17
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +1 -34
  32. package/dist/index.js.map +1 -1
  33. package/dist/openapi/endpoints.d.ts +5 -0
  34. package/dist/openapi/endpoints.d.ts.map +1 -0
  35. package/dist/openapi/endpoints.js +77 -0
  36. package/dist/openapi/endpoints.js.map +1 -0
  37. package/dist/openapi/index.d.ts +7 -87
  38. package/dist/openapi/index.d.ts.map +1 -1
  39. package/dist/openapi/index.js +8 -267
  40. package/dist/openapi/index.js.map +1 -1
  41. package/dist/openapi/operation.d.ts +5 -0
  42. package/dist/openapi/operation.d.ts.map +1 -0
  43. package/dist/openapi/operation.js +141 -0
  44. package/dist/openapi/operation.js.map +1 -0
  45. package/dist/openapi/schema.d.ts +5 -0
  46. package/dist/openapi/schema.d.ts.map +1 -0
  47. package/dist/openapi/schema.js +84 -0
  48. package/dist/openapi/schema.js.map +1 -0
  49. package/dist/openapi/types.d.ts +82 -0
  50. package/dist/openapi/types.d.ts.map +1 -0
  51. package/dist/openapi/types.js +2 -0
  52. package/dist/openapi/types.js.map +1 -0
  53. package/dist/packageInfo.d.ts +18 -0
  54. package/dist/packageInfo.d.ts.map +1 -0
  55. package/dist/packageInfo.js +30 -0
  56. package/dist/packageInfo.js.map +1 -0
  57. package/dist/rest/index.d.ts +5 -5
  58. package/dist/rest/index.d.ts.map +1 -1
  59. package/dist/rest/index.js +49 -48
  60. package/dist/rest/index.js.map +1 -1
  61. package/dist/test-runner/index.d.ts +2 -57
  62. package/dist/test-runner/index.d.ts.map +1 -1
  63. package/dist/test-runner/index.js +58 -160
  64. package/dist/test-runner/index.js.map +1 -1
  65. package/dist/test-runner/response.d.ts +3 -0
  66. package/dist/test-runner/response.d.ts.map +1 -0
  67. package/dist/test-runner/response.js +29 -0
  68. package/dist/test-runner/response.js.map +1 -0
  69. package/dist/test-runner/result.d.ts +6 -0
  70. package/dist/test-runner/result.d.ts.map +1 -0
  71. package/dist/test-runner/result.js +17 -0
  72. package/dist/test-runner/result.js.map +1 -0
  73. package/dist/test-runner/serialization.d.ts +12 -0
  74. package/dist/test-runner/serialization.d.ts.map +1 -0
  75. package/dist/test-runner/serialization.js +99 -0
  76. package/dist/test-runner/serialization.js.map +1 -0
  77. package/dist/test-runner/types.d.ts +58 -0
  78. package/dist/test-runner/types.d.ts.map +1 -0
  79. package/dist/test-runner/types.js +2 -0
  80. package/dist/test-runner/types.js.map +1 -0
  81. package/package.json +5 -5
  82. package/src/ankh.provider.ts +1 -1
  83. package/src/api-phase1.contract.test.ts +24 -0
  84. package/src/discovery/http.ts +38 -0
  85. package/src/discovery/index.test.ts +76 -75
  86. package/src/discovery/index.ts +49 -72
  87. package/src/graphql/index.test.ts +10 -11
  88. package/src/graphql/index.ts +35 -315
  89. package/src/graphql/introspection.ts +163 -0
  90. package/src/graphql/operation.ts +60 -0
  91. package/src/graphql/types.ts +79 -0
  92. package/src/index.test.ts +21 -13
  93. package/src/index.ts +1 -54
  94. package/src/openapi/endpoints.ts +124 -0
  95. package/src/openapi/index.test.ts +47 -47
  96. package/src/openapi/index.ts +12 -467
  97. package/src/openapi/operation.ts +231 -0
  98. package/src/openapi/schema.ts +127 -0
  99. package/src/openapi/types.ts +93 -0
  100. package/src/packageInfo.ts +50 -0
  101. package/src/rest/index.test.ts +17 -14
  102. package/src/rest/index.ts +67 -61
  103. package/src/test-runner/index.test.ts +153 -120
  104. package/src/test-runner/index.ts +97 -299
  105. package/src/test-runner/response.ts +32 -0
  106. package/src/test-runner/result.ts +35 -0
  107. package/src/test-runner/serialization.ts +151 -0
  108. package/src/test-runner/types.ts +81 -0
  109. package/dist/generated-api/index.d.ts +0 -10
  110. package/dist/generated-api/index.d.ts.map +0 -1
  111. package/dist/generated-api/index.js +0 -274
  112. package/dist/generated-api/index.js.map +0 -1
  113. package/dist/generated-api/validateGeneratedApiCollection.d.ts +0 -3
  114. package/dist/generated-api/validateGeneratedApiCollection.d.ts.map +0 -1
  115. package/dist/generated-api/validateGeneratedApiCollection.js +0 -35
  116. package/dist/generated-api/validateGeneratedApiCollection.js.map +0 -1
  117. package/src/generated-api/index.test.ts +0 -173
  118. package/src/generated-api/index.ts +0 -414
  119. package/src/generated-api/validateGeneratedApiCollection.test.ts +0 -91
  120. package/src/generated-api/validateGeneratedApiCollection.ts +0 -76
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/graphql/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,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AAQ,CAAC,QAAQ,CAAC,EAAE,iBAAiB,CAAC;CACvC;AAED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,UAAU,CAAC,EAAE,aAAa,CAAC;IACpC,QAAQ,CAAC,aAAa,CAAC,EAAE,0BAA0B,CAAC;IACpD,QAAQ,CAAC,oBAAoB,CAAC,EAAE,OAAO,CAAC;IACxC,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,UAAU,CAAC,EAAE,SAAS,0BAA0B,EAAE,CAAC;IAC5D,QAAQ,CAAC,QAAQ,CAAC,EAAE,iBAAiB,CAAC;CACvC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/graphql/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n CredentialRef,\n DataContractValue,\n DataSchema,\n OperationId,\n} from '@ankhorage/contracts/data';\n\nexport type GraphQlOperationKind = 'mutation' | 'query' | 'subscription';\n\nexport interface GraphQlIntrospectionTypeRef {\n readonly kind: string;\n readonly name?: string | null;\n readonly ofType?: GraphQlIntrospectionTypeRef | null;\n}\n\nexport interface GraphQlIntrospectionInputValue {\n readonly name: string;\n readonly description?: string | null;\n readonly type: GraphQlIntrospectionTypeRef;\n readonly defaultValue?: string | null;\n}\n\nexport interface GraphQlIntrospectionField {\n readonly name: string;\n readonly description?: string | null;\n readonly args?: readonly GraphQlIntrospectionInputValue[] | null;\n readonly type: GraphQlIntrospectionTypeRef;\n}\n\nexport interface GraphQlIntrospectionEnumValue {\n readonly name: string;\n readonly description?: string | null;\n}\n\nexport interface GraphQlIntrospectionType {\n readonly kind: string;\n readonly name?: string | null;\n readonly description?: string | null;\n readonly fields?: readonly GraphQlIntrospectionField[] | null;\n readonly inputFields?: readonly GraphQlIntrospectionInputValue[] | null;\n readonly enumValues?: readonly GraphQlIntrospectionEnumValue[] | null;\n readonly possibleTypes?: readonly GraphQlIntrospectionTypeRef[] | null;\n}\n\nexport interface GraphQlIntrospectionSchema {\n readonly queryType?: { readonly name?: string | null } | null;\n readonly mutationType?: { readonly name?: string | null } | null;\n readonly subscriptionType?: { readonly name?: string | null } | null;\n readonly types?: readonly GraphQlIntrospectionType[] | null;\n}\n\nexport interface GraphQlIntrospectionResult {\n readonly __schema?: GraphQlIntrospectionSchema;\n}\n\nexport interface GraphQlOperationDefinition {\n readonly id: OperationId;\n readonly kind: GraphQlOperationKind;\n readonly name?: string;\n readonly description?: string;\n readonly document?: string;\n readonly variables?: DataSchema;\n readonly response?: DataSchema;\n readonly selectionPath?: string;\n readonly metadata?: DataContractValue;\n}\n\nexport interface GraphQlApiDefinition {\n readonly id: string;\n readonly endpointUrl: string;\n readonly name?: string;\n readonly description?: string;\n readonly credential?: CredentialRef;\n readonly introspection?: GraphQlIntrospectionResult;\n readonly introspectionEnabled?: boolean;\n readonly schemaVersion?: string;\n readonly operations?: readonly GraphQlOperationDefinition[];\n readonly metadata?: DataContractValue;\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -1,23 +1,7 @@
1
- import type { ApiOrigin, ApiProtocol, DataSourceConfig, DataSourceKind } from '@ankhorage/contracts/data';
2
1
  export * from './discovery';
3
- export * from './generated-api';
4
2
  export * from './graphql';
5
3
  export * from './openapi';
4
+ export * from './packageInfo';
6
5
  export * from './rest';
7
6
  export * from './test-runner';
8
- export declare const DATA_SOURCES_PACKAGE_NAME: "@ankhorage/data-sources";
9
- export declare const SUPPORTED_DATA_SOURCE_KINDS: readonly ["api", "database"];
10
- export declare const SUPPORTED_API_ORIGINS: readonly ["external", "generated"];
11
- export declare const SUPPORTED_API_PROTOCOLS: readonly ["graphql", "rest"];
12
- export interface DataSourcesPackageInfo {
13
- readonly packageName: typeof DATA_SOURCES_PACKAGE_NAME;
14
- readonly supportedKinds: typeof SUPPORTED_DATA_SOURCE_KINDS;
15
- readonly supportedApiOrigins: typeof SUPPORTED_API_ORIGINS;
16
- readonly supportedApiProtocols: typeof SUPPORTED_API_PROTOCOLS;
17
- }
18
- export declare function getDataSourcesPackageInfo(): DataSourcesPackageInfo;
19
- export declare function isSupportedDataSourceKind(kind: string): kind is DataSourceKind;
20
- export declare function isSupportedApiOrigin(origin: string): origin is ApiOrigin;
21
- export declare function isSupportedApiProtocol(protocol: string): protocol is ApiProtocol;
22
- export declare function getDataSourceKind(source: DataSourceConfig): DataSourceKind;
23
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EACT,WAAW,EACX,gBAAgB,EAChB,cAAc,EACf,MAAM,2BAA2B,CAAC;AAEnC,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,eAAe,CAAC;AAE9B,eAAO,MAAM,yBAAyB,EAAG,yBAAkC,CAAC;AAC5E,eAAO,MAAM,2BAA2B,8BAGM,CAAC;AAC/C,eAAO,MAAM,qBAAqB,oCAGO,CAAC;AAC1C,eAAO,MAAM,uBAAuB,8BAGO,CAAC;AAE5C,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,WAAW,EAAE,OAAO,yBAAyB,CAAC;IACvD,QAAQ,CAAC,cAAc,EAAE,OAAO,2BAA2B,CAAC;IAC5D,QAAQ,CAAC,mBAAmB,EAAE,OAAO,qBAAqB,CAAC;IAC3D,QAAQ,CAAC,qBAAqB,EAAE,OAAO,uBAAuB,CAAC;CAChE;AAED,wBAAgB,yBAAyB,IAAI,sBAAsB,CAOlE;AAED,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,cAAc,CAE9E;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,IAAI,SAAS,CAExE;AAED,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,QAAQ,IAAI,WAAW,CAEhF;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,gBAAgB,GAAG,cAAc,CAE1E"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,QAAQ,CAAC;AACvB,cAAc,eAAe,CAAC"}
package/dist/index.js CHANGED
@@ -1,40 +1,7 @@
1
1
  export * from './discovery';
2
- export * from './generated-api';
3
2
  export * from './graphql';
4
3
  export * from './openapi';
4
+ export * from './packageInfo';
5
5
  export * from './rest';
6
6
  export * from './test-runner';
7
- export const DATA_SOURCES_PACKAGE_NAME = '@ankhorage/data-sources';
8
- export const SUPPORTED_DATA_SOURCE_KINDS = [
9
- 'api',
10
- 'database',
11
- ];
12
- export const SUPPORTED_API_ORIGINS = [
13
- 'external',
14
- 'generated',
15
- ];
16
- export const SUPPORTED_API_PROTOCOLS = [
17
- 'graphql',
18
- 'rest',
19
- ];
20
- export function getDataSourcesPackageInfo() {
21
- return {
22
- packageName: DATA_SOURCES_PACKAGE_NAME,
23
- supportedKinds: SUPPORTED_DATA_SOURCE_KINDS,
24
- supportedApiOrigins: SUPPORTED_API_ORIGINS,
25
- supportedApiProtocols: SUPPORTED_API_PROTOCOLS,
26
- };
27
- }
28
- export function isSupportedDataSourceKind(kind) {
29
- return SUPPORTED_DATA_SOURCE_KINDS.some((supported) => supported === kind);
30
- }
31
- export function isSupportedApiOrigin(origin) {
32
- return SUPPORTED_API_ORIGINS.some((supported) => supported === origin);
33
- }
34
- export function isSupportedApiProtocol(protocol) {
35
- return SUPPORTED_API_PROTOCOLS.some((supported) => supported === protocol);
36
- }
37
- export function getDataSourceKind(source) {
38
- return source.kind;
39
- }
40
7
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,eAAe,CAAC;AAE9B,MAAM,CAAC,MAAM,yBAAyB,GAAG,yBAAkC,CAAC;AAC5E,MAAM,CAAC,MAAM,2BAA2B,GAAG;IACzC,KAAK;IACL,UAAU;CACkC,CAAC;AAC/C,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,UAAU;IACV,WAAW;CAC4B,CAAC;AAC1C,MAAM,CAAC,MAAM,uBAAuB,GAAG;IACrC,SAAS;IACT,MAAM;CACmC,CAAC;AAS5C,MAAM,UAAU,yBAAyB;IACvC,OAAO;QACL,WAAW,EAAE,yBAAyB;QACtC,cAAc,EAAE,2BAA2B;QAC3C,mBAAmB,EAAE,qBAAqB;QAC1C,qBAAqB,EAAE,uBAAuB;KAC/C,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,yBAAyB,CAAC,IAAY;IACpD,OAAO,2BAA2B,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,KAAK,IAAI,CAAC,CAAC;AAC7E,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,MAAc;IACjD,OAAO,qBAAqB,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,KAAK,MAAM,CAAC,CAAC;AACzE,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,QAAgB;IACrD,OAAO,uBAAuB,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,KAAK,QAAQ,CAAC,CAAC;AAC7E,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,MAAwB;IACxD,OAAO,MAAM,CAAC,IAAI,CAAC;AACrB,CAAC","sourcesContent":["import type {\n ApiOrigin,\n ApiProtocol,\n DataSourceConfig,\n DataSourceKind,\n} from '@ankhorage/contracts/data';\n\nexport * from './discovery';\nexport * from './generated-api';\nexport * from './graphql';\nexport * from './openapi';\nexport * from './rest';\nexport * from './test-runner';\n\nexport const DATA_SOURCES_PACKAGE_NAME = '@ankhorage/data-sources' as const;\nexport const SUPPORTED_DATA_SOURCE_KINDS = [\n 'api',\n 'database',\n] as const satisfies readonly DataSourceKind[];\nexport const SUPPORTED_API_ORIGINS = [\n 'external',\n 'generated',\n] as const satisfies readonly ApiOrigin[];\nexport const SUPPORTED_API_PROTOCOLS = [\n 'graphql',\n 'rest',\n] as const satisfies readonly ApiProtocol[];\n\nexport interface DataSourcesPackageInfo {\n readonly packageName: typeof DATA_SOURCES_PACKAGE_NAME;\n readonly supportedKinds: typeof SUPPORTED_DATA_SOURCE_KINDS;\n readonly supportedApiOrigins: typeof SUPPORTED_API_ORIGINS;\n readonly supportedApiProtocols: typeof SUPPORTED_API_PROTOCOLS;\n}\n\nexport function getDataSourcesPackageInfo(): DataSourcesPackageInfo {\n return {\n packageName: DATA_SOURCES_PACKAGE_NAME,\n supportedKinds: SUPPORTED_DATA_SOURCE_KINDS,\n supportedApiOrigins: SUPPORTED_API_ORIGINS,\n supportedApiProtocols: SUPPORTED_API_PROTOCOLS,\n };\n}\n\nexport function isSupportedDataSourceKind(kind: string): kind is DataSourceKind {\n return SUPPORTED_DATA_SOURCE_KINDS.some((supported) => supported === kind);\n}\n\nexport function isSupportedApiOrigin(origin: string): origin is ApiOrigin {\n return SUPPORTED_API_ORIGINS.some((supported) => supported === origin);\n}\n\nexport function isSupportedApiProtocol(protocol: string): protocol is ApiProtocol {\n return SUPPORTED_API_PROTOCOLS.some((supported) => supported === protocol);\n}\n\nexport function getDataSourceKind(source: DataSourceConfig): DataSourceKind {\n return source.kind;\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,QAAQ,CAAC;AACvB,cAAc,eAAe,CAAC","sourcesContent":["export * from './discovery';\nexport * from './graphql';\nexport * from './openapi';\nexport * from './packageInfo';\nexport * from './rest';\nexport * from './test-runner';\n"]}
@@ -0,0 +1,5 @@
1
+ import type { DataEndpointConfig, DataSourceDiagnostic, EndpointId } from '@ankhorage/contracts/data';
2
+ import type { OpenApiImportInput } from './types';
3
+ export declare function normalizeOpenApiEndpointId(path: string): EndpointId;
4
+ export declare function normalizeOpenApiEndpoints(input: OpenApiImportInput, diagnostics: DataSourceDiagnostic[]): Record<EndpointId, DataEndpointConfig>;
5
+ //# sourceMappingURL=endpoints.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"endpoints.d.ts","sourceRoot":"","sources":["../../src/openapi/endpoints.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,oBAAoB,EACpB,UAAU,EAEX,MAAM,2BAA2B,CAAC;AAGnC,OAAO,KAAK,EAEV,kBAAkB,EAGnB,MAAM,SAAS,CAAC;AAYjB,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CAOnE;AAED,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,kBAAkB,EACzB,WAAW,EAAE,oBAAoB,EAAE,GAClC,MAAM,CAAC,UAAU,EAAE,kBAAkB,CAAC,CAuBxC"}
@@ -0,0 +1,77 @@
1
+ import { normalizeOpenApiOperation } from './operation';
2
+ const OPENAPI_HTTP_METHODS = [
3
+ 'delete',
4
+ 'get',
5
+ 'head',
6
+ 'options',
7
+ 'patch',
8
+ 'post',
9
+ 'put',
10
+ ];
11
+ export function normalizeOpenApiEndpointId(path) {
12
+ const normalized = path
13
+ .replace(/\{([^}]+)\}/g, '$1')
14
+ .replace(/[^A-Za-z0-9]+/g, '-')
15
+ .replace(/^-+|-+$/g, '')
16
+ .toLowerCase();
17
+ return normalized.length > 0 ? normalized : 'root';
18
+ }
19
+ export function normalizeOpenApiEndpoints(input, diagnostics) {
20
+ const { paths } = input.document;
21
+ if (paths === undefined || Object.keys(paths).length === 0) {
22
+ diagnostics.push({
23
+ code: 'invalid-config',
24
+ apiId: input.id,
25
+ message: 'OpenAPI document must define at least one path.',
26
+ path: 'paths',
27
+ severity: 'error',
28
+ });
29
+ return {};
30
+ }
31
+ const operationIds = new Set();
32
+ return Object.fromEntries(Object.entries(paths).map(([path, pathItem]) => {
33
+ const endpointId = normalizeOpenApiEndpointId(path);
34
+ return [
35
+ endpointId,
36
+ normalizeOpenApiEndpoint(input, path, pathItem, endpointId, operationIds, diagnostics),
37
+ ];
38
+ }));
39
+ }
40
+ function normalizeOpenApiEndpoint(input, path, pathItem, endpointId, operationIds, diagnostics) {
41
+ const operations = Object.fromEntries(getOpenApiOperations(pathItem).map(([method, operation]) => {
42
+ const normalized = normalizeOpenApiOperation(input, endpointId, path, method, operation, pathItem, operationIds, diagnostics);
43
+ return [normalized.id, normalized];
44
+ }));
45
+ return {
46
+ id: endpointId,
47
+ kind: 'http',
48
+ path,
49
+ credential: input.credential,
50
+ operations,
51
+ };
52
+ }
53
+ function getOpenApiOperations(pathItem) {
54
+ return OPENAPI_HTTP_METHODS.flatMap((method) => {
55
+ const operation = getOpenApiOperation(pathItem, method);
56
+ return operation === undefined ? [] : [[method, operation]];
57
+ });
58
+ }
59
+ function getOpenApiOperation(pathItem, method) {
60
+ switch (method) {
61
+ case 'delete':
62
+ return pathItem.delete;
63
+ case 'get':
64
+ return pathItem.get;
65
+ case 'head':
66
+ return pathItem.head;
67
+ case 'options':
68
+ return pathItem.options;
69
+ case 'patch':
70
+ return pathItem.patch;
71
+ case 'post':
72
+ return pathItem.post;
73
+ case 'put':
74
+ return pathItem.put;
75
+ }
76
+ }
77
+ //# sourceMappingURL=endpoints.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"endpoints.js","sourceRoot":"","sources":["../../src/openapi/endpoints.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAQxD,MAAM,oBAAoB,GAAG;IAC3B,QAAQ;IACR,KAAK;IACL,MAAM;IACN,SAAS;IACT,OAAO;IACP,MAAM;IACN,KAAK;CAC0C,CAAC;AAElD,MAAM,UAAU,0BAA0B,CAAC,IAAY;IACrD,MAAM,UAAU,GAAG,IAAI;SACpB,OAAO,CAAC,cAAc,EAAE,IAAI,CAAC;SAC7B,OAAO,CAAC,gBAAgB,EAAE,GAAG,CAAC;SAC9B,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC;SACvB,WAAW,EAAE,CAAC;IACjB,OAAO,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC;AACrD,CAAC;AAED,MAAM,UAAU,yBAAyB,CACvC,KAAyB,EACzB,WAAmC;IAEnC,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC,QAAQ,CAAC;IACjC,IAAI,KAAK,KAAK,SAAS,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC3D,WAAW,CAAC,IAAI,CAAC;YACf,IAAI,EAAE,gBAAgB;YACtB,KAAK,EAAE,KAAK,CAAC,EAAE;YACf,OAAO,EAAE,iDAAiD;YAC1D,IAAI,EAAE,OAAO;YACb,QAAQ,EAAE,OAAO;SAClB,CAAC,CAAC;QACH,OAAO,EAAE,CAAC;IACZ,CAAC;I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,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;IAC9D,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,mBAAmB,CAC1B,QAA+B,EAC/B,MAAyB;IAEzB,QAAQ,MAAM,EAAE,CAAC;QACf,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAC,MAAM,CAAC;QACzB,KAAK,KAAK;YACR,OAAO,QAAQ,CAAC,GAAG,CAAC;QACtB,KAAK,MAAM;YACT,OAAO,QAAQ,CAAC,IAAI,CAAC;QACvB,KAAK,SAAS;YACZ,OAAO,QAAQ,CAAC,OAAO,CAAC;QAC1B,KAAK,OAAO;YACV,OAAO,QAAQ,CAAC,KAAK,CAAC;QACxB,KAAK,MAAM;YACT,OAAO,QAAQ,CAAC,IAAI,CAAC;QACvB,KAAK,KAAK;YACR,OAAO,QAAQ,CAAC,GAAG,CAAC;IACxB,CAAC;AACH,CAAC","sourcesContent":["import type {\n DataEndpointConfig,\n DataSourceDiagnostic,\n EndpointId,\n OperationId,\n} from '@ankhorage/contracts/data';\n\nimport { normalizeOpenApiOperation } from './operation';\nimport type {\n OpenApiHttpMethod,\n OpenApiImportInput,\n OpenApiOperationObject,\n OpenApiPathItemObject,\n} from './types';\n\nconst OPENAPI_HTTP_METHODS = [\n 'delete',\n 'get',\n 'head',\n 'options',\n 'patch',\n 'post',\n 'put',\n] as const satisfies readonly OpenApiHttpMethod[];\n\nexport function normalizeOpenApiEndpointId(path: string): EndpointId {\n const normalized = path\n .replace(/\\{([^}]+)\\}/g, '$1')\n .replace(/[^A-Za-z0-9]+/g, '-')\n .replace(/^-+|-+$/g, '')\n .toLowerCase();\n return normalized.length > 0 ? normalized : 'root';\n}\n\nexport function normalizeOpenApiEndpoints(\n input: OpenApiImportInput,\n diagnostics: DataSourceDiagnostic[],\n): Record<EndpointId, DataEndpointConfig> {\n const { paths } = input.document;\n if (paths === undefined || Object.keys(paths).length === 0) {\n diagnostics.push({\n code: 'invalid-config',\n apiId: input.id,\n message: 'OpenAPI document must define at least one path.',\n path: 'paths',\n severity: 'error',\n });\n return {};\n }\n\n const operationIds = new Set<OperationId>();\n return Object.fromEntries(\n Object.entries(paths).map(([path, pathItem]) => {\n const endpointId = normalizeOpenApiEndpointId(path);\n return [\n endpointId,\n normalizeOpenApiEndpoint(input, path, pathItem, endpointId, operationIds, diagnostics),\n ];\n }),\n );\n}\n\nfunction normalizeOpenApiEndpoint(\n input: OpenApiImportInput,\n path: string,\n pathItem: OpenApiPathItemObject,\n endpointId: EndpointId,\n operationIds: Set<OperationId>,\n diagnostics: DataSourceDiagnostic[],\n): DataEndpointConfig {\n const operations = Object.fromEntries(\n getOpenApiOperations(pathItem).map(([method, operation]) => {\n const normalized = normalizeOpenApiOperation(\n input,\n endpointId,\n path,\n method,\n operation,\n pathItem,\n operationIds,\n diagnostics,\n );\n return [normalized.id, normalized];\n }),\n );\n return {\n id: endpointId,\n kind: 'http',\n path,\n credential: input.credential,\n operations,\n };\n}\n\nfunction getOpenApiOperations(\n pathItem: OpenApiPathItemObject,\n): readonly [OpenApiHttpMethod, OpenApiOperationObject][] {\n return OPENAPI_HTTP_METHODS.flatMap((method) => {\n const operation = getOpenApiOperation(pathItem, method);\n return operation === undefined ? [] : [[method, operation]];\n });\n}\n\nfunction getOpenApiOperation(\n pathItem: OpenApiPathItemObject,\n method: OpenApiHttpMethod,\n): OpenApiOperationObject | undefined {\n switch (method) {\n case 'delete':\n return pathItem.delete;\n case 'get':\n return pathItem.get;\n case 'head':\n return pathItem.head;\n case 'options':\n return pathItem.options;\n case 'patch':\n return pathItem.patch;\n case 'post':\n return pathItem.post;\n case 'put':\n return pathItem.put;\n }\n}\n"]}
@@ -1,89 +1,9 @@
1
- import type { CredentialRef, DataContractValue, DataSchema, DataSourceDiagnosticResult, EndpointId, ExternalRestApiDataSourceConfig, OperationId } from '@ankhorage/contracts/data';
2
- declare const OPENAPI_HTTP_METHODS: readonly ["delete", "get", "head", "options", "patch", "post", "put"];
3
- export type OpenApiHttpMethod = (typeof OPENAPI_HTTP_METHODS)[number];
4
- export interface OpenApiServerObject {
5
- readonly url: string;
6
- readonly description?: string;
7
- }
8
- export interface OpenApiSchemaObject {
9
- readonly $ref?: string;
10
- readonly type?: string | readonly string[];
11
- readonly title?: string;
12
- readonly description?: string;
13
- readonly enum?: readonly DataContractValue[];
14
- readonly const?: DataContractValue;
15
- readonly default?: DataContractValue;
16
- readonly format?: string;
17
- readonly nullable?: boolean;
18
- readonly required?: readonly string[];
19
- readonly properties?: Readonly<Record<string, OpenApiSchemaObject>>;
20
- readonly additionalProperties?: boolean | OpenApiSchemaObject;
21
- readonly items?: OpenApiSchemaObject;
22
- readonly allOf?: readonly OpenApiSchemaObject[];
23
- readonly anyOf?: readonly OpenApiSchemaObject[];
24
- readonly oneOf?: readonly OpenApiSchemaObject[];
25
- }
26
- export interface OpenApiMediaTypeObject {
27
- readonly schema?: OpenApiSchemaObject;
28
- }
29
- export interface OpenApiRequestBodyObject {
30
- readonly description?: string;
31
- readonly required?: boolean;
32
- readonly content?: Readonly<Record<string, OpenApiMediaTypeObject>>;
33
- }
34
- export interface OpenApiResponseObject {
35
- readonly description?: string;
36
- readonly content?: Readonly<Record<string, OpenApiMediaTypeObject>>;
37
- }
38
- export interface OpenApiParameterObject {
39
- readonly name: string;
40
- readonly in: string;
41
- readonly required?: boolean;
42
- readonly description?: string;
43
- readonly schema?: OpenApiSchemaObject;
44
- }
45
- export interface OpenApiOperationObject {
46
- readonly operationId?: string;
47
- readonly summary?: string;
48
- readonly description?: string;
49
- readonly deprecated?: boolean;
50
- readonly parameters?: readonly OpenApiParameterObject[];
51
- readonly requestBody?: OpenApiRequestBodyObject;
52
- readonly responses?: Readonly<Record<string, OpenApiResponseObject>>;
53
- }
54
- export type OpenApiPathItemObject = Partial<Record<OpenApiHttpMethod, OpenApiOperationObject>> & {
55
- readonly parameters?: readonly OpenApiParameterObject[];
56
- };
57
- export interface OpenApiComponentsObject {
58
- readonly schemas?: Readonly<Record<string, OpenApiSchemaObject>>;
59
- readonly securitySchemes?: Readonly<Record<string, DataContractValue>>;
60
- }
61
- export interface OpenApiDocumentObject {
62
- readonly openapi?: string;
63
- readonly info?: {
64
- readonly title?: string;
65
- readonly version?: string;
66
- readonly description?: string;
67
- };
68
- readonly servers?: readonly OpenApiServerObject[];
69
- readonly paths?: Readonly<Record<string, OpenApiPathItemObject>>;
70
- readonly components?: OpenApiComponentsObject;
71
- }
72
- export interface OpenApiImportInput {
73
- readonly id: string;
74
- readonly document: OpenApiDocumentObject;
75
- readonly baseUrl?: string;
76
- readonly credential?: CredentialRef;
77
- readonly documentId?: string;
78
- readonly documentUrl?: string;
79
- readonly name?: string;
80
- readonly description?: string;
81
- readonly metadata?: DataContractValue;
82
- }
83
- export type OpenApiImportResult = DataSourceDiagnosticResult<ExternalRestApiDataSourceConfig>;
1
+ import type { DataSourceDiagnosticResult, ExternalRestApiDefinition } from '@ankhorage/contracts/data';
2
+ import type { OpenApiImportInput } from './types';
3
+ export { normalizeOpenApiEndpointId } from './endpoints';
4
+ export { normalizeOpenApiOperationId } from './operation';
5
+ export { normalizeOpenApiSchema } from './schema';
6
+ export type * from './types';
7
+ export type OpenApiImportResult = DataSourceDiagnosticResult<ExternalRestApiDefinition>;
84
8
  export declare function importOpenApiDocument(input: OpenApiImportInput): OpenApiImportResult;
85
- export declare function normalizeOpenApiOperationId(method: OpenApiHttpMethod, path: string, operationId?: string): OperationId;
86
- export declare function normalizeOpenApiEndpointId(path: string): EndpointId;
87
- export declare function normalizeOpenApiSchema(schema: OpenApiSchemaObject): DataSchema;
88
- export {};
89
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/openapi/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,iBAAiB,EAQjB,UAAU,EAIV,0BAA0B,EAC1B,UAAU,EACV,+BAA+B,EAC/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AC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,QAAQ,CAAC,EAAE,iBAAiB,CAAC;CACvC;AAED,MAAM,MAAM,mBAAmB,GAAG,0BAA0B,CAAC,+BAA+B,CAAC,CAAC;AAE9F,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,kBAAkB,GAAG,mBAAmB,CAoCpF;AAED,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,iBAAiB,EACzB,IAAI,EAAE,MAAM,EACZ,WAAW,CAAC,EAAE,MAAM,GACnB,WAAW,CAQb;AAED,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CAOnE;AAED,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,mBAAmB,GAAG,UAAU,CAmB9E"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/openapi/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,0BAA0B,EAC1B,yBAAyB,EAC1B,MAAM,2BAA2B,CAAC;AAInC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAElD,OAAO,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAClD,mBAAmB,SAAS,CAAC;AAE7B,MAAM,MAAM,mBAAmB,GAAG,0BAA0B,CAAC,yBAAyB,CAAC,CAAC;AAExF,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,kBAAkB,GAAG,mBAAmB,CAmCpF"}
@@ -1,18 +1,13 @@
1
- const OPENAPI_HTTP_METHODS = ['delete', 'get', 'head', 'options', 'patch', 'post', 'put'];
2
- const DATA_SCHEMA_PRIMITIVES = [
3
- 'array',
4
- 'boolean',
5
- 'integer',
6
- 'null',
7
- 'number',
8
- 'object',
9
- 'string',
10
- ];
1
+ import { normalizeOpenApiEndpoints } from './endpoints';
2
+ import { normalizeOpenApiSchemas } from './schema';
3
+ export { normalizeOpenApiEndpointId } from './endpoints';
4
+ export { normalizeOpenApiOperationId } from './operation';
5
+ export { normalizeOpenApiSchema } from './schema';
11
6
  export function importOpenApiDocument(input) {
12
7
  const diagnostics = [];
13
8
  const baseUrl = resolveOpenApiBaseUrl(input, diagnostics);
14
9
  const schemas = normalizeOpenApiSchemas(input.document.components?.schemas, input.id, diagnostics);
15
- const endpoints = normalizeOpenApiEndpoints(input, baseUrl, diagnostics);
10
+ const endpoints = normalizeOpenApiEndpoints(input, diagnostics);
16
11
  if (baseUrl === undefined || diagnostics.some((diagnostic) => diagnostic.severity === 'error')) {
17
12
  return { ok: false, diagnostics };
18
13
  }
@@ -20,7 +15,6 @@ export function importOpenApiDocument(input) {
20
15
  ok: true,
21
16
  data: {
22
17
  id: input.id,
23
- kind: 'api',
24
18
  origin: 'external',
25
19
  protocol: 'rest',
26
20
  name: input.name ?? input.document.info?.title,
@@ -39,43 +33,6 @@ export function importOpenApiDocument(input) {
39
33
  diagnostics,
40
34
  };
41
35
  }
42
- export function normalizeOpenApiOperationId(method, path, operationId) {
43
- const rawId = operationId ?? `${method}-${path}`;
44
- const normalized = rawId
45
- .replace(/\{([^}]+)\}/g, '$1')
46
- .replace(/[^A-Za-z0-9]+/g, '-')
47
- .replace(/^-+|-+$/g, '')
48
- .toLowerCase();
49
- return normalized.length > 0 ? normalized : `${method}-root`;
50
- }
51
- export function normalizeOpenApiEndpointId(path) {
52
- const normalized = path
53
- .replace(/\{([^}]+)\}/g, '$1')
54
- .replace(/[^A-Za-z0-9]+/g, '-')
55
- .replace(/^-+|-+$/g, '')
56
- .toLowerCase();
57
- return normalized.length > 0 ? normalized : 'root';
58
- }
59
- export function normalizeOpenApiSchema(schema) {
60
- return {
61
- ref: normalizeOpenApiSchemaRef(schema.$ref),
62
- type: normalizeSchemaType(schema.type),
63
- title: schema.title,
64
- description: schema.description,
65
- enum: schema.enum,
66
- const: schema.const,
67
- default: schema.default,
68
- format: schema.format,
69
- nullable: schema.nullable,
70
- required: schema.required,
71
- properties: normalizeSchemaRecord(schema.properties),
72
- additionalProperties: normalizeAdditionalProperties(schema.additionalProperties),
73
- items: schema.items === undefined ? undefined : normalizeOpenApiSchema(schema.items),
74
- allOf: normalizeSchemaList(schema.allOf),
75
- anyOf: normalizeSchemaList(schema.anyOf),
76
- oneOf: normalizeSchemaList(schema.oneOf),
77
- };
78
- }
79
36
  function resolveOpenApiBaseUrl(input, diagnostics) {
80
37
  if (input.baseUrl !== undefined && input.baseUrl.trim().length > 0)
81
38
  return input.baseUrl;
@@ -83,7 +40,7 @@ function resolveOpenApiBaseUrl(input, diagnostics) {
83
40
  if (servers.length === 0) {
84
41
  diagnostics.push({
85
42
  code: 'ambiguous-server',
86
- dataSourceId: input.id,
43
+ apiId: input.id,
87
44
  message: 'OpenAPI import requires a server URL or an explicit baseUrl override.',
88
45
  path: 'servers',
89
46
  severity: 'error',
@@ -93,7 +50,7 @@ function resolveOpenApiBaseUrl(input, diagnostics) {
93
50
  if (servers.length > 1) {
94
51
  diagnostics.push({
95
52
  code: 'ambiguous-server',
96
- dataSourceId: input.id,
53
+ apiId: input.id,
97
54
  message: 'OpenAPI document defines multiple servers. The first server URL was selected.',
98
55
  path: 'servers',
99
56
  severity: 'warning',
@@ -101,220 +58,4 @@ function resolveOpenApiBaseUrl(input, diagnostics) {
101
58
  }
102
59
  return servers[0]?.url;
103
60
  }
104
- function normalizeOpenApiSchemas(schemas, dataSourceId, diagnostics) {
105
- if (schemas === undefined)
106
- return undefined;
107
- const registry = {};
108
- for (const [schemaId, schema] of Object.entries(schemas)) {
109
- registry[schemaId] = normalizeOpenApiSchema(schema);
110
- collectUnsupportedSchemaDiagnostics(schema, dataSourceId, `components.schemas.${schemaId}`, diagnostics);
111
- }
112
- return registry;
113
- }
114
- function normalizeOpenApiEndpoints(input, baseUrl, diagnostics) {
115
- const { paths } = input.document;
116
- if (paths === undefined || Object.keys(paths).length === 0) {
117
- diagnostics.push({
118
- code: 'invalid-config',
119
- dataSourceId: input.id,
120
- message: 'OpenAPI document must define at least one path.',
121
- path: 'paths',
122
- severity: 'error',
123
- });
124
- return {};
125
- }
126
- const endpoints = {};
127
- const operationIds = new Set();
128
- for (const [path, pathItem] of Object.entries(paths)) {
129
- const endpointId = normalizeOpenApiEndpointId(path);
130
- const operations = {};
131
- for (const method of OPENAPI_HTTP_METHODS) {
132
- const operation = pathItem[method];
133
- if (operation === undefined)
134
- continue;
135
- const operationId = resolveUniqueOperationId(input.id, endpointId, method, path, operation.operationId, operationIds, diagnostics);
136
- const parameters = normalizeOpenApiParameters([...(pathItem.parameters ?? []), ...(operation.parameters ?? [])], input.id, endpointId, operationId, diagnostics);
137
- operations[operationId] = {
138
- id: operationId,
139
- endpointId,
140
- name: operation.summary,
141
- description: operation.description,
142
- protocol: 'http',
143
- intent: mapOpenApiMethodToIntent(method),
144
- method: method.toUpperCase(),
145
- path,
146
- request: normalizeOpenApiRequest(operation.requestBody, parameters),
147
- response: normalizeOpenApiResponse(operation.responses),
148
- metadata: {
149
- deprecated: operation.deprecated ?? false,
150
- source: 'openapi',
151
- },
152
- };
153
- }
154
- endpoints[endpointId] = {
155
- id: endpointId,
156
- kind: 'http',
157
- baseUrl,
158
- path,
159
- credential: input.credential,
160
- operations,
161
- };
162
- }
163
- return endpoints;
164
- }
165
- function resolveUniqueOperationId(dataSourceId, endpointId, method, path, operationId, operationIds, diagnostics) {
166
- const normalized = normalizeOpenApiOperationId(method, path, operationId);
167
- if (!operationIds.has(normalized)) {
168
- operationIds.add(normalized);
169
- return normalized;
170
- }
171
- let suffix = 2;
172
- let uniqueId = `${normalized}-${suffix}`;
173
- while (operationIds.has(uniqueId)) {
174
- suffix += 1;
175
- uniqueId = `${normalized}-${suffix}`;
176
- }
177
- operationIds.add(uniqueId);
178
- diagnostics.push({
179
- code: 'duplicate-operation-id',
180
- dataSourceId,
181
- endpointId,
182
- operationId: uniqueId,
183
- message: `OpenAPI operation id '${normalized}' is duplicated. Normalized to '${uniqueId}'.`,
184
- path: `paths.${path}.${method}.operationId`,
185
- severity: 'warning',
186
- });
187
- return uniqueId;
188
- }
189
- function normalizeOpenApiParameters(parameters, dataSourceId, endpointId, operationId, diagnostics) {
190
- if (parameters.length === 0)
191
- return undefined;
192
- const normalized = [];
193
- for (const parameter of parameters) {
194
- const location = normalizeParameterLocation(parameter.in);
195
- if (location === undefined) {
196
- diagnostics.push({
197
- code: 'invalid-config',
198
- dataSourceId,
199
- endpointId,
200
- operationId,
201
- message: `OpenAPI parameter '${parameter.name}' uses unsupported location '${parameter.in}'.`,
202
- path: `paths.${endpointId}.parameters.${parameter.name}`,
203
- severity: 'warning',
204
- });
205
- continue;
206
- }
207
- normalized.push({
208
- name: parameter.name,
209
- location,
210
- required: parameter.required,
211
- description: parameter.description,
212
- schema: parameter.schema === undefined ? undefined : normalizeOpenApiSchema(parameter.schema),
213
- });
214
- }
215
- return normalized;
216
- }
217
- function normalizeParameterLocation(location) {
218
- if (location === 'cookie' ||
219
- location === 'header' ||
220
- location === 'path' ||
221
- location === 'query') {
222
- return location;
223
- }
224
- return undefined;
225
- }
226
- function normalizeOpenApiRequest(requestBody, parameters) {
227
- const content = firstContentEntry(requestBody?.content);
228
- if (requestBody === undefined && parameters === undefined)
229
- return undefined;
230
- return {
231
- contentType: content?.contentType,
232
- parameters,
233
- schema: content?.schema === undefined ? undefined : normalizeOpenApiSchema(content.schema),
234
- };
235
- }
236
- function normalizeOpenApiResponse(responses) {
237
- if (responses === undefined)
238
- return undefined;
239
- const status = chooseResponseStatus(Object.keys(responses));
240
- if (status === undefined)
241
- return undefined;
242
- const response = responses[status];
243
- const content = firstContentEntry(response?.content);
244
- return {
245
- status,
246
- contentType: content?.contentType,
247
- description: response?.description,
248
- schema: content?.schema === undefined ? undefined : normalizeOpenApiSchema(content.schema),
249
- };
250
- }
251
- function firstContentEntry(content) {
252
- if (content === undefined)
253
- return undefined;
254
- const [entry] = Object.entries(content);
255
- if (entry === undefined)
256
- return undefined;
257
- const [contentType, media] = entry;
258
- return { contentType, schema: media.schema };
259
- }
260
- function chooseResponseStatus(statuses) {
261
- return statuses.find((status) => status.startsWith('2')) ?? statuses[0];
262
- }
263
- function mapOpenApiMethodToIntent(method) {
264
- if (method === 'get' || method === 'head')
265
- return 'read';
266
- if (method === 'post')
267
- return 'create';
268
- if (method === 'delete')
269
- return 'delete';
270
- if (method === 'patch' || method === 'put')
271
- return 'update';
272
- return 'action';
273
- }
274
- function normalizeOpenApiSchemaRef(ref) {
275
- if (ref === undefined)
276
- return undefined;
277
- const prefix = '#/components/schemas/';
278
- return { id: ref.startsWith(prefix) ? ref.slice(prefix.length) : ref };
279
- }
280
- function normalizeSchemaRecord(record) {
281
- if (record === undefined)
282
- return undefined;
283
- return Object.fromEntries(Object.entries(record).map(([key, schema]) => [key, normalizeOpenApiSchema(schema)]));
284
- }
285
- function normalizeSchemaList(list) {
286
- return list?.map(normalizeOpenApiSchema);
287
- }
288
- function normalizeAdditionalProperties(value) {
289
- if (value === undefined || typeof value === 'boolean')
290
- return value;
291
- return normalizeOpenApiSchema(value);
292
- }
293
- function normalizeSchemaType(type) {
294
- if (type === undefined)
295
- return undefined;
296
- if (typeof type === 'string')
297
- return isDataSchemaPrimitive(type) ? type : undefined;
298
- return type.filter(isDataSchemaPrimitive);
299
- }
300
- function isDataSchemaPrimitive(type) {
301
- return DATA_SCHEMA_PRIMITIVES.some((primitive) => primitive === type);
302
- }
303
- function collectUnsupportedSchemaDiagnostics(schema, dataSourceId, path, diagnostics) {
304
- if (typeof schema.type === 'string' && !isDataSchemaPrimitive(schema.type)) {
305
- diagnostics.push({
306
- code: 'unsupported-schema',
307
- dataSourceId,
308
- message: `OpenAPI schema type '${schema.type}' is not supported by the normalized schema model.`,
309
- path: `${path}.type`,
310
- severity: 'warning',
311
- });
312
- }
313
- for (const [propertyName, propertySchema] of Object.entries(schema.properties ?? {})) {
314
- collectUnsupportedSchemaDiagnostics(propertySchema, dataSourceId, `${path}.properties.${propertyName}`, diagnostics);
315
- }
316
- if (schema.items !== undefined) {
317
- collectUnsupportedSchemaDiagnostics(schema.items, dataSourceId, `${path}.items`, diagnostics);
318
- }
319
- }
320
61
  //# sourceMappingURL=index.js.map