@ankhorage/data-sources 0.0.0 → 0.1.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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # @ankhorage/data-sources
2
+
3
+ ## 0.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - a52311c: Add manual REST data-source definition helpers with normalization and structured diagnostics.
8
+ - 84ddd56: Add dependency-free OpenAPI JSON import helpers that normalize paths, operations, parameters, requests, responses, schemas, and diagnostics into shared Ankhorage data-source contracts.
9
+ - bee5b37: Establish the package baseline, ownership boundaries, shared contracts dependency, and initial smoke-tested public API.
package/README.md CHANGED
@@ -15,6 +15,10 @@ Provider-neutral data source and endpoint system for APIs, databases, and runtim
15
15
  - [Architecture overview](././paradox/diagrams/architecture-overview.mmd)
16
16
  - [Module relationships](././paradox/diagrams/module-relationships.mmd)
17
17
  - [Export graph](././paradox/diagrams/export-graph.mmd)
18
+ - [createManualRestDataSource sequence](././paradox/diagrams/sequences/create-manual-rest-data-source.mmd)
19
+ - [normalizeManualRestDataSource sequence](././paradox/diagrams/sequences/normalize-manual-rest-data-source.mmd)
20
+ - [normalizeOpenApiSchema sequence](././paradox/diagrams/sequences/normalize-open-api-schema.mmd)
21
+ - [validateManualRestDataSource sequence](././paradox/diagrams/sequences/validate-manual-rest-data-source.mmd)
18
22
 
19
23
  ## Architecture preview
20
24
 
@@ -27,6 +31,10 @@ graph TD
27
31
  entrypoint_src_index_ts["src/index.ts"]
28
32
  package__ankhorage_data_sources --> entrypoint_src_index_ts
29
33
  module_src_index_ts["src/index.ts"]
34
+ module_src_openapi_index_ts["src/openapi/index.ts"]
35
+ package__ankhorage_data_sources -.-> module_src_openapi_index_ts
36
+ module_src_rest_index_ts["src/rest/index.ts"]
37
+ package__ankhorage_data_sources -.-> module_src_rest_index_ts
30
38
  ```
31
39
 
32
40
  </details>
package/dist/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import type { DataSourceConfig, DataSourceKind } from '@ankhorage/contracts/data';
2
+ export * from './openapi';
3
+ export * from './rest';
2
4
  export declare const DATA_SOURCES_PACKAGE_NAME: "@ankhorage/data-sources";
3
5
  export declare const SUPPORTED_DATA_SOURCE_KINDS: readonly ["database", "graphql", "managed-api", "openapi", "rest"];
4
6
  export interface DataSourcesPackageInfo {
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAElF,eAAO,MAAM,yBAAyB,EAAG,yBAAkC,CAAC;AAE5E,eAAO,MAAM,2BAA2B,oEAMM,CAAC;AAE/C,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,WAAW,EAAE,OAAO,yBAAyB,CAAC;IACvD,QAAQ,CAAC,cAAc,EAAE,OAAO,2BAA2B,CAAC;CAC7D;AAED,wBAAgB,yBAAyB,IAAI,sBAAsB,CAKlE;AAED,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,cAAc,CAE9E;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,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAElF,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AAEvB,eAAO,MAAM,yBAAyB,EAAG,yBAAkC,CAAC;AAE5E,eAAO,MAAM,2BAA2B,oEAMM,CAAC;AAE/C,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,WAAW,EAAE,OAAO,yBAAyB,CAAC;IACvD,QAAQ,CAAC,cAAc,EAAE,OAAO,2BAA2B,CAAC;CAC7D;AAED,wBAAgB,yBAAyB,IAAI,sBAAsB,CAKlE;AAED,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,cAAc,CAE9E;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,gBAAgB,GAAG,cAAc,CAE1E"}
package/dist/index.js CHANGED
@@ -1,3 +1,5 @@
1
+ export * from './openapi';
2
+ export * from './rest';
1
3
  export const DATA_SOURCES_PACKAGE_NAME = '@ankhorage/data-sources';
2
4
  export const SUPPORTED_DATA_SOURCE_KINDS = [
3
5
  'database',
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,yBAAyB,GAAG,yBAAkC,CAAC;AAE5E,MAAM,CAAC,MAAM,2BAA2B,GAAG;IACzC,UAAU;IACV,SAAS;IACT,aAAa;IACb,SAAS;IACT,MAAM;CACsC,CAAC;AAO/C,MAAM,UAAU,yBAAyB;IACvC,OAAO;QACL,WAAW,EAAE,yBAAyB;QACtC,cAAc,EAAE,2BAA2B;KAC5C,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,yBAAyB,CAAC,IAAY;IACpD,OAAO,2BAA2B,CAAC,IAAI,CAAC,CAAC,aAAa,EAAE,EAAE,CAAC,aAAa,KAAK,IAAI,CAAC,CAAC;AACrF,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,MAAwB;IACxD,OAAO,MAAM,CAAC,IAAI,CAAC;AACrB,CAAC","sourcesContent":["import type { DataSourceConfig, DataSourceKind } from '@ankhorage/contracts/data';\n\nexport const DATA_SOURCES_PACKAGE_NAME = '@ankhorage/data-sources' as const;\n\nexport const SUPPORTED_DATA_SOURCE_KINDS = [\n 'database',\n 'graphql',\n 'managed-api',\n 'openapi',\n 'rest',\n] as const satisfies readonly DataSourceKind[];\n\nexport interface DataSourcesPackageInfo {\n readonly packageName: typeof DATA_SOURCES_PACKAGE_NAME;\n readonly supportedKinds: typeof SUPPORTED_DATA_SOURCE_KINDS;\n}\n\nexport function getDataSourcesPackageInfo(): DataSourcesPackageInfo {\n return {\n packageName: DATA_SOURCES_PACKAGE_NAME,\n supportedKinds: SUPPORTED_DATA_SOURCE_KINDS,\n };\n}\n\nexport function isSupportedDataSourceKind(kind: string): kind is DataSourceKind {\n return SUPPORTED_DATA_SOURCE_KINDS.some((supportedKind) => supportedKind === kind);\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":"AAEA,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AAEvB,MAAM,CAAC,MAAM,yBAAyB,GAAG,yBAAkC,CAAC;AAE5E,MAAM,CAAC,MAAM,2BAA2B,GAAG;IACzC,UAAU;IACV,SAAS;IACT,aAAa;IACb,SAAS;IACT,MAAM;CACsC,CAAC;AAO/C,MAAM,UAAU,yBAAyB;IACvC,OAAO;QACL,WAAW,EAAE,yBAAyB;QACtC,cAAc,EAAE,2BAA2B;KAC5C,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,yBAAyB,CAAC,IAAY;IACpD,OAAO,2BAA2B,CAAC,IAAI,CAAC,CAAC,aAAa,EAAE,EAAE,CAAC,aAAa,KAAK,IAAI,CAAC,CAAC;AACrF,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,MAAwB;IACxD,OAAO,MAAM,CAAC,IAAI,CAAC;AACrB,CAAC","sourcesContent":["import type { DataSourceConfig, DataSourceKind } from '@ankhorage/contracts/data';\n\nexport * from './openapi';\nexport * from './rest';\n\nexport const DATA_SOURCES_PACKAGE_NAME = '@ankhorage/data-sources' as const;\n\nexport const SUPPORTED_DATA_SOURCE_KINDS = [\n 'database',\n 'graphql',\n 'managed-api',\n 'openapi',\n 'rest',\n] as const satisfies readonly DataSourceKind[];\n\nexport interface DataSourcesPackageInfo {\n readonly packageName: typeof DATA_SOURCES_PACKAGE_NAME;\n readonly supportedKinds: typeof SUPPORTED_DATA_SOURCE_KINDS;\n}\n\nexport function getDataSourcesPackageInfo(): DataSourcesPackageInfo {\n return {\n packageName: DATA_SOURCES_PACKAGE_NAME,\n supportedKinds: SUPPORTED_DATA_SOURCE_KINDS,\n };\n}\n\nexport function isSupportedDataSourceKind(kind: string): kind is DataSourceKind {\n return SUPPORTED_DATA_SOURCE_KINDS.some((supportedKind) => supportedKind === kind);\n}\n\nexport function getDataSourceKind(source: DataSourceConfig): DataSourceKind {\n return source.kind;\n}\n"]}
@@ -0,0 +1,89 @@
1
+ import type { CredentialRef, DataContractValue, DataSchema, DataSourceDiagnosticResult, EndpointId, OpenApiDataSourceConfig, 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<OpenApiDataSourceConfig>;
84
+ 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
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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,uBAAuB,EACvB,WAAW,EACZ,MAAM,2BAA2B,CAAC;AAEnC,QAAA,MAAM,oBAAoB,uEAAwE,CAAC;AAWnG,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEtE,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAAC;IAC3C,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,iBAAiB,EAAE,CAAC;IAC7C,QAAQ,CAAC,KAAK,CAAC,EAAE,iBAAiB,CAAC;IACnC,QAAQ,CAAC,OAAO,CAAC,EAAE,iBAAiB,CAAC;IACrC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,MAAM,EAAE,C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qBAAqB,CAAC,CAAC,CAAC;IACjE,QAAQ,CAAC,UAAU,CAAC,EAAE,uBAAuB,CAAC;CAC/C;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,QAAQ,EAAE,qBAAqB,CAAC;IACzC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,UAAU,CAAC,EAAE,aAAa,CAAC;IACpC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,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,uBAAuB,CAAC,CAAC;AAEtF,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,kBAAkB,GAAG,mBAAmB,CAmCpF;AAED,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,iBAAiB,EACzB,IAAI,EAAE,MAAM,EACZ,WAAW,CAAC,EAAE,MAAM,GACnB,WAAW,CASb;AAED,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CAQnE;AAED,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,mBAAmB,GAAG,UAAU,CAqB9E"}
@@ -0,0 +1,330 @@
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
+ ];
11
+ export function importOpenApiDocument(input) {
12
+ const diagnostics = [];
13
+ const baseUrl = resolveOpenApiBaseUrl(input, diagnostics);
14
+ const schemas = normalizeOpenApiSchemas(input.document.components?.schemas, input.id, diagnostics);
15
+ const endpoints = normalizeOpenApiEndpoints(input, baseUrl, diagnostics);
16
+ const hasErrors = diagnostics.some((diagnostic) => diagnostic.severity === 'error');
17
+ if (hasErrors) {
18
+ return { ok: false, diagnostics };
19
+ }
20
+ return {
21
+ ok: true,
22
+ data: {
23
+ id: input.id,
24
+ kind: 'openapi',
25
+ name: input.name ?? input.document.info?.title,
26
+ description: input.description ?? input.document.info?.description,
27
+ baseUrl,
28
+ credential: input.credential,
29
+ endpoints,
30
+ schemas,
31
+ import: {
32
+ url: input.documentUrl,
33
+ documentId: input.documentId,
34
+ version: input.document.info?.version,
35
+ },
36
+ metadata: input.metadata,
37
+ },
38
+ diagnostics,
39
+ };
40
+ }
41
+ export function normalizeOpenApiOperationId(method, path, operationId) {
42
+ const rawId = operationId ?? `${method}-${path}`;
43
+ const normalized = rawId
44
+ .replace(/\{([^}]+)\}/g, '$1')
45
+ .replace(/[^A-Za-z0-9]+/g, '-')
46
+ .replace(/^-+|-+$/g, '')
47
+ .toLowerCase();
48
+ return normalized.length > 0 ? normalized : `${method}-root`;
49
+ }
50
+ export function normalizeOpenApiEndpointId(path) {
51
+ const normalized = path
52
+ .replace(/\{([^}]+)\}/g, '$1')
53
+ .replace(/[^A-Za-z0-9]+/g, '-')
54
+ .replace(/^-+|-+$/g, '')
55
+ .toLowerCase();
56
+ return normalized.length > 0 ? normalized : 'root';
57
+ }
58
+ export function normalizeOpenApiSchema(schema) {
59
+ const additionalProperties = normalizeAdditionalProperties(schema.additionalProperties);
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,
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
+ function resolveOpenApiBaseUrl(input, diagnostics) {
80
+ if (input.baseUrl !== undefined)
81
+ return input.baseUrl;
82
+ const servers = input.document.servers ?? [];
83
+ if (servers.length === 0) {
84
+ diagnostics.push({
85
+ code: 'ambiguous-server',
86
+ dataSourceId: input.id,
87
+ message: 'OpenAPI document does not define a server URL and no baseUrl override was provided.',
88
+ path: 'servers',
89
+ severity: 'warning',
90
+ });
91
+ return undefined;
92
+ }
93
+ if (servers.length > 1) {
94
+ diagnostics.push({
95
+ code: 'ambiguous-server',
96
+ dataSourceId: input.id,
97
+ message: 'OpenAPI document defines multiple servers. The first server URL was selected.',
98
+ path: 'servers',
99
+ severity: 'warning',
100
+ });
101
+ }
102
+ return servers[0]?.url;
103
+ }
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
+ const request = normalizeOpenApiRequest(operation.requestBody, parameters);
138
+ const response = normalizeOpenApiResponse(operation.responses);
139
+ operations[operationId] = {
140
+ id: operationId,
141
+ endpointId,
142
+ name: operation.summary,
143
+ description: operation.description,
144
+ protocol: 'http',
145
+ intent: mapOpenApiMethodToIntent(method),
146
+ method: method.toUpperCase(),
147
+ path,
148
+ request,
149
+ response,
150
+ metadata: {
151
+ deprecated: operation.deprecated ?? false,
152
+ source: 'openapi',
153
+ },
154
+ };
155
+ }
156
+ endpoints[endpointId] = {
157
+ id: endpointId,
158
+ kind: 'http',
159
+ baseUrl,
160
+ path,
161
+ credential: input.credential,
162
+ operations,
163
+ };
164
+ }
165
+ return endpoints;
166
+ }
167
+ function resolveUniqueOperationId(dataSourceId, endpointId, method, path, operationId, operationIds, diagnostics) {
168
+ const normalized = normalizeOpenApiOperationId(method, path, operationId);
169
+ if (!operationIds.has(normalized)) {
170
+ operationIds.add(normalized);
171
+ return normalized;
172
+ }
173
+ let suffix = 2;
174
+ let uniqueId = `${normalized}-${suffix}`;
175
+ while (operationIds.has(uniqueId)) {
176
+ suffix += 1;
177
+ uniqueId = `${normalized}-${suffix}`;
178
+ }
179
+ operationIds.add(uniqueId);
180
+ diagnostics.push({
181
+ code: 'duplicate-operation-id',
182
+ dataSourceId,
183
+ endpointId,
184
+ operationId: uniqueId,
185
+ message: `OpenAPI operation id '${normalized}' is duplicated. Normalized to '${uniqueId}'.`,
186
+ path: `paths.${path}.${method}.operationId`,
187
+ severity: 'warning',
188
+ });
189
+ return uniqueId;
190
+ }
191
+ function normalizeOpenApiParameters(parameters, dataSourceId, endpointId, operationId, diagnostics) {
192
+ if (parameters.length === 0)
193
+ return undefined;
194
+ const normalized = [];
195
+ for (const parameter of parameters) {
196
+ const location = normalizeParameterLocation(parameter.in);
197
+ if (location === undefined) {
198
+ diagnostics.push({
199
+ code: 'invalid-config',
200
+ dataSourceId,
201
+ endpointId,
202
+ operationId,
203
+ message: `OpenAPI parameter '${parameter.name}' uses unsupported location '${parameter.in}'.`,
204
+ path: `paths.${endpointId}.parameters.${parameter.name}`,
205
+ severity: 'warning',
206
+ });
207
+ continue;
208
+ }
209
+ normalized.push({
210
+ name: parameter.name,
211
+ location,
212
+ required: parameter.required,
213
+ description: parameter.description,
214
+ schema: parameter.schema === undefined ? undefined : normalizeOpenApiSchema(parameter.schema),
215
+ });
216
+ }
217
+ return normalized;
218
+ }
219
+ function normalizeParameterLocation(location) {
220
+ if (location === 'cookie' ||
221
+ location === 'header' ||
222
+ location === 'path' ||
223
+ location === 'query') {
224
+ return location;
225
+ }
226
+ return undefined;
227
+ }
228
+ function normalizeOpenApiRequest(requestBody, parameters) {
229
+ const content = firstContentEntry(requestBody?.content);
230
+ if (requestBody === undefined && parameters === undefined)
231
+ return undefined;
232
+ return {
233
+ contentType: content?.contentType,
234
+ parameters,
235
+ schema: content?.schema === undefined ? undefined : normalizeOpenApiSchema(content.schema),
236
+ };
237
+ }
238
+ function normalizeOpenApiResponse(responses) {
239
+ if (responses === undefined)
240
+ return undefined;
241
+ const status = chooseResponseStatus(Object.keys(responses));
242
+ if (status === undefined)
243
+ return undefined;
244
+ const response = responses[status];
245
+ const content = firstContentEntry(response?.content);
246
+ return {
247
+ status,
248
+ contentType: content?.contentType,
249
+ description: response?.description,
250
+ schema: content?.schema === undefined ? undefined : normalizeOpenApiSchema(content.schema),
251
+ };
252
+ }
253
+ function firstContentEntry(content) {
254
+ if (content === undefined)
255
+ return undefined;
256
+ const [entry] = Object.entries(content);
257
+ if (entry === undefined)
258
+ return undefined;
259
+ const [contentType, media] = entry;
260
+ return { contentType, schema: media.schema };
261
+ }
262
+ function chooseResponseStatus(statuses) {
263
+ return statuses.find((status) => status.startsWith('2')) ?? statuses[0];
264
+ }
265
+ function mapOpenApiMethodToIntent(method) {
266
+ if (method === 'get' || method === 'head')
267
+ return 'read';
268
+ if (method === 'post')
269
+ return 'create';
270
+ if (method === 'delete')
271
+ return 'delete';
272
+ if (method === 'patch' || method === 'put')
273
+ return 'update';
274
+ return 'action';
275
+ }
276
+ function normalizeOpenApiSchemaRef(ref) {
277
+ if (ref === undefined)
278
+ return undefined;
279
+ const prefix = '#/components/schemas/';
280
+ if (ref.startsWith(prefix))
281
+ return { id: ref.slice(prefix.length) };
282
+ return { id: ref };
283
+ }
284
+ function normalizeSchemaRecord(record) {
285
+ if (record === undefined)
286
+ return undefined;
287
+ const normalized = {};
288
+ for (const [key, schema] of Object.entries(record)) {
289
+ normalized[key] = normalizeOpenApiSchema(schema);
290
+ }
291
+ return normalized;
292
+ }
293
+ function normalizeSchemaList(list) {
294
+ return list?.map((schema) => normalizeOpenApiSchema(schema));
295
+ }
296
+ function normalizeAdditionalProperties(additionalProperties) {
297
+ if (additionalProperties === undefined || typeof additionalProperties === 'boolean') {
298
+ return additionalProperties;
299
+ }
300
+ return normalizeOpenApiSchema(additionalProperties);
301
+ }
302
+ function normalizeSchemaType(type) {
303
+ if (type === undefined)
304
+ return undefined;
305
+ if (typeof type === 'string') {
306
+ return isDataSchemaPrimitive(type) ? type : undefined;
307
+ }
308
+ return type.filter(isDataSchemaPrimitive);
309
+ }
310
+ function isDataSchemaPrimitive(type) {
311
+ return DATA_SCHEMA_PRIMITIVES.some((primitive) => primitive === type);
312
+ }
313
+ function collectUnsupportedSchemaDiagnostics(schema, dataSourceId, path, diagnostics) {
314
+ if (typeof schema.type === 'string' && !isDataSchemaPrimitive(schema.type)) {
315
+ diagnostics.push({
316
+ code: 'unsupported-schema',
317
+ dataSourceId,
318
+ message: `OpenAPI schema type '${schema.type}' is not supported by the normalized schema model.`,
319
+ path: `${path}.type`,
320
+ severity: 'warning',
321
+ });
322
+ }
323
+ for (const [propertyName, propertySchema] of Object.entries(schema.properties ?? {})) {
324
+ collectUnsupportedSchemaDiagnostics(propertySchema, dataSourceId, `${path}.properties.${propertyName}`, diagnostics);
325
+ }
326
+ if (schema.items !== undefined) {
327
+ collectUnsupportedSchemaDiagnostics(schema.items, dataSourceId, `${path}.items`, diagnostics);
328
+ }
329
+ }
330
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/openapi/index.ts"],"names":[],"mappings":"AAoBA,MAAM,oBAAoB,GAAG,CAAC,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,CAAU,CAAC;AACnG,MAAM,sBAAsB,GAAG;IAC7B,OAAO;IACP,SAAS;IACT,SAAS;IACT,MAAM;IACN,QAAQ;IACR,QAAQ;IACR,QAAQ;CAC6C,CAAC;AAgGxD,MAAM,UAAU,qBAAqB,CAAC,KAAyB;IAC7D,MAAM,WAAW,GAA2B,EAAE,CAAC;IAC/C,MAAM,OAAO,GAAG,qBAAqB,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;IAC1D,MAAM,OAAO,GAAG,uBAAuB,CACrC,KAAK,CAAC,QAAQ,CAAC,UAAU,EAAE,OAAO,EAClC,KAAK,CAAC,EAAE,EACR,WAAW,CACZ,CAAC;IACF,MAAM,SAAS,GAAG,yBAAyB,CAAC,KAAK,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC;IACzE,MAAM,SAAS,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC;IAEpF,IAAI,SAAS,EAAE,CAAC;QACd,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC;IACpC,CAAC;IAED,OAAO;QACL,EAAE,EAAE,IAAI;QACR,IAAI,EAAE;YACJ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AK,IAAI,CAAC,CAAC;AACxE,CAAC;AAED,SAAS,mCAAmC,CAC1C,MAA2B,EAC3B,YAAoB,EACpB,IAAY,EACZ,WAAmC;IAEnC,IAAI,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,IAAI,CAAC,qBAAqB,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;QAC3E,WAAW,CAAC,IAAI,CAAC;YACf,IAAI,EAAE,oBAAoB;YAC1B,YAAY;YACZ,OAAO,EAAE,wBAAwB,MAAM,CAAC,IAAI,oDAAoD;YAChG,IAAI,EAAE,GAAG,IAAI,OAAO;YACpB,QAAQ,EAAE,SAAS;SACpB,CAAC,CAAC;IACL,CAAC;IAED,KAAK,MAAM,CAAC,YAAY,EAAE,cAAc,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,IAAI,EAAE,CAAC,EAAE,CAAC;QACrF,mCAAmC,CACjC,cAAc,EACd,YAAY,EACZ,GAAG,IAAI,eAAe,YAAY,EAAE,EACpC,WAAW,CACZ,CAAC;IACJ,CAAC;IAED,IAAI,MAAM,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;QAC/B,mCAAmC,CAAC,MAAM,CAAC,KAAK,EAAE,YAAY,EAAE,GAAG,IAAI,QAAQ,EAAE,WAAW,CAAC,CAAC;IAChG,CAAC;AACH,CAAC","sourcesContent":["import type {\n CredentialRef,\n DataContractValue,\n DataEndpointConfig,\n DataOperationConfig,\n DataOperationIntent,\n DataOperationParameter,\n DataOperationParameterLocation,\n DataOperationRequest,\n DataOperationResponse,\n DataSchema,\n DataSchemaPrimitiveType,\n DataSchemaRegistry,\n DataSourceDiagnostic,\n DataSourceDiagnosticResult,\n EndpointId,\n OpenApiDataSourceConfig,\n OperationId,\n} from '@ankhorage/contracts/data';\n\nconst OPENAPI_HTTP_METHODS = ['delete', 'get', 'head', 'options', 'patch', 'post', 'put'] as const;\nconst DATA_SCHEMA_PRIMITIVES = [\n 'array',\n 'boolean',\n 'integer',\n 'null',\n 'number',\n 'object',\n 'string',\n] as const satisfies readonly DataSchemaPrimitiveType[];\n\nexport type OpenApiHttpMethod = (typeof OPENAPI_HTTP_METHODS)[number];\n\nexport interface OpenApiServerObject {\n readonly url: string;\n readonly description?: string;\n}\n\nexport interface OpenApiSchemaObject {\n readonly $ref?: string;\n readonly type?: string | readonly string[];\n readonly title?: string;\n readonly description?: string;\n readonly enum?: readonly DataContractValue[];\n readonly const?: DataContractValue;\n readonly default?: DataContractValue;\n readonly format?: string;\n readonly nullable?: boolean;\n readonly required?: readonly string[];\n readonly properties?: Readonly<Record<string, OpenApiSchemaObject>>;\n readonly additionalProperties?: boolean | OpenApiSchemaObject;\n readonly items?: OpenApiSchemaObject;\n readonly allOf?: readonly OpenApiSchemaObject[];\n readonly anyOf?: readonly OpenApiSchemaObject[];\n readonly oneOf?: readonly OpenApiSchemaObject[];\n}\n\nexport interface OpenApiMediaTypeObject {\n readonly schema?: OpenApiSchemaObject;\n}\n\nexport interface OpenApiRequestBodyObject {\n readonly description?: string;\n readonly required?: boolean;\n readonly content?: Readonly<Record<string, OpenApiMediaTypeObject>>;\n}\n\nexport interface OpenApiResponseObject {\n readonly description?: string;\n readonly content?: Readonly<Record<string, OpenApiMediaTypeObject>>;\n}\n\nexport interface OpenApiParameterObject {\n readonly name: string;\n readonly in: string;\n readonly required?: boolean;\n readonly description?: string;\n readonly schema?: OpenApiSchemaObject;\n}\n\nexport interface OpenApiOperationObject {\n readonly operationId?: string;\n readonly summary?: string;\n readonly description?: string;\n readonly deprecated?: boolean;\n readonly parameters?: readonly OpenApiParameterObject[];\n readonly requestBody?: OpenApiRequestBodyObject;\n readonly responses?: Readonly<Record<string, OpenApiResponseObject>>;\n}\n\nexport type OpenApiPathItemObject = Partial<Record<OpenApiHttpMethod, OpenApiOperationObject>> & {\n readonly parameters?: readonly OpenApiParameterObject[];\n};\n\nexport interface OpenApiComponentsObject {\n readonly schemas?: Readonly<Record<string, OpenApiSchemaObject>>;\n readonly securitySchemes?: Readonly<Record<string, DataContractValue>>;\n}\n\nexport interface OpenApiDocumentObject {\n readonly openapi?: string;\n readonly info?: {\n readonly title?: string;\n readonly version?: string;\n readonly description?: string;\n };\n readonly servers?: readonly OpenApiServerObject[];\n readonly paths?: Readonly<Record<string, OpenApiPathItemObject>>;\n readonly components?: OpenApiComponentsObject;\n}\n\nexport interface OpenApiImportInput {\n readonly id: string;\n readonly document: OpenApiDocumentObject;\n readonly baseUrl?: string;\n readonly credential?: CredentialRef;\n readonly documentId?: string;\n readonly documentUrl?: string;\n readonly name?: string;\n readonly description?: string;\n readonly metadata?: DataContractValue;\n}\n\nexport type OpenApiImportResult = DataSourceDiagnosticResult<OpenApiDataSourceConfig>;\n\nexport function importOpenApiDocument(input: OpenApiImportInput): OpenApiImportResult {\n const diagnostics: DataSourceDiagnostic[] = [];\n const baseUrl = resolveOpenApiBaseUrl(input, diagnostics);\n const schemas = normalizeOpenApiSchemas(\n input.document.components?.schemas,\n input.id,\n diagnostics,\n );\n const endpoints = normalizeOpenApiEndpoints(input, baseUrl, diagnostics);\n const hasErrors = diagnostics.some((diagnostic) => diagnostic.severity === 'error');\n\n if (hasErrors) {\n return { ok: false, diagnostics };\n }\n\n return {\n ok: true,\n data: {\n id: input.id,\n kind: 'openapi',\n name: input.name ?? input.document.info?.title,\n description: input.description ?? input.document.info?.description,\n baseUrl,\n credential: input.credential,\n endpoints,\n schemas,\n import: {\n url: input.documentUrl,\n documentId: input.documentId,\n version: input.document.info?.version,\n },\n metadata: input.metadata,\n },\n diagnostics,\n };\n}\n\nexport function normalizeOpenApiOperationId(\n method: OpenApiHttpMethod,\n path: string,\n operationId?: string,\n): OperationId {\n const rawId = operationId ?? `${method}-${path}`;\n const normalized = rawId\n .replace(/\\{([^}]+)\\}/g, '$1')\n .replace(/[^A-Za-z0-9]+/g, '-')\n .replace(/^-+|-+$/g, '')\n .toLowerCase();\n\n return normalized.length > 0 ? normalized : `${method}-root`;\n}\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\n return normalized.length > 0 ? normalized : 'root';\n}\n\nexport function normalizeOpenApiSchema(schema: OpenApiSchemaObject): DataSchema {\n const additionalProperties = normalizeAdditionalProperties(schema.additionalProperties);\n\n return {\n ref: normalizeOpenApiSchemaRef(schema.$ref),\n type: normalizeSchemaType(schema.type),\n title: schema.title,\n description: schema.description,\n enum: schema.enum,\n const: schema.const,\n default: schema.default,\n format: schema.format,\n nullable: schema.nullable,\n required: schema.required,\n properties: normalizeSchemaRecord(schema.properties),\n additionalProperties,\n items: schema.items === undefined ? undefined : normalizeOpenApiSchema(schema.items),\n allOf: normalizeSchemaList(schema.allOf),\n anyOf: normalizeSchemaList(schema.anyOf),\n oneOf: normalizeSchemaList(schema.oneOf),\n };\n}\n\nfunction resolveOpenApiBaseUrl(\n input: OpenApiImportInput,\n diagnostics: DataSourceDiagnostic[],\n): string | undefined {\n if (input.baseUrl !== undefined) return input.baseUrl;\n\n const servers = input.document.servers ?? [];\n\n if (servers.length === 0) {\n diagnostics.push({\n code: 'ambiguous-server',\n dataSourceId: input.id,\n message:\n 'OpenAPI document does not define a server URL and no baseUrl override was provided.',\n path: 'servers',\n severity: 'warning',\n });\n return undefined;\n }\n\n if (servers.length > 1) {\n diagnostics.push({\n code: 'ambiguous-server',\n dataSourceId: input.id,\n message: 'OpenAPI document defines multiple servers. The first server URL was selected.',\n path: 'servers',\n severity: 'warning',\n });\n }\n\n return servers[0]?.url;\n}\n\nfunction normalizeOpenApiSchemas(\n schemas: Readonly<Record<string, OpenApiSchemaObject>> | undefined,\n dataSourceId: string,\n diagnostics: DataSourceDiagnostic[],\n): DataSchemaRegistry | undefined {\n if (schemas === undefined) return undefined;\n\n const registry: Record<string, DataSchema> = {};\n\n for (const [schemaId, schema] of Object.entries(schemas)) {\n registry[schemaId] = normalizeOpenApiSchema(schema);\n collectUnsupportedSchemaDiagnostics(\n schema,\n dataSourceId,\n `components.schemas.${schemaId}`,\n diagnostics,\n );\n }\n\n return registry;\n}\n\nfunction normalizeOpenApiEndpoints(\n input: OpenApiImportInput,\n baseUrl: string | undefined,\n diagnostics: DataSourceDiagnostic[],\n): Record<EndpointId, DataEndpointConfig> {\n const { paths } = input.document;\n\n if (paths === undefined || Object.keys(paths).length === 0) {\n diagnostics.push({\n code: 'invalid-config',\n dataSourceId: 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 endpoints: Record<EndpointId, DataEndpointConfig> = {};\n const operationIds = new Set<OperationId>();\n\n for (const [path, pathItem] of Object.entries(paths)) {\n const endpointId = normalizeOpenApiEndpointId(path);\n const operations: Record<OperationId, DataOperationConfig> = {};\n\n for (const method of OPENAPI_HTTP_METHODS) {\n const operation = pathItem[method];\n if (operation === undefined) continue;\n\n const operationId = resolveUniqueOperationId(\n input.id,\n endpointId,\n method,\n path,\n operation.operationId,\n operationIds,\n diagnostics,\n );\n const parameters = normalizeOpenApiParameters(\n [...(pathItem.parameters ?? []), ...(operation.parameters ?? [])],\n input.id,\n endpointId,\n operationId,\n diagnostics,\n );\n const request = normalizeOpenApiRequest(operation.requestBody, parameters);\n const response = normalizeOpenApiResponse(operation.responses);\n\n operations[operationId] = {\n id: operationId,\n endpointId,\n name: operation.summary,\n description: operation.description,\n protocol: 'http',\n intent: mapOpenApiMethodToIntent(method),\n method: method.toUpperCase(),\n path,\n request,\n response,\n metadata: {\n deprecated: operation.deprecated ?? false,\n source: 'openapi',\n },\n };\n }\n\n endpoints[endpointId] = {\n id: endpointId,\n kind: 'http',\n baseUrl,\n path,\n credential: input.credential,\n operations,\n };\n }\n\n return endpoints;\n}\n\nfunction resolveUniqueOperationId(\n dataSourceId: string,\n endpointId: EndpointId,\n method: OpenApiHttpMethod,\n path: string,\n operationId: string | undefined,\n operationIds: Set<OperationId>,\n diagnostics: DataSourceDiagnostic[],\n): OperationId {\n const normalized = normalizeOpenApiOperationId(method, path, operationId);\n\n if (!operationIds.has(normalized)) {\n operationIds.add(normalized);\n return normalized;\n }\n\n let suffix = 2;\n let uniqueId: OperationId = `${normalized}-${suffix}`;\n\n while (operationIds.has(uniqueId)) {\n suffix += 1;\n uniqueId = `${normalized}-${suffix}`;\n }\n\n operationIds.add(uniqueId);\n diagnostics.push({\n code: 'duplicate-operation-id',\n dataSourceId,\n endpointId,\n operationId: uniqueId,\n message: `OpenAPI operation id '${normalized}' is duplicated. Normalized to '${uniqueId}'.`,\n path: `paths.${path}.${method}.operationId`,\n severity: 'warning',\n });\n\n return uniqueId;\n}\n\nfunction normalizeOpenApiParameters(\n parameters: readonly OpenApiParameterObject[],\n dataSourceId: string,\n endpointId: EndpointId,\n operationId: OperationId,\n diagnostics: DataSourceDiagnostic[],\n): readonly DataOperationParameter[] | undefined {\n if (parameters.length === 0) return undefined;\n\n const normalized: DataOperationParameter[] = [];\n\n for (const parameter of parameters) {\n const location = normalizeParameterLocation(parameter.in);\n\n if (location === undefined) {\n diagnostics.push({\n code: 'invalid-config',\n dataSourceId,\n endpointId,\n operationId,\n message: `OpenAPI parameter '${parameter.name}' uses unsupported location '${parameter.in}'.`,\n path: `paths.${endpointId}.parameters.${parameter.name}`,\n severity: 'warning',\n });\n continue;\n }\n\n normalized.push({\n name: parameter.name,\n location,\n required: parameter.required,\n description: parameter.description,\n schema: parameter.schema === undefined ? undefined : normalizeOpenApiSchema(parameter.schema),\n });\n }\n\n return normalized;\n}\n\nfunction normalizeParameterLocation(location: string): DataOperationParameterLocation | undefined {\n if (\n location === 'cookie' ||\n location === 'header' ||\n location === 'path' ||\n location === 'query'\n ) {\n return location;\n }\n\n return undefined;\n}\n\nfunction normalizeOpenApiRequest(\n requestBody: OpenApiRequestBodyObject | undefined,\n parameters: readonly DataOperationParameter[] | undefined,\n): DataOperationRequest | undefined {\n const content = firstContentEntry(requestBody?.content);\n\n if (requestBody === undefined && parameters === undefined) return undefined;\n\n return {\n contentType: content?.contentType,\n parameters,\n schema: content?.schema === undefined ? undefined : normalizeOpenApiSchema(content.schema),\n };\n}\n\nfunction normalizeOpenApiResponse(\n responses: Readonly<Record<string, OpenApiResponseObject>> | undefined,\n): DataOperationResponse | undefined {\n if (responses === undefined) return undefined;\n\n const status = chooseResponseStatus(Object.keys(responses));\n if (status === undefined) return undefined;\n\n const response = responses[status];\n const content = firstContentEntry(response?.content);\n\n return {\n status,\n contentType: content?.contentType,\n description: response?.description,\n schema: content?.schema === undefined ? undefined : normalizeOpenApiSchema(content.schema),\n };\n}\n\nfunction firstContentEntry(\n content: Readonly<Record<string, OpenApiMediaTypeObject>> | undefined,\n): { readonly contentType: string; readonly schema?: OpenApiSchemaObject } | undefined {\n if (content === undefined) return undefined;\n\n const [entry] = Object.entries(content);\n if (entry === undefined) return undefined;\n\n const [contentType, media] = entry;\n return { contentType, schema: media.schema };\n}\n\nfunction chooseResponseStatus(statuses: readonly string[]): string | undefined {\n return statuses.find((status) => status.startsWith('2')) ?? statuses[0];\n}\n\nfunction mapOpenApiMethodToIntent(method: OpenApiHttpMethod): DataOperationIntent {\n if (method === 'get' || method === 'head') return 'read';\n if (method === 'post') return 'create';\n if (method === 'delete') return 'delete';\n if (method === 'patch' || method === 'put') return 'update';\n return 'action';\n}\n\nfunction normalizeOpenApiSchemaRef(ref: string | undefined): { readonly id: string } | undefined {\n if (ref === undefined) return undefined;\n\n const prefix = '#/components/schemas/';\n if (ref.startsWith(prefix)) return { id: ref.slice(prefix.length) };\n\n return { id: ref };\n}\n\nfunction normalizeSchemaRecord(\n record: Readonly<Record<string, OpenApiSchemaObject>> | undefined,\n): Readonly<Record<string, DataSchema>> | undefined {\n if (record === undefined) return undefined;\n\n const normalized: Record<string, DataSchema> = {};\n\n for (const [key, schema] of Object.entries(record)) {\n normalized[key] = normalizeOpenApiSchema(schema);\n }\n\n return normalized;\n}\n\nfunction normalizeSchemaList(\n list: readonly OpenApiSchemaObject[] | undefined,\n): readonly DataSchema[] | undefined {\n return list?.map((schema) => normalizeOpenApiSchema(schema));\n}\n\nfunction normalizeAdditionalProperties(\n additionalProperties: boolean | OpenApiSchemaObject | undefined,\n): boolean | DataSchema | undefined {\n if (additionalProperties === undefined || typeof additionalProperties === 'boolean') {\n return additionalProperties;\n }\n\n return normalizeOpenApiSchema(additionalProperties);\n}\n\nfunction normalizeSchemaType(\n type: string | readonly string[] | undefined,\n): DataSchemaPrimitiveType | readonly DataSchemaPrimitiveType[] | undefined {\n if (type === undefined) return undefined;\n\n if (typeof type === 'string') {\n return isDataSchemaPrimitive(type) ? type : undefined;\n }\n\n return type.filter(isDataSchemaPrimitive);\n}\n\nfunction isDataSchemaPrimitive(type: string): type is DataSchemaPrimitiveType {\n return DATA_SCHEMA_PRIMITIVES.some((primitive) => primitive === type);\n}\n\nfunction collectUnsupportedSchemaDiagnostics(\n schema: OpenApiSchemaObject,\n dataSourceId: string,\n path: string,\n diagnostics: DataSourceDiagnostic[],\n): void {\n if (typeof schema.type === 'string' && !isDataSchemaPrimitive(schema.type)) {\n diagnostics.push({\n code: 'unsupported-schema',\n dataSourceId,\n message: `OpenAPI schema type '${schema.type}' is not supported by the normalized schema model.`,\n path: `${path}.type`,\n severity: 'warning',\n });\n }\n\n for (const [propertyName, propertySchema] of Object.entries(schema.properties ?? {})) {\n collectUnsupportedSchemaDiagnostics(\n propertySchema,\n dataSourceId,\n `${path}.properties.${propertyName}`,\n diagnostics,\n );\n }\n\n if (schema.items !== undefined) {\n collectUnsupportedSchemaDiagnostics(schema.items, dataSourceId, `${path}.items`, diagnostics);\n }\n}\n"]}
@@ -0,0 +1,44 @@
1
+ import type { CredentialRef, DataContractValue, DataOperationIntent, DataOperationMethod, DataOperationPagination, DataOperationParameter, DataOperationRequest, DataOperationResponse, DataSchemaRegistry, DataSourceDiagnostic, DataSourceDiagnosticResult, EndpointId, OperationId, RestDataSourceConfig } from '@ankhorage/contracts/data';
2
+ declare const REST_METHODS: readonly ["DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT"];
3
+ export type ManualRestMethod = (typeof REST_METHODS)[number];
4
+ export interface ManualRestOperationDefinition {
5
+ readonly id: OperationId;
6
+ readonly intent: DataOperationIntent;
7
+ readonly method: string;
8
+ readonly name?: string;
9
+ readonly description?: string;
10
+ readonly path?: string;
11
+ readonly credential?: CredentialRef;
12
+ readonly parameters?: readonly DataOperationParameter[];
13
+ readonly request?: DataOperationRequest;
14
+ readonly response?: DataOperationResponse;
15
+ readonly pagination?: DataOperationPagination;
16
+ readonly metadata?: DataContractValue;
17
+ }
18
+ export interface ManualRestEndpointDefinition {
19
+ readonly id: EndpointId;
20
+ readonly path: string;
21
+ readonly name?: string;
22
+ readonly description?: string;
23
+ readonly credential?: CredentialRef;
24
+ readonly operations: readonly ManualRestOperationDefinition[];
25
+ readonly metadata?: DataContractValue;
26
+ }
27
+ export interface ManualRestDataSourceDefinition {
28
+ readonly id: string;
29
+ readonly baseUrl: string;
30
+ readonly name?: string;
31
+ readonly description?: string;
32
+ readonly credential?: CredentialRef;
33
+ readonly endpoints: readonly ManualRestEndpointDefinition[];
34
+ readonly schemas?: DataSchemaRegistry;
35
+ readonly metadata?: DataContractValue;
36
+ }
37
+ export declare function isManualRestMethod(method: string): method is ManualRestMethod;
38
+ export declare function normalizeManualRestMethod(method: string): DataOperationMethod;
39
+ export declare function extractRestPathParams(path: string): readonly string[];
40
+ export declare function validateManualRestDataSource(definition: ManualRestDataSourceDefinition): readonly DataSourceDiagnostic[];
41
+ export declare function createManualRestDataSource(definition: ManualRestDataSourceDefinition): DataSourceDiagnosticResult<RestDataSourceConfig>;
42
+ export declare function normalizeManualRestDataSource(definition: ManualRestDataSourceDefinition): RestDataSourceConfig;
43
+ export {};
44
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/rest/index.ts"],"names":[],"mappings":"AAAA,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