@ankhorage/data-sources 1.0.0 → 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.
- package/CHANGELOG.md +12 -0
- package/README.md +6 -41
- package/dist/ankh.provider.js +1 -1
- package/dist/ankh.provider.js.map +1 -1
- package/dist/discovery/http.d.ts +10 -0
- package/dist/discovery/http.d.ts.map +1 -0
- package/dist/discovery/http.js +35 -0
- package/dist/discovery/http.js.map +1 -0
- package/dist/discovery/index.d.ts +9 -9
- package/dist/discovery/index.d.ts.map +1 -1
- package/dist/discovery/index.js +27 -55
- package/dist/discovery/index.js.map +1 -1
- package/dist/graphql/index.d.ts +8 -76
- package/dist/graphql/index.d.ts.map +1 -1
- package/dist/graphql/index.js +17 -197
- package/dist/graphql/index.js.map +1 -1
- package/dist/graphql/introspection.d.ts +5 -0
- package/dist/graphql/introspection.d.ts.map +1 -0
- package/dist/graphql/introspection.js +136 -0
- package/dist/graphql/introspection.js.map +1 -0
- package/dist/graphql/operation.d.ts +5 -0
- package/dist/graphql/operation.d.ts.map +1 -0
- package/dist/graphql/operation.js +39 -0
- package/dist/graphql/operation.js.map +1 -0
- package/dist/graphql/types.d.ts +71 -0
- package/dist/graphql/types.d.ts.map +1 -0
- package/dist/graphql/types.js +2 -0
- package/dist/graphql/types.js.map +1 -0
- package/dist/index.d.ts +1 -17
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -34
- package/dist/index.js.map +1 -1
- package/dist/openapi/endpoints.d.ts +5 -0
- package/dist/openapi/endpoints.d.ts.map +1 -0
- package/dist/openapi/endpoints.js +77 -0
- package/dist/openapi/endpoints.js.map +1 -0
- package/dist/openapi/index.d.ts +7 -87
- package/dist/openapi/index.d.ts.map +1 -1
- package/dist/openapi/index.js +8 -267
- package/dist/openapi/index.js.map +1 -1
- package/dist/openapi/operation.d.ts +5 -0
- package/dist/openapi/operation.d.ts.map +1 -0
- package/dist/openapi/operation.js +141 -0
- package/dist/openapi/operation.js.map +1 -0
- package/dist/openapi/schema.d.ts +5 -0
- package/dist/openapi/schema.d.ts.map +1 -0
- package/dist/openapi/schema.js +84 -0
- package/dist/openapi/schema.js.map +1 -0
- package/dist/openapi/types.d.ts +82 -0
- package/dist/openapi/types.d.ts.map +1 -0
- package/dist/openapi/types.js +2 -0
- package/dist/openapi/types.js.map +1 -0
- package/dist/packageInfo.d.ts +18 -0
- package/dist/packageInfo.d.ts.map +1 -0
- package/dist/packageInfo.js +30 -0
- package/dist/packageInfo.js.map +1 -0
- package/dist/rest/index.d.ts +5 -5
- package/dist/rest/index.d.ts.map +1 -1
- package/dist/rest/index.js +49 -48
- package/dist/rest/index.js.map +1 -1
- package/dist/test-runner/index.d.ts +2 -57
- package/dist/test-runner/index.d.ts.map +1 -1
- package/dist/test-runner/index.js +58 -160
- package/dist/test-runner/index.js.map +1 -1
- package/dist/test-runner/response.d.ts +3 -0
- package/dist/test-runner/response.d.ts.map +1 -0
- package/dist/test-runner/response.js +29 -0
- package/dist/test-runner/response.js.map +1 -0
- package/dist/test-runner/result.d.ts +6 -0
- package/dist/test-runner/result.d.ts.map +1 -0
- package/dist/test-runner/result.js +17 -0
- package/dist/test-runner/result.js.map +1 -0
- package/dist/test-runner/serialization.d.ts +12 -0
- package/dist/test-runner/serialization.d.ts.map +1 -0
- package/dist/test-runner/serialization.js +99 -0
- package/dist/test-runner/serialization.js.map +1 -0
- package/dist/test-runner/types.d.ts +58 -0
- package/dist/test-runner/types.d.ts.map +1 -0
- package/dist/test-runner/types.js +2 -0
- package/dist/test-runner/types.js.map +1 -0
- package/package.json +5 -5
- package/src/ankh.provider.ts +1 -1
- package/src/api-phase1.contract.test.ts +24 -0
- package/src/discovery/http.ts +38 -0
- package/src/discovery/index.test.ts +76 -75
- package/src/discovery/index.ts +49 -72
- package/src/graphql/index.test.ts +10 -11
- package/src/graphql/index.ts +35 -315
- package/src/graphql/introspection.ts +163 -0
- package/src/graphql/operation.ts +60 -0
- package/src/graphql/types.ts +79 -0
- package/src/index.test.ts +21 -13
- package/src/index.ts +1 -54
- package/src/openapi/endpoints.ts +124 -0
- package/src/openapi/index.test.ts +47 -47
- package/src/openapi/index.ts +12 -467
- package/src/openapi/operation.ts +231 -0
- package/src/openapi/schema.ts +127 -0
- package/src/openapi/types.ts +93 -0
- package/src/packageInfo.ts +50 -0
- package/src/rest/index.test.ts +17 -14
- package/src/rest/index.ts +67 -61
- package/src/test-runner/index.test.ts +153 -120
- package/src/test-runner/index.ts +97 -299
- package/src/test-runner/response.ts +32 -0
- package/src/test-runner/result.ts +35 -0
- package/src/test-runner/serialization.ts +151 -0
- package/src/test-runner/types.ts +81 -0
- package/dist/generated-api/index.d.ts +0 -10
- package/dist/generated-api/index.d.ts.map +0 -1
- package/dist/generated-api/index.js +0 -272
- package/dist/generated-api/index.js.map +0 -1
- package/src/generated-api/index.test.ts +0 -173
- package/src/generated-api/index.ts +0 -410
|
@@ -1 +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,KAA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,CAAC;IACpF,OAAO,IAAI,CAAC,MAAM,CAAC,qBAAqB,CAAC,CAAC;AAC5C,CAAC;AAED,SAAS,qBAAqB,CAAC,IAAY;IACzC,OAAO,sBAAsB,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,KAAK,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;IACD,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 ExternalRestApiDataSourceConfig,\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<ExternalRestApiDataSourceConfig>;\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\n if (baseUrl === undefined || diagnostics.some((diagnostic) => diagnostic.severity === 'error')) {\n return { ok: false, diagnostics };\n }\n\n return {\n ok: true,\n data: {\n id: input.id,\n kind: 'api',\n origin: 'external',\n protocol: 'rest',\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 openApi: {\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 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 return normalized.length > 0 ? normalized : 'root';\n}\n\nexport function normalizeOpenApiSchema(schema: OpenApiSchemaObject): DataSchema {\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: normalizeAdditionalProperties(schema.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 && input.baseUrl.trim().length > 0) return input.baseUrl;\n\n const servers = input.document.servers ?? [];\n if (servers.length === 0) {\n diagnostics.push({\n code: 'ambiguous-server',\n dataSourceId: input.id,\n message: 'OpenAPI import requires a server URL or an explicit baseUrl override.',\n path: 'servers',\n severity: 'error',\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 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 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 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\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: normalizeOpenApiRequest(operation.requestBody, parameters),\n response: normalizeOpenApiResponse(operation.responses),\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 if (!operationIds.has(normalized)) {\n operationIds.add(normalized);\n return normalized;\n }\n\n let suffix = 2;\n let uniqueId: OperationId = `${normalized}-${suffix}`;\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 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 const normalized: DataOperationParameter[] = [];\n\n for (const parameter of parameters) {\n const location = normalizeParameterLocation(parameter.in);\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 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 if (requestBody === undefined && parameters === undefined) return undefined;\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 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 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 const [entry] = Object.entries(content);\n if (entry === undefined) return undefined;\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 const prefix = '#/components/schemas/';\n return { id: ref.startsWith(prefix) ? ref.slice(prefix.length) : 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 return Object.fromEntries(\n Object.entries(record).map(([key, schema]) => [key, normalizeOpenApiSchema(schema)]),\n );\n}\n\nfunction normalizeSchemaList(\n list: readonly OpenApiSchemaObject[] | undefined,\n): readonly DataSchema[] | undefined {\n return list?.map(normalizeOpenApiSchema);\n}\n\nfunction normalizeAdditionalProperties(\n value: boolean | OpenApiSchemaObject | undefined,\n): boolean | DataSchema | undefined {\n if (value === undefined || typeof value === 'boolean') return value;\n return normalizeOpenApiSchema(value);\n}\n\nfunction normalizeSchemaType(\n type: string | readonly string[] | undefined,\n): DataSchemaPrimitiveType | readonly DataSchemaPrimitiveType[] | undefined {\n if (type === undefined) return undefined;\n if (typeof type === 'string') return isDataSchemaPrimitive(type) ? type : undefined;\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 if (schema.items !== undefined) {\n collectUnsupportedSchemaDiagnostics(schema.items, dataSourceId, `${path}.items`, diagnostics);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/openapi/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,uBAAuB,EAAE,M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,QAAQ,CAAC,IAAI,EAAE,OAAO;aACtC;YACD,QAAQ,EAAE,KAAK,CAAC,QAAQ;SACzB;QACD,WAAW;KACZ,CAAC;AACJ,CAAC;AAED,SAAS,qBAAqB,CAC5B,KAAyB,EACzB,WAAmC;IAEnC,IAAI,KAAK,CAAC,OAAO,KAAK,SAAS,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,KAAK,CAAC,OAAO,CAAC;IAEzF,MAAM,OAAO,GAAG,KAAK,CAAC,QAAQ,CAAC,OAAO,IAAI,EAAE,CAAC;IAC7C,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,WAAW,CAAC,IAAI,CAAC;YACf,IAAI,EAAE,kBAAkB;YACxB,KAAK,EAAE,KAAK,CAAC,EAAE;YACf,OAAO,EAAE,uEAAuE;YAChF,IAAI,EAAE,SAAS;YACf,QAAQ,EAAE,OAAO;SAClB,CAAC,CAAC;QACH,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACvB,WAAW,CAAC,IAAI,CAAC;YACf,IAAI,EAAE,kBAAkB;YACxB,KAAK,EAAE,KAAK,CAAC,EAAE;YACf,OAAO,EAAE,+EAA+E;YACxF,IAAI,EAAE,SAAS;YACf,QAAQ,EAAE,SAAS;SACpB,CAAC,CAAC;IACL,CAAC;IACD,OAAO,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC;AACzB,CAAC","sourcesContent":["import type {\n DataSourceDiagnostic,\n DataSourceDiagnosticResult,\n ExternalRestApiDefinition,\n} from '@ankhorage/contracts/data';\n\nimport { normalizeOpenApiEndpoints } from './endpoints';\nimport { normalizeOpenApiSchemas } from './schema';\nimport type { OpenApiImportInput } from './types';\n\nexport { normalizeOpenApiEndpointId } from './endpoints';\nexport { normalizeOpenApiOperationId } from './operation';\nexport { normalizeOpenApiSchema } from './schema';\nexport type * from './types';\n\nexport type OpenApiImportResult = DataSourceDiagnosticResult<ExternalRestApiDefinition>;\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, diagnostics);\n\n if (baseUrl === undefined || diagnostics.some((diagnostic) => diagnostic.severity === 'error')) {\n return { ok: false, diagnostics };\n }\n\n return {\n ok: true,\n data: {\n id: input.id,\n origin: 'external',\n protocol: 'rest',\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 openApi: {\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\nfunction resolveOpenApiBaseUrl(\n input: OpenApiImportInput,\n diagnostics: DataSourceDiagnostic[],\n): string | undefined {\n if (input.baseUrl !== undefined && input.baseUrl.trim().length > 0) return input.baseUrl;\n\n const servers = input.document.servers ?? [];\n if (servers.length === 0) {\n diagnostics.push({\n code: 'ambiguous-server',\n apiId: input.id,\n message: 'OpenAPI import requires a server URL or an explicit baseUrl override.',\n path: 'servers',\n severity: 'error',\n });\n return undefined;\n }\n\n if (servers.length > 1) {\n diagnostics.push({\n code: 'ambiguous-server',\n apiId: input.id,\n message: 'OpenAPI document defines multiple servers. The first server URL was selected.',\n path: 'servers',\n severity: 'warning',\n });\n }\n return servers[0]?.url;\n}\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { DataOperationConfig, DataSourceDiagnostic, EndpointId, OperationId } from '@ankhorage/contracts/data';
|
|
2
|
+
import type { OpenApiHttpMethod, OpenApiImportInput, OpenApiOperationObject, OpenApiPathItemObject } from './types';
|
|
3
|
+
export declare function normalizeOpenApiOperationId(method: OpenApiHttpMethod, path: string, operationId?: string): OperationId;
|
|
4
|
+
export declare function normalizeOpenApiOperation(input: OpenApiImportInput, endpointId: EndpointId, path: string, method: OpenApiHttpMethod, operation: OpenApiOperationObject, pathItem: OpenApiPathItemObject, operationIds: Set<OperationId>, diagnostics: DataSourceDiagnostic[]): DataOperationConfig;
|
|
5
|
+
//# sourceMappingURL=operation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operation.d.ts","sourceRoot":"","sources":["../../src/openapi/operation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EAMnB,oBAAoB,EACpB,UAAU,EACV,WAAW,EACZ,MAAM,2BAA2B,CAAC;AAGnC,OAAO,KAAK,EACV,iBAAiB,EACjB,kBAAkB,EAElB,sBAAsB,EAEtB,qBAAqB,EAItB,MAAM,SAAS,CAAC;AAEjB,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,iBAAiB,EACzB,IAAI,EAAE,MAAM,EACZ,WAAW,CAAC,EAAE,MAAM,GACnB,WAAW,CAQb;AAED,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,kBAAkB,EACzB,UAAU,EAAE,UAAU,EACtB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,iBAAiB,EACzB,SAAS,EAAE,sBAAsB,EACjC,QAAQ,EAAE,qBAAqB,EAC/B,YAAY,EAAE,GAAG,CAAC,WAAW,CAAC,EAC9B,WAAW,EAAE,oBAAoB,EAAE,GAClC,mBAAmB,CA8BrB"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { normalizeOpenApiSchema } from './schema';
|
|
2
|
+
export function normalizeOpenApiOperationId(method, path, operationId) {
|
|
3
|
+
const rawId = operationId ?? `${method}-${path}`;
|
|
4
|
+
const normalized = rawId
|
|
5
|
+
.replace(/\{([^}]+)\}/g, '$1')
|
|
6
|
+
.replace(/[^A-Za-z0-9]+/g, '-')
|
|
7
|
+
.replace(/^-+|-+$/g, '')
|
|
8
|
+
.toLowerCase();
|
|
9
|
+
return normalized.length > 0 ? normalized : `${method}-root`;
|
|
10
|
+
}
|
|
11
|
+
export function normalizeOpenApiOperation(input, endpointId, path, method, operation, pathItem, operationIds, diagnostics) {
|
|
12
|
+
const operationId = resolveUniqueOperationId(input.id, endpointId, method, path, operation.operationId, operationIds, diagnostics);
|
|
13
|
+
const parameters = normalizeOpenApiParameters([...(pathItem.parameters ?? []), ...(operation.parameters ?? [])], input.id, endpointId, operationId, diagnostics);
|
|
14
|
+
return {
|
|
15
|
+
id: operationId,
|
|
16
|
+
endpointId,
|
|
17
|
+
name: operation.summary,
|
|
18
|
+
description: operation.description,
|
|
19
|
+
protocol: 'http',
|
|
20
|
+
intent: mapOpenApiMethodToIntent(method),
|
|
21
|
+
method: method.toUpperCase(),
|
|
22
|
+
path,
|
|
23
|
+
request: normalizeOpenApiRequest(operation.requestBody, parameters),
|
|
24
|
+
response: normalizeOpenApiResponse(operation.responses),
|
|
25
|
+
metadata: { deprecated: operation.deprecated ?? false, source: 'openapi' },
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function resolveUniqueOperationId(apiId, endpointId, method, path, operationId, operationIds, diagnostics) {
|
|
29
|
+
const normalized = normalizeOpenApiOperationId(method, path, operationId);
|
|
30
|
+
if (!operationIds.has(normalized)) {
|
|
31
|
+
operationIds.add(normalized);
|
|
32
|
+
return normalized;
|
|
33
|
+
}
|
|
34
|
+
const uniqueId = findUniqueOperationId(normalized, operationIds);
|
|
35
|
+
operationIds.add(uniqueId);
|
|
36
|
+
diagnostics.push({
|
|
37
|
+
code: 'duplicate-operation-id',
|
|
38
|
+
apiId,
|
|
39
|
+
endpointId,
|
|
40
|
+
operationId: uniqueId,
|
|
41
|
+
message: `OpenAPI operation id '${normalized}' is duplicated. Normalized to '${uniqueId}'.`,
|
|
42
|
+
path: `paths.${path}.${method}.operationId`,
|
|
43
|
+
severity: 'warning',
|
|
44
|
+
});
|
|
45
|
+
return uniqueId;
|
|
46
|
+
}
|
|
47
|
+
function findUniqueOperationId(normalized, operationIds) {
|
|
48
|
+
let suffix = 2;
|
|
49
|
+
let candidate = `${normalized}-${suffix}`;
|
|
50
|
+
while (operationIds.has(candidate)) {
|
|
51
|
+
suffix += 1;
|
|
52
|
+
candidate = `${normalized}-${suffix}`;
|
|
53
|
+
}
|
|
54
|
+
return candidate;
|
|
55
|
+
}
|
|
56
|
+
function normalizeOpenApiParameters(parameters, apiId, endpointId, operationId, diagnostics) {
|
|
57
|
+
if (parameters.length === 0)
|
|
58
|
+
return undefined;
|
|
59
|
+
return parameters.flatMap((parameter) => normalizeOpenApiParameter(parameter, apiId, endpointId, operationId, diagnostics));
|
|
60
|
+
}
|
|
61
|
+
function normalizeOpenApiParameter(parameter, apiId, endpointId, operationId, diagnostics) {
|
|
62
|
+
const location = normalizeParameterLocation(parameter.in);
|
|
63
|
+
if (location !== undefined) {
|
|
64
|
+
return [
|
|
65
|
+
{
|
|
66
|
+
name: parameter.name,
|
|
67
|
+
location,
|
|
68
|
+
required: parameter.required,
|
|
69
|
+
description: parameter.description,
|
|
70
|
+
schema: parameter.schema === undefined ? undefined : normalizeOpenApiSchema(parameter.schema),
|
|
71
|
+
},
|
|
72
|
+
];
|
|
73
|
+
}
|
|
74
|
+
diagnostics.push({
|
|
75
|
+
code: 'invalid-config',
|
|
76
|
+
apiId,
|
|
77
|
+
endpointId,
|
|
78
|
+
operationId,
|
|
79
|
+
message: `OpenAPI parameter '${parameter.name}' uses unsupported location '${parameter.in}'.`,
|
|
80
|
+
path: `paths.${endpointId}.parameters.${parameter.name}`,
|
|
81
|
+
severity: 'warning',
|
|
82
|
+
});
|
|
83
|
+
return [];
|
|
84
|
+
}
|
|
85
|
+
function normalizeParameterLocation(location) {
|
|
86
|
+
if (location === 'cookie' ||
|
|
87
|
+
location === 'header' ||
|
|
88
|
+
location === 'path' ||
|
|
89
|
+
location === 'query') {
|
|
90
|
+
return location;
|
|
91
|
+
}
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
function normalizeOpenApiRequest(requestBody, parameters) {
|
|
95
|
+
const content = firstContentEntry(requestBody?.content);
|
|
96
|
+
if (requestBody === undefined && parameters === undefined)
|
|
97
|
+
return undefined;
|
|
98
|
+
return {
|
|
99
|
+
contentType: content?.contentType,
|
|
100
|
+
parameters,
|
|
101
|
+
schema: content?.schema === undefined ? undefined : normalizeOpenApiSchema(content.schema),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
function normalizeOpenApiResponse(responses) {
|
|
105
|
+
const selected = chooseResponseEntry(responses);
|
|
106
|
+
if (selected === undefined)
|
|
107
|
+
return undefined;
|
|
108
|
+
const [status, response] = selected;
|
|
109
|
+
const content = firstContentEntry(response.content);
|
|
110
|
+
return {
|
|
111
|
+
status,
|
|
112
|
+
contentType: content?.contentType,
|
|
113
|
+
description: response.description,
|
|
114
|
+
schema: content?.schema === undefined ? undefined : normalizeOpenApiSchema(content.schema),
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
function chooseResponseEntry(responses) {
|
|
118
|
+
if (responses === undefined)
|
|
119
|
+
return undefined;
|
|
120
|
+
const entries = Object.entries(responses);
|
|
121
|
+
return entries.find(([status]) => status.startsWith('2')) ?? entries[0];
|
|
122
|
+
}
|
|
123
|
+
function firstContentEntry(content) {
|
|
124
|
+
const entry = content === undefined ? undefined : Object.entries(content)[0];
|
|
125
|
+
if (entry === undefined)
|
|
126
|
+
return undefined;
|
|
127
|
+
const [contentType, media] = entry;
|
|
128
|
+
return { contentType, schema: media.schema };
|
|
129
|
+
}
|
|
130
|
+
function mapOpenApiMethodToIntent(method) {
|
|
131
|
+
if (method === 'get' || method === 'head')
|
|
132
|
+
return 'read';
|
|
133
|
+
if (method === 'post')
|
|
134
|
+
return 'create';
|
|
135
|
+
if (method === 'delete')
|
|
136
|
+
return 'delete';
|
|
137
|
+
if (method === 'patch' || method === 'put')
|
|
138
|
+
return 'update';
|
|
139
|
+
return 'action';
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=operation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operation.js","sourceRoot":"","sources":["../../src/openapi/operation.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAalD,MAAM,UAAU,2BAA2B,CACzC,MAAyB,EACzB,IAAY,EACZ,WAAoB;IAEpB,MAAM,KAAK,GAAG,WAAW,IAAI,GAAG,MAAM,IAAI,IAAI,EAAE,CAAC;IACjD,MAAM,UAAU,GAAG,KAAK;SACrB,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,GAAG,MAAM,OAAO,CAAC;AAC/D,CAAC;AAED,MAAM,UAAU,yBAAyB,CACvC,KAAyB,EACzB,UAAsB,EACtB,IAAY,EACZ,MAAyB,EACzB,SAAiC,EACjC,QAA+B,EAC/B,YAA8B,EAC9B,WAAmC;IAEnC,MAAM,WAAW,GAAG,wBAAwB,CAC1C,KAAK,CAAC,EAAE,EACR,UAAU,EACV,MAAM,EACN,IAAI,EACJ,SAAS,CAAC,WAAW,EACrB,YAAY,EACZ,WAAW,CACZ,CAAC;IACF,MAAM,UAAU,GAAG,0BAA0B,CAC3C,CAAC,GAAG,CAAC,QAAQ,CAAC,UAAU,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,SAAS,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC,EACjE,KAAK,CAAC,EAAE,EACR,UAAU,EACV,WAAW,EACX,WAAW,CACZ,CAAC;IACF,OAAO;QACL,EAAE,EAAE,WAAW;QACf,UAAU;QACV,IAAI,EAAE,SAAS,CAAC,OAAO;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,SAAS,CAAC,CAAC,CAAC,sBAAsB,CAAC,OAAO,CAAC,MAAM,CAAC;KAC3F,CAAC;AACJ,CAAC;AAED,SAAS,mBAAmB,CAC1B,SAAsE;IAEtE,IAAI,SAAS,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC9C,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAC1C,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC;AAC1E,CAAC;AAED,SAAS,iBAAiB,CACxB,OAAqE;IAErE,MAAM,KAAK,GAAG,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7E,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC1C,MAAM,CAAC,WAAW,EAAE,KAAK,CAAC,GAAG,KAAK,CAAC;IACnC,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC;AAC/C,CAAC;AAED,SAAS,wBAAwB,CAAC,MAAyB;IACzD,IAAI,MAAM,KAAK,KAAK,IAAI,MAAM,KAAK,MAAM;QAAE,OAAO,MAAM,CAAC;IACzD,IAAI,MAAM,KAAK,MAAM;QAAE,OAAO,QAAQ,CAAC;IACvC,IAAI,MAAM,KAAK,QAAQ;QAAE,OAAO,QAAQ,CAAC;IACzC,IAAI,MAAM,KAAK,OAAO,IAAI,MAAM,KAAK,KAAK;QAAE,OAAO,QAAQ,CAAC;IAC5D,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["import type {\n DataOperationConfig,\n DataOperationIntent,\n DataOperationParameter,\n DataOperationParameterLocation,\n DataOperationRequest,\n DataOperationResponse,\n DataSourceDiagnostic,\n EndpointId,\n OperationId,\n} from '@ankhorage/contracts/data';\n\nimport { normalizeOpenApiSchema } from './schema';\nimport type {\n OpenApiHttpMethod,\n OpenApiImportInput,\n OpenApiMediaTypeObject,\n OpenApiOperationObject,\n OpenApiParameterObject,\n OpenApiPathItemObject,\n OpenApiRequestBodyObject,\n OpenApiResponseObject,\n OpenApiSchemaObject,\n} from './types';\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 return normalized.length > 0 ? normalized : `${method}-root`;\n}\n\nexport function normalizeOpenApiOperation(\n input: OpenApiImportInput,\n endpointId: EndpointId,\n path: string,\n method: OpenApiHttpMethod,\n operation: OpenApiOperationObject,\n pathItem: OpenApiPathItemObject,\n operationIds: Set<OperationId>,\n diagnostics: DataSourceDiagnostic[],\n): DataOperationConfig {\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 return {\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: normalizeOpenApiRequest(operation.requestBody, parameters),\n response: normalizeOpenApiResponse(operation.responses),\n metadata: { deprecated: operation.deprecated ?? false, source: 'openapi' },\n };\n}\n\nfunction resolveUniqueOperationId(\n apiId: 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 if (!operationIds.has(normalized)) {\n operationIds.add(normalized);\n return normalized;\n }\n\n const uniqueId = findUniqueOperationId(normalized, operationIds);\n operationIds.add(uniqueId);\n diagnostics.push({\n code: 'duplicate-operation-id',\n apiId,\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 return uniqueId;\n}\n\nfunction findUniqueOperationId(\n normalized: OperationId,\n operationIds: Set<OperationId>,\n): OperationId {\n let suffix = 2;\n let candidate: OperationId = `${normalized}-${suffix}`;\n while (operationIds.has(candidate)) {\n suffix += 1;\n candidate = `${normalized}-${suffix}`;\n }\n return candidate;\n}\n\nfunction normalizeOpenApiParameters(\n parameters: readonly OpenApiParameterObject[],\n apiId: string,\n endpointId: EndpointId,\n operationId: OperationId,\n diagnostics: DataSourceDiagnostic[],\n): readonly DataOperationParameter[] | undefined {\n if (parameters.length === 0) return undefined;\n return parameters.flatMap((parameter) =>\n normalizeOpenApiParameter(parameter, apiId, endpointId, operationId, diagnostics),\n );\n}\n\nfunction normalizeOpenApiParameter(\n parameter: OpenApiParameterObject,\n apiId: string,\n endpointId: EndpointId,\n operationId: OperationId,\n diagnostics: DataSourceDiagnostic[],\n): readonly DataOperationParameter[] {\n const location = normalizeParameterLocation(parameter.in);\n if (location !== undefined) {\n return [\n {\n name: parameter.name,\n location,\n required: parameter.required,\n description: parameter.description,\n schema:\n parameter.schema === undefined ? undefined : normalizeOpenApiSchema(parameter.schema),\n },\n ];\n }\n diagnostics.push({\n code: 'invalid-config',\n apiId,\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 return [];\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 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 if (requestBody === undefined && parameters === undefined) return undefined;\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 const selected = chooseResponseEntry(responses);\n if (selected === undefined) return undefined;\n const [status, response] = selected;\n const content = firstContentEntry(response.content);\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 chooseResponseEntry(\n responses: Readonly<Record<string, OpenApiResponseObject>> | undefined,\n): readonly [string, OpenApiResponseObject] | undefined {\n if (responses === undefined) return undefined;\n const entries = Object.entries(responses);\n return entries.find(([status]) => status.startsWith('2')) ?? entries[0];\n}\n\nfunction firstContentEntry(\n content: Readonly<Record<string, OpenApiMediaTypeObject>> | undefined,\n): { readonly contentType: string; readonly schema?: OpenApiSchemaObject } | undefined {\n const entry = content === undefined ? undefined : Object.entries(content)[0];\n if (entry === undefined) return undefined;\n const [contentType, media] = entry;\n return { contentType, schema: media.schema };\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"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { DataSchema, DataSchemaRegistry, DataSourceDiagnostic } from '@ankhorage/contracts/data';
|
|
2
|
+
import type { OpenApiSchemaObject } from './types';
|
|
3
|
+
export declare function normalizeOpenApiSchema(schema: OpenApiSchemaObject): DataSchema;
|
|
4
|
+
export declare function normalizeOpenApiSchemas(schemas: Readonly<Record<string, OpenApiSchemaObject>> | undefined, apiId: string, diagnostics: DataSourceDiagnostic[]): DataSchemaRegistry | undefined;
|
|
5
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/openapi/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EAEV,kBAAkB,EAClB,oBAAoB,EACrB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAYnD,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,mBAAmB,GAAG,UAAU,CAmB9E;AAED,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC,GAAG,SAAS,EAClE,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,oBAAoB,EAAE,GAClC,kBAAkB,GAAG,SAAS,CAahC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
const DATA_SCHEMA_PRIMITIVES = [
|
|
2
|
+
'array',
|
|
3
|
+
'boolean',
|
|
4
|
+
'integer',
|
|
5
|
+
'null',
|
|
6
|
+
'number',
|
|
7
|
+
'object',
|
|
8
|
+
'string',
|
|
9
|
+
];
|
|
10
|
+
export function normalizeOpenApiSchema(schema) {
|
|
11
|
+
return {
|
|
12
|
+
ref: normalizeOpenApiSchemaRef(schema.$ref),
|
|
13
|
+
type: normalizeSchemaType(schema.type),
|
|
14
|
+
title: schema.title,
|
|
15
|
+
description: schema.description,
|
|
16
|
+
enum: schema.enum,
|
|
17
|
+
const: schema.const,
|
|
18
|
+
default: schema.default,
|
|
19
|
+
format: schema.format,
|
|
20
|
+
nullable: schema.nullable,
|
|
21
|
+
required: schema.required,
|
|
22
|
+
properties: normalizeSchemaRecord(schema.properties),
|
|
23
|
+
additionalProperties: normalizeAdditionalProperties(schema.additionalProperties),
|
|
24
|
+
items: schema.items === undefined ? undefined : normalizeOpenApiSchema(schema.items),
|
|
25
|
+
allOf: normalizeSchemaList(schema.allOf),
|
|
26
|
+
anyOf: normalizeSchemaList(schema.anyOf),
|
|
27
|
+
oneOf: normalizeSchemaList(schema.oneOf),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export function normalizeOpenApiSchemas(schemas, apiId, diagnostics) {
|
|
31
|
+
if (schemas === undefined)
|
|
32
|
+
return undefined;
|
|
33
|
+
return Object.fromEntries(Object.entries(schemas).map(([schemaId, schema]) => {
|
|
34
|
+
collectUnsupportedSchemaDiagnostics(schema, apiId, `components.schemas.${schemaId}`, diagnostics);
|
|
35
|
+
return [schemaId, normalizeOpenApiSchema(schema)];
|
|
36
|
+
}));
|
|
37
|
+
}
|
|
38
|
+
function normalizeOpenApiSchemaRef(ref) {
|
|
39
|
+
if (ref === undefined)
|
|
40
|
+
return undefined;
|
|
41
|
+
const prefix = '#/components/schemas/';
|
|
42
|
+
return { id: ref.startsWith(prefix) ? ref.slice(prefix.length) : ref };
|
|
43
|
+
}
|
|
44
|
+
function normalizeSchemaRecord(record) {
|
|
45
|
+
if (record === undefined)
|
|
46
|
+
return undefined;
|
|
47
|
+
return Object.fromEntries(Object.entries(record).map(([key, schema]) => [key, normalizeOpenApiSchema(schema)]));
|
|
48
|
+
}
|
|
49
|
+
function normalizeSchemaList(list) {
|
|
50
|
+
return list?.map(normalizeOpenApiSchema);
|
|
51
|
+
}
|
|
52
|
+
function normalizeAdditionalProperties(value) {
|
|
53
|
+
if (value === undefined || typeof value === 'boolean')
|
|
54
|
+
return value;
|
|
55
|
+
return normalizeOpenApiSchema(value);
|
|
56
|
+
}
|
|
57
|
+
function normalizeSchemaType(type) {
|
|
58
|
+
if (type === undefined)
|
|
59
|
+
return undefined;
|
|
60
|
+
if (typeof type === 'string')
|
|
61
|
+
return isDataSchemaPrimitive(type) ? type : undefined;
|
|
62
|
+
return type.filter(isDataSchemaPrimitive);
|
|
63
|
+
}
|
|
64
|
+
function isDataSchemaPrimitive(type) {
|
|
65
|
+
return DATA_SCHEMA_PRIMITIVES.some((primitive) => primitive === type);
|
|
66
|
+
}
|
|
67
|
+
function collectUnsupportedSchemaDiagnostics(schema, apiId, path, diagnostics) {
|
|
68
|
+
if (typeof schema.type === 'string' && !isDataSchemaPrimitive(schema.type)) {
|
|
69
|
+
diagnostics.push({
|
|
70
|
+
code: 'unsupported-schema',
|
|
71
|
+
apiId,
|
|
72
|
+
message: `OpenAPI schema type '${schema.type}' is not supported by the normalized schema model.`,
|
|
73
|
+
path: `${path}.type`,
|
|
74
|
+
severity: 'warning',
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
for (const [propertyName, propertySchema] of Object.entries(schema.properties ?? {})) {
|
|
78
|
+
collectUnsupportedSchemaDiagnostics(propertySchema, apiId, `${path}.properties.${propertyName}`, diagnostics);
|
|
79
|
+
}
|
|
80
|
+
if (schema.items !== undefined) {
|
|
81
|
+
collectUnsupportedSchemaDiagnostics(schema.items, apiId, `${path}.items`, diagnostics);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/openapi/schema.ts"],"names":[],"mappings":"AASA,MAAM,sBAAsB,GAAG;IAC7B,OAAO;IACP,SAAS;IACT,SAAS;IACT,MAAM;IACN,QAAQ;IACR,QAAQ;IACR,QAAQ;CAC6C,CAAC;AAExD,MAAM,UAAU,sBAAsB,CAAC,MAA2B;IAChE,OAAO;QACL,GAAG,EAAE,yBAAyB,CAAC,MAAM,CAAC,IAAI,CAAC;QAC3C,IAAI,EAAE,mBAAmB,CAAC,MAAM,CAAC,IAAI,CAAC;QACtC,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,WAAW,EAAE,MA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;AAED,SAAS,mCAAmC,CAC1C,MAA2B,EAC3B,KAAa,EACb,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,KAAK;YACL,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,KAAK,EACL,GAAG,IAAI,eAAe,YAAY,EAAE,EACpC,WAAW,CACZ,CAAC;IACJ,CAAC;IACD,IAAI,MAAM,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;QAC/B,mCAAmC,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,IAAI,QAAQ,EAAE,WAAW,CAAC,CAAC;IACzF,CAAC;AACH,CAAC","sourcesContent":["import type {\n DataSchema,\n DataSchemaPrimitiveType,\n DataSchemaRegistry,\n DataSourceDiagnostic,\n} from '@ankhorage/contracts/data';\n\nimport type { OpenApiSchemaObject } from './types';\n\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 function normalizeOpenApiSchema(schema: OpenApiSchemaObject): DataSchema {\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: normalizeAdditionalProperties(schema.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\nexport function normalizeOpenApiSchemas(\n schemas: Readonly<Record<string, OpenApiSchemaObject>> | undefined,\n apiId: string,\n diagnostics: DataSourceDiagnostic[],\n): DataSchemaRegistry | undefined {\n if (schemas === undefined) return undefined;\n return Object.fromEntries(\n Object.entries(schemas).map(([schemaId, schema]) => {\n collectUnsupportedSchemaDiagnostics(\n schema,\n apiId,\n `components.schemas.${schemaId}`,\n diagnostics,\n );\n return [schemaId, normalizeOpenApiSchema(schema)];\n }),\n );\n}\n\nfunction normalizeOpenApiSchemaRef(ref: string | undefined): { readonly id: string } | undefined {\n if (ref === undefined) return undefined;\n const prefix = '#/components/schemas/';\n return { id: ref.startsWith(prefix) ? ref.slice(prefix.length) : 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 return Object.fromEntries(\n Object.entries(record).map(([key, schema]) => [key, normalizeOpenApiSchema(schema)]),\n );\n}\n\nfunction normalizeSchemaList(\n list: readonly OpenApiSchemaObject[] | undefined,\n): readonly DataSchema[] | undefined {\n return list?.map(normalizeOpenApiSchema);\n}\n\nfunction normalizeAdditionalProperties(\n value: boolean | OpenApiSchemaObject | undefined,\n): boolean | DataSchema | undefined {\n if (value === undefined || typeof value === 'boolean') return value;\n return normalizeOpenApiSchema(value);\n}\n\nfunction normalizeSchemaType(\n type: string | readonly string[] | undefined,\n): DataSchemaPrimitiveType | readonly DataSchemaPrimitiveType[] | undefined {\n if (type === undefined) return undefined;\n if (typeof type === 'string') return isDataSchemaPrimitive(type) ? type : undefined;\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 apiId: 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 apiId,\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 apiId,\n `${path}.properties.${propertyName}`,\n diagnostics,\n );\n }\n if (schema.items !== undefined) {\n collectUnsupportedSchemaDiagnostics(schema.items, apiId, `${path}.items`, diagnostics);\n }\n}\n"]}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { CredentialRef, DataContractValue } from '@ankhorage/contracts/data';
|
|
2
|
+
export type OpenApiHttpMethod = 'delete' | 'get' | 'head' | 'options' | 'patch' | 'post' | 'put';
|
|
3
|
+
export interface OpenApiServerObject {
|
|
4
|
+
readonly url: string;
|
|
5
|
+
readonly description?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface OpenApiSchemaObject {
|
|
8
|
+
readonly $ref?: string;
|
|
9
|
+
readonly type?: string | readonly string[];
|
|
10
|
+
readonly title?: string;
|
|
11
|
+
readonly description?: string;
|
|
12
|
+
readonly enum?: readonly DataContractValue[];
|
|
13
|
+
readonly const?: DataContractValue;
|
|
14
|
+
readonly default?: DataContractValue;
|
|
15
|
+
readonly format?: string;
|
|
16
|
+
readonly nullable?: boolean;
|
|
17
|
+
readonly required?: readonly string[];
|
|
18
|
+
readonly properties?: Readonly<Record<string, OpenApiSchemaObject>>;
|
|
19
|
+
readonly additionalProperties?: boolean | OpenApiSchemaObject;
|
|
20
|
+
readonly items?: OpenApiSchemaObject;
|
|
21
|
+
readonly allOf?: readonly OpenApiSchemaObject[];
|
|
22
|
+
readonly anyOf?: readonly OpenApiSchemaObject[];
|
|
23
|
+
readonly oneOf?: readonly OpenApiSchemaObject[];
|
|
24
|
+
}
|
|
25
|
+
export interface OpenApiMediaTypeObject {
|
|
26
|
+
readonly schema?: OpenApiSchemaObject;
|
|
27
|
+
}
|
|
28
|
+
export interface OpenApiRequestBodyObject {
|
|
29
|
+
readonly description?: string;
|
|
30
|
+
readonly required?: boolean;
|
|
31
|
+
readonly content?: Readonly<Record<string, OpenApiMediaTypeObject>>;
|
|
32
|
+
}
|
|
33
|
+
export interface OpenApiResponseObject {
|
|
34
|
+
readonly description?: string;
|
|
35
|
+
readonly content?: Readonly<Record<string, OpenApiMediaTypeObject>>;
|
|
36
|
+
}
|
|
37
|
+
export interface OpenApiParameterObject {
|
|
38
|
+
readonly name: string;
|
|
39
|
+
readonly in: string;
|
|
40
|
+
readonly required?: boolean;
|
|
41
|
+
readonly description?: string;
|
|
42
|
+
readonly schema?: OpenApiSchemaObject;
|
|
43
|
+
}
|
|
44
|
+
export interface OpenApiOperationObject {
|
|
45
|
+
readonly operationId?: string;
|
|
46
|
+
readonly summary?: string;
|
|
47
|
+
readonly description?: string;
|
|
48
|
+
readonly deprecated?: boolean;
|
|
49
|
+
readonly parameters?: readonly OpenApiParameterObject[];
|
|
50
|
+
readonly requestBody?: OpenApiRequestBodyObject;
|
|
51
|
+
readonly responses?: Readonly<Record<string, OpenApiResponseObject>>;
|
|
52
|
+
}
|
|
53
|
+
export type OpenApiPathItemObject = Partial<Record<OpenApiHttpMethod, OpenApiOperationObject>> & {
|
|
54
|
+
readonly parameters?: readonly OpenApiParameterObject[];
|
|
55
|
+
};
|
|
56
|
+
export interface OpenApiComponentsObject {
|
|
57
|
+
readonly schemas?: Readonly<Record<string, OpenApiSchemaObject>>;
|
|
58
|
+
readonly securitySchemes?: Readonly<Record<string, DataContractValue>>;
|
|
59
|
+
}
|
|
60
|
+
export interface OpenApiDocumentObject {
|
|
61
|
+
readonly openapi?: string;
|
|
62
|
+
readonly info?: {
|
|
63
|
+
readonly title?: string;
|
|
64
|
+
readonly version?: string;
|
|
65
|
+
readonly description?: string;
|
|
66
|
+
};
|
|
67
|
+
readonly servers?: readonly OpenApiServerObject[];
|
|
68
|
+
readonly paths?: Readonly<Record<string, OpenApiPathItemObject>>;
|
|
69
|
+
readonly components?: OpenApiComponentsObject;
|
|
70
|
+
}
|
|
71
|
+
export interface OpenApiImportInput {
|
|
72
|
+
readonly id: string;
|
|
73
|
+
readonly document: OpenApiDocumentObject;
|
|
74
|
+
readonly baseUrl?: string;
|
|
75
|
+
readonly credential?: CredentialRef;
|
|
76
|
+
readonly documentId?: string;
|
|
77
|
+
readonly documentUrl?: string;
|
|
78
|
+
readonly name?: string;
|
|
79
|
+
readonly description?: string;
|
|
80
|
+
readonly metadata?: DataContractValue;
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/openapi/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAElF,MAAM,MAAM,iBAAiB,GAAG,QAAQ,GAAG,KAAK,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,GAAG,MAAM,GAAG,KAAK,CAAC;AAEjG,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,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,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,CAAC,EAAE;QACd,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QACxB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;QAC1B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;KAC/B,CAAC;IACF,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,mBAAmB,EAAE,CAAC;IAClD,QAAQ,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/openapi/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { CredentialRef, DataContractValue } from '@ankhorage/contracts/data';\n\nexport type OpenApiHttpMethod = 'delete' | 'get' | 'head' | 'options' | 'patch' | 'post' | 'put';\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"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ApiProtocol, DataSourceConfig, DataSourceKind } from '@ankhorage/contracts/data';
|
|
2
|
+
export declare const DATA_SOURCES_PACKAGE_NAME: "@ankhorage/data-sources";
|
|
3
|
+
export declare const SUPPORTED_DATA_SOURCE_KINDS: readonly ["database"];
|
|
4
|
+
export declare const SUPPORTED_API_ORIGINS: readonly ["external"];
|
|
5
|
+
export declare const SUPPORTED_API_PROTOCOLS: readonly ["graphql", "rest"];
|
|
6
|
+
export type SupportedApiOrigin = (typeof SUPPORTED_API_ORIGINS)[number];
|
|
7
|
+
export interface DataSourcesPackageInfo {
|
|
8
|
+
readonly packageName: typeof DATA_SOURCES_PACKAGE_NAME;
|
|
9
|
+
readonly supportedKinds: typeof SUPPORTED_DATA_SOURCE_KINDS;
|
|
10
|
+
readonly supportedApiOrigins: typeof SUPPORTED_API_ORIGINS;
|
|
11
|
+
readonly supportedApiProtocols: typeof SUPPORTED_API_PROTOCOLS;
|
|
12
|
+
}
|
|
13
|
+
export declare function getDataSourcesPackageInfo(): DataSourcesPackageInfo;
|
|
14
|
+
export declare function isSupportedDataSourceKind(kind: string): kind is DataSourceKind;
|
|
15
|
+
export declare function isSupportedApiOrigin(origin: string): origin is SupportedApiOrigin;
|
|
16
|
+
export declare function isSupportedApiProtocol(protocol: string): protocol is ApiProtocol;
|
|
17
|
+
export declare function getDataSourceKind(source: DataSourceConfig): DataSourceKind;
|
|
18
|
+
//# sourceMappingURL=packageInfo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"packageInfo.d.ts","sourceRoot":"","sources":["../src/packageInfo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,WAAW,EACX,gBAAgB,EAChB,cAAc,EACf,MAAM,2BAA2B,CAAC;AAEnC,eAAO,MAAM,yBAAyB,EAAG,yBAAkC,CAAC;AAC5E,eAAO,MAAM,2BAA2B,uBAEM,CAAC;AAC/C,eAAO,MAAM,qBAAqB,uBAAuD,CAAC;AAC1F,eAAO,MAAM,uBAAuB,8BAGO,CAAC;AAE5C,MAAM,MAAM,kBAAkB,GAAG,CAAC,OAAO,qBAAqB,CAAC,CAAC,MAAM,CAAC,CAAC;AAExE,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,kBAAkB,CAEjF;AAED,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,QAAQ,IAAI,WAAW,CAEhF;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,gBAAgB,GAAG,cAAc,CAE1E"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export const DATA_SOURCES_PACKAGE_NAME = '@ankhorage/data-sources';
|
|
2
|
+
export const SUPPORTED_DATA_SOURCE_KINDS = [
|
|
3
|
+
'database',
|
|
4
|
+
];
|
|
5
|
+
export const SUPPORTED_API_ORIGINS = ['external'];
|
|
6
|
+
export const SUPPORTED_API_PROTOCOLS = [
|
|
7
|
+
'graphql',
|
|
8
|
+
'rest',
|
|
9
|
+
];
|
|
10
|
+
export function getDataSourcesPackageInfo() {
|
|
11
|
+
return {
|
|
12
|
+
packageName: DATA_SOURCES_PACKAGE_NAME,
|
|
13
|
+
supportedKinds: SUPPORTED_DATA_SOURCE_KINDS,
|
|
14
|
+
supportedApiOrigins: SUPPORTED_API_ORIGINS,
|
|
15
|
+
supportedApiProtocols: SUPPORTED_API_PROTOCOLS,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export function isSupportedDataSourceKind(kind) {
|
|
19
|
+
return SUPPORTED_DATA_SOURCE_KINDS.some((supported) => supported === kind);
|
|
20
|
+
}
|
|
21
|
+
export function isSupportedApiOrigin(origin) {
|
|
22
|
+
return SUPPORTED_API_ORIGINS.some((supported) => supported === origin);
|
|
23
|
+
}
|
|
24
|
+
export function isSupportedApiProtocol(protocol) {
|
|
25
|
+
return SUPPORTED_API_PROTOCOLS.some((supported) => supported === protocol);
|
|
26
|
+
}
|
|
27
|
+
export function getDataSourceKind(source) {
|
|
28
|
+
return source.kind;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=packageInfo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"packageInfo.js","sourceRoot":"","sources":["../src/packageInfo.ts"],"names":[],"mappings":"AAOA,MAAM,CAAC,MAAM,yBAAyB,GAAG,yBAAkC,CAAC;AAC5E,MAAM,CAAC,MAAM,2BAA2B,GAAG;IACzC,UAAU;CACkC,CAAC;AAC/C,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,UAAU,CAAyC,CAAC;AAC1F,MAAM,CAAC,MAAM,uBAAuB,GAAG;IACrC,SAAS;IACT,MAAM;CACmC,CAAC;AAW5C,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 const DATA_SOURCES_PACKAGE_NAME = '@ankhorage/data-sources' as const;\nexport const SUPPORTED_DATA_SOURCE_KINDS = [\n 'database',\n] as const satisfies readonly DataSourceKind[];\nexport const SUPPORTED_API_ORIGINS = ['external'] as const satisfies readonly ApiOrigin[];\nexport const SUPPORTED_API_PROTOCOLS = [\n 'graphql',\n 'rest',\n] as const satisfies readonly ApiProtocol[];\n\nexport type SupportedApiOrigin = (typeof SUPPORTED_API_ORIGINS)[number];\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 SupportedApiOrigin {\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"]}
|
package/dist/rest/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CredentialRef, DataContractValue, DataOperationIntent, DataOperationMethod, DataOperationPagination, DataOperationParameter, DataOperationRequest, DataOperationResponse, DataSchemaRegistry, DataSourceDiagnostic, DataSourceDiagnosticResult, EndpointId,
|
|
1
|
+
import type { CredentialRef, DataContractValue, DataOperationIntent, DataOperationMethod, DataOperationPagination, DataOperationParameter, DataOperationRequest, DataOperationResponse, DataSchemaRegistry, DataSourceDiagnostic, DataSourceDiagnosticResult, EndpointId, ExternalRestApiDefinition, OperationId } from '@ankhorage/contracts/data';
|
|
2
2
|
declare const REST_METHODS: readonly ["DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT"];
|
|
3
3
|
export type ManualRestMethod = (typeof REST_METHODS)[number];
|
|
4
4
|
export interface ManualRestOperationDefinition {
|
|
@@ -24,7 +24,7 @@ export interface ManualRestEndpointDefinition {
|
|
|
24
24
|
readonly operations: readonly ManualRestOperationDefinition[];
|
|
25
25
|
readonly metadata?: DataContractValue;
|
|
26
26
|
}
|
|
27
|
-
export interface
|
|
27
|
+
export interface ManualRestApiDefinition {
|
|
28
28
|
readonly id: string;
|
|
29
29
|
readonly baseUrl: string;
|
|
30
30
|
readonly name?: string;
|
|
@@ -37,8 +37,8 @@ export interface ManualRestDataSourceDefinition {
|
|
|
37
37
|
export declare function isManualRestMethod(method: string): method is ManualRestMethod;
|
|
38
38
|
export declare function normalizeManualRestMethod(method: string): DataOperationMethod;
|
|
39
39
|
export declare function extractRestPathParams(path: string): readonly string[];
|
|
40
|
-
export declare function
|
|
41
|
-
export declare function
|
|
42
|
-
export declare function
|
|
40
|
+
export declare function validateManualRestApi(definition: ManualRestApiDefinition): readonly DataSourceDiagnostic[];
|
|
41
|
+
export declare function createManualRestApi(definition: ManualRestApiDefinition): DataSourceDiagnosticResult<ExternalRestApiDefinition>;
|
|
42
|
+
export declare function normalizeManualRestApi(definition: ManualRestApiDefinition): ExternalRestApiDefinition;
|
|
43
43
|
export {};
|
|
44
44
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/rest/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/rest/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,iBAAiB,EAGjB,mBAAmB,EACnB,mBAAmB,EACnB,uBAAuB,EACvB,sBAAsB,EACtB,oBAAoB,EACpB,qBAAqB,EACrB,kBAAkB,EAClB,oBAAoB,EACpB,0BAA0B,EAC1B,UAAU,EACV
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/rest/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,iBAAiB,EAGjB,mBAAmB,EACnB,mBAAmB,EACnB,uBAAuB,EACvB,sBAAsB,EACtB,oBAAoB,EACpB,qBAAqB,EACrB,kBAAkB,EAClB,oBAAoB,EACpB,0BAA0B,EAC1B,UAAU,EACV,yBAAyB,EACzB,WAAW,EACZ,MAAM,2BAA2B,CAAC;AAEnC,QAAA,MAAM,YAAY,uEAAwE,CAAC;AAE3F,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,YA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