@ankhorage/data-sources 0.0.0 → 0.2.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,15 @@
1
+ # @ankhorage/data-sources
2
+
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 504dc55: Add dependency-free GraphQL introspection normalization helpers and serializable GraphQL operation modeling.
8
+
9
+ ## 0.1.0
10
+
11
+ ### Minor Changes
12
+
13
+ - a52311c: Add manual REST data-source definition helpers with normalization and structured diagnostics.
14
+ - 84ddd56: Add dependency-free OpenAPI JSON import helpers that normalize paths, operations, parameters, requests, responses, schemas, and diagnostics into shared Ankhorage data-source contracts.
15
+ - bee5b37: Establish the package baseline, ownership boundaries, shared contracts dependency, and initial smoke-tested public API.
package/README.md CHANGED
@@ -15,6 +15,12 @@ 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
+ - [normalizeGraphQlIntrospectionOperations sequence](././paradox/diagrams/sequences/normalize-graph-ql-introspection-operations.mmd)
20
+ - [normalizeGraphQlIntrospectionSchemas sequence](././paradox/diagrams/sequences/normalize-graph-ql-introspection-schemas.mmd)
21
+ - [normalizeManualRestDataSource sequence](././paradox/diagrams/sequences/normalize-manual-rest-data-source.mmd)
22
+ - [normalizeOpenApiSchema sequence](././paradox/diagrams/sequences/normalize-open-api-schema.mmd)
23
+ - [validateManualRestDataSource sequence](././paradox/diagrams/sequences/validate-manual-rest-data-source.mmd)
18
24
 
19
25
  ## Architecture preview
20
26
 
@@ -26,7 +32,13 @@ graph TD
26
32
  package__ankhorage_data_sources["@ankhorage/data-sources"]
27
33
  entrypoint_src_index_ts["src/index.ts"]
28
34
  package__ankhorage_data_sources --> entrypoint_src_index_ts
35
+ module_src_graphql_index_ts["src/graphql/index.ts"]
36
+ package__ankhorage_data_sources -.-> module_src_graphql_index_ts
29
37
  module_src_index_ts["src/index.ts"]
38
+ module_src_openapi_index_ts["src/openapi/index.ts"]
39
+ package__ankhorage_data_sources -.-> module_src_openapi_index_ts
40
+ module_src_rest_index_ts["src/rest/index.ts"]
41
+ package__ankhorage_data_sources -.-> module_src_rest_index_ts
30
42
  ```
31
43
 
32
44
  </details>
@@ -0,0 +1,83 @@
1
+ import type { CredentialRef, DataContractValue, DataSchema, DataSchemaRegistry, DataSourceDiagnostic, DataSourceDiagnosticResult, GraphQlDataSourceConfig, OperationId } from '@ankhorage/contracts/data';
2
+ export declare const GRAPHQL_INTROSPECTION_QUERY = "query AnkhorageGraphQlIntrospection {\n __schema {\n queryType { name }\n mutationType { name }\n subscriptionType { name }\n types {\n kind\n name\n description\n fields {\n name\n description\n args {\n name\n description\n type { kind name ofType { kind name ofType { kind name ofType { kind name } } } }\n defaultValue\n }\n type { kind name ofType { kind name ofType { kind name ofType { kind name } } } }\n }\n inputFields {\n name\n description\n type { kind name ofType { kind name ofType { kind name ofType { kind name } } } }\n defaultValue\n }\n enumValues { name description }\n possibleTypes { kind name }\n }\n }\n}";
3
+ export type GraphQlOperationKind = 'mutation' | 'query' | 'subscription';
4
+ export interface GraphQlIntrospectionTypeRef {
5
+ readonly kind: string;
6
+ readonly name?: string | null;
7
+ readonly ofType?: GraphQlIntrospectionTypeRef | null;
8
+ }
9
+ export interface GraphQlIntrospectionInputValue {
10
+ readonly name: string;
11
+ readonly description?: string | null;
12
+ readonly type: GraphQlIntrospectionTypeRef;
13
+ readonly defaultValue?: string | null;
14
+ }
15
+ export interface GraphQlIntrospectionField {
16
+ readonly name: string;
17
+ readonly description?: string | null;
18
+ readonly args?: readonly GraphQlIntrospectionInputValue[] | null;
19
+ readonly type: GraphQlIntrospectionTypeRef;
20
+ }
21
+ export interface GraphQlIntrospectionEnumValue {
22
+ readonly name: string;
23
+ readonly description?: string | null;
24
+ }
25
+ export interface GraphQlIntrospectionType {
26
+ readonly kind: string;
27
+ readonly name?: string | null;
28
+ readonly description?: string | null;
29
+ readonly fields?: readonly GraphQlIntrospectionField[] | null;
30
+ readonly inputFields?: readonly GraphQlIntrospectionInputValue[] | null;
31
+ readonly enumValues?: readonly GraphQlIntrospectionEnumValue[] | null;
32
+ readonly possibleTypes?: readonly GraphQlIntrospectionTypeRef[] | null;
33
+ }
34
+ export interface GraphQlIntrospectionSchema {
35
+ readonly queryType?: {
36
+ readonly name?: string | null;
37
+ } | null;
38
+ readonly mutationType?: {
39
+ readonly name?: string | null;
40
+ } | null;
41
+ readonly subscriptionType?: {
42
+ readonly name?: string | null;
43
+ } | null;
44
+ readonly types?: readonly GraphQlIntrospectionType[] | null;
45
+ }
46
+ export interface GraphQlIntrospectionResult {
47
+ readonly __schema?: GraphQlIntrospectionSchema;
48
+ }
49
+ export interface GraphQlOperationDefinition {
50
+ readonly id: OperationId;
51
+ readonly kind: GraphQlOperationKind;
52
+ readonly name?: string;
53
+ readonly description?: string;
54
+ readonly document?: string;
55
+ readonly variables?: DataSchema;
56
+ readonly response?: DataSchema;
57
+ readonly selectionPath?: string;
58
+ readonly metadata?: DataContractValue;
59
+ }
60
+ export interface GraphQlDataSourceDefinition {
61
+ readonly id: string;
62
+ readonly endpointUrl: string;
63
+ readonly name?: string;
64
+ readonly description?: string;
65
+ readonly credential?: CredentialRef;
66
+ readonly introspection?: GraphQlIntrospectionResult;
67
+ readonly introspectionEnabled?: boolean;
68
+ readonly schemaVersion?: string;
69
+ readonly operations?: readonly GraphQlOperationDefinition[];
70
+ readonly metadata?: DataContractValue;
71
+ }
72
+ export interface GraphQlIntrospectionRequest {
73
+ readonly query: typeof GRAPHQL_INTROSPECTION_QUERY;
74
+ readonly operationName: 'AnkhorageGraphQlIntrospection';
75
+ }
76
+ export declare function createGraphQlIntrospectionRequest(): GraphQlIntrospectionRequest;
77
+ export declare function normalizeGraphQlOperationId(kind: GraphQlOperationKind, name: string): OperationId;
78
+ export declare function createGraphQlDataSource(definition: GraphQlDataSourceDefinition): DataSourceDiagnosticResult<GraphQlDataSourceConfig>;
79
+ export declare function validateGraphQlDataSource(definition: GraphQlDataSourceDefinition): readonly DataSourceDiagnostic[];
80
+ export declare function normalizeGraphQlDataSource(definition: GraphQlDataSourceDefinition): GraphQlDataSourceConfig;
81
+ export declare function normalizeGraphQlIntrospectionSchemas(introspection: GraphQlIntrospectionResult | undefined): DataSchemaRegistry | undefined;
82
+ export declare function normalizeGraphQlIntrospectionOperations(introspection: GraphQlIntrospectionResult | undefined): readonly GraphQlOperationDefinition[];
83
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/graphql/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,iBAAiB,EAKjB,UAAU,EACV,kBAAkB,EAClB,oBAAoB,EACpB,0BAA0B,EAC1B,uBAAuB,EACvB,WAAW,EACZ,MAAM,2BAA2B,CAAC;AAEnC,eAAO,MAAM,2BAA2B,2xBA8BtC,CAAC;AAEH,MAAM,MAAM,oBAAoB,GAAG,UAAU,GAAG,OAAO,GAAG,cAAc,CAAC;AAIzE,MAAM,WAAW,2BAA2B;IAC1C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,QAAQ,CAAC,MAAM,CAAC,EAAE,2BAA2B,GAAG,IAAI,CAAC;CACtD;AAED,MAAM,WAAW,8BAA8B;IAC7C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,QAAQ,CAAC,IAAI,EAAE,2BAA2B,CAAC;IAC3C,QAAQ,CAAC,YAAY,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5D,QAAQ,CAAC,QAAQ,CAAC,EAAE,iBAAiB,CAAC;CACvC;AAED,MAAM,WAAW,2BAA2B;IAC1C,QAAQ,CAAC,KAAK,EAAE,OAAO,2BAA2B,CAAC;IACnD,QAAQ,CAAC,aAAa,EAAE,+BAA+B,CAAC;CACzD;AAED,wBAAgB,iCAAiC,IAAI,2BAA2B,CAK/E;AAED,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,oBAAoB,EAAE,IAAI,EAAE,MAAM,GAAG,WAAW,CAOjG;AAED,wBAAgB,uBAAuB,CACrC,UAAU,EAAE,2BAA2B,GACtC,0BAA0B,CAAC,uBAAuB,CAAC,CAWrD;AAED,wBAAgB,yBAAyB,CACvC,UAAU,EAAE,2BAA2B,GACtC,SAAS,oBAAoB,EAAE,CAmCjC;AAED,wBAAgB,0BAA0B,CACxC,UAAU,EAAE,2BAA2B,GACtC,uBAAuB,CAsCzB;AAED,wBAAgB,oCAAoC,CAClD,aAAa,EAAE,0BAA0B,GAAG,SAAS,GACpD,kBAAkB,GAAG,SAAS,CAYhC;AAED,wBAAgB,uCAAuC,CACrD,aAAa,EAAE,0BAA0B,GAAG,SAAS,GACpD,SAAS,0BAA0B,EAAE,CAYvC"}
@@ -0,0 +1,327 @@
1
+ export const GRAPHQL_INTROSPECTION_QUERY = `query AnkhorageGraphQlIntrospection {
2
+ __schema {
3
+ queryType { name }
4
+ mutationType { name }
5
+ subscriptionType { name }
6
+ types {
7
+ kind
8
+ name
9
+ description
10
+ fields {
11
+ name
12
+ description
13
+ args {
14
+ name
15
+ description
16
+ type { kind name ofType { kind name ofType { kind name ofType { kind name } } } }
17
+ defaultValue
18
+ }
19
+ type { kind name ofType { kind name ofType { kind name ofType { kind name } } } }
20
+ }
21
+ inputFields {
22
+ name
23
+ description
24
+ type { kind name ofType { kind name ofType { kind name ofType { kind name } } } }
25
+ defaultValue
26
+ }
27
+ enumValues { name description }
28
+ possibleTypes { kind name }
29
+ }
30
+ }
31
+ }`;
32
+ export function createGraphQlIntrospectionRequest() {
33
+ return {
34
+ query: GRAPHQL_INTROSPECTION_QUERY,
35
+ operationName: 'AnkhorageGraphQlIntrospection',
36
+ };
37
+ }
38
+ export function normalizeGraphQlOperationId(kind, name) {
39
+ const normalizedName = name
40
+ .replace(/[^A-Za-z0-9]+/g, '-')
41
+ .replace(/^-+|-+$/g, '')
42
+ .toLowerCase();
43
+ return normalizedName.length > 0 ? `${kind}.${normalizedName}` : `${kind}.operation`;
44
+ }
45
+ export function createGraphQlDataSource(definition) {
46
+ const diagnostics = validateGraphQlDataSource(definition);
47
+ const hasErrors = diagnostics.some((diagnostic) => diagnostic.severity === 'error');
48
+ if (hasErrors)
49
+ return { ok: false, diagnostics };
50
+ return {
51
+ ok: true,
52
+ data: normalizeGraphQlDataSource(definition),
53
+ diagnostics,
54
+ };
55
+ }
56
+ export function validateGraphQlDataSource(definition) {
57
+ const diagnostics = [];
58
+ if (definition.endpointUrl.trim().length === 0) {
59
+ diagnostics.push({
60
+ code: 'invalid-config',
61
+ dataSourceId: definition.id,
62
+ message: 'GraphQL data source requires a non-empty endpointUrl.',
63
+ path: 'endpointUrl',
64
+ severity: 'error',
65
+ });
66
+ }
67
+ if (definition.introspectionEnabled === false && definition.introspection !== undefined) {
68
+ diagnostics.push({
69
+ code: 'invalid-config',
70
+ dataSourceId: definition.id,
71
+ message: 'GraphQL introspection data was provided while introspection is disabled.',
72
+ path: 'introspection',
73
+ severity: 'warning',
74
+ });
75
+ }
76
+ if (definition.introspectionEnabled !== false && definition.introspection === undefined) {
77
+ diagnostics.push({
78
+ code: 'missing-schema',
79
+ dataSourceId: definition.id,
80
+ message: 'GraphQL introspection result was not provided. Manual operations can still be used.',
81
+ path: 'introspection',
82
+ severity: 'info',
83
+ });
84
+ }
85
+ return diagnostics;
86
+ }
87
+ export function normalizeGraphQlDataSource(definition) {
88
+ const schemas = normalizeGraphQlIntrospectionSchemas(definition.introspection);
89
+ const introspectionOperations = normalizeGraphQlIntrospectionOperations(definition.introspection);
90
+ const manualOperations = definition.operations ?? [];
91
+ const operations = {};
92
+ for (const operation of [...introspectionOperations, ...manualOperations]) {
93
+ operations[operation.id] = normalizeGraphQlOperation(operation);
94
+ }
95
+ const endpoint = {
96
+ id: 'graphql',
97
+ kind: 'graphql',
98
+ baseUrl: definition.endpointUrl,
99
+ credential: definition.credential,
100
+ operations,
101
+ metadata: {
102
+ source: 'graphql',
103
+ },
104
+ };
105
+ return {
106
+ id: definition.id,
107
+ kind: 'graphql',
108
+ name: definition.name,
109
+ description: definition.description,
110
+ endpointUrl: definition.endpointUrl,
111
+ credential: definition.credential,
112
+ endpoints: {
113
+ graphql: endpoint,
114
+ },
115
+ schemas,
116
+ introspection: {
117
+ enabled: definition.introspectionEnabled ?? definition.introspection !== undefined,
118
+ schemaVersion: definition.schemaVersion,
119
+ },
120
+ metadata: definition.metadata,
121
+ };
122
+ }
123
+ export function normalizeGraphQlIntrospectionSchemas(introspection) {
124
+ const types = introspection?.__schema?.types?.filter(isNamedGraphQlType) ?? [];
125
+ if (types.length === 0)
126
+ return undefined;
127
+ const schemas = {};
128
+ for (const type of types) {
129
+ if (type.name === undefined || type.name === null || type.name.startsWith('__'))
130
+ continue;
131
+ schemas[type.name] = normalizeGraphQlType(type);
132
+ }
133
+ return schemas;
134
+ }
135
+ export function normalizeGraphQlIntrospectionOperations(introspection) {
136
+ const schema = introspection?.__schema;
137
+ if (schema === undefined)
138
+ return [];
139
+ const types = schema.types?.filter(isNamedGraphQlType) ?? [];
140
+ const operations = [];
141
+ appendRootOperations(operations, 'query', schema.queryType?.name, types);
142
+ appendRootOperations(operations, 'mutation', schema.mutationType?.name, types);
143
+ appendRootOperations(operations, 'subscription', schema.subscriptionType?.name, types);
144
+ return operations;
145
+ }
146
+ function appendRootOperations(operations, kind, rootTypeName, types) {
147
+ if (rootTypeName === undefined || rootTypeName === null)
148
+ return;
149
+ const rootType = types.find((type) => type.name === rootTypeName);
150
+ for (const field of rootType?.fields ?? []) {
151
+ operations.push({
152
+ id: normalizeGraphQlOperationId(kind, field.name),
153
+ kind,
154
+ name: field.name,
155
+ description: field.description ?? undefined,
156
+ variables: normalizeGraphQlVariablesSchema(field.args ?? []),
157
+ response: normalizeGraphQlTypeRef(field.type),
158
+ selectionPath: `$.data.${field.name}`,
159
+ metadata: {
160
+ rootType: rootTypeName,
161
+ source: 'introspection',
162
+ },
163
+ });
164
+ }
165
+ }
166
+ function normalizeGraphQlOperation(operation) {
167
+ const response = operation.response === undefined
168
+ ? undefined
169
+ : {
170
+ schema: operation.response,
171
+ };
172
+ return {
173
+ id: operation.id,
174
+ endpointId: 'graphql',
175
+ name: operation.name,
176
+ description: operation.description,
177
+ protocol: 'graphql',
178
+ intent: mapGraphQlOperationKindToIntent(operation.kind),
179
+ request: {
180
+ schema: operation.variables,
181
+ },
182
+ response,
183
+ metadata: createGraphQlOperationMetadata(operation),
184
+ };
185
+ }
186
+ function mapGraphQlOperationKindToIntent(kind) {
187
+ if (kind === 'query' || kind === 'subscription')
188
+ return 'read';
189
+ return 'action';
190
+ }
191
+ function normalizeGraphQlVariablesSchema(args) {
192
+ const properties = {};
193
+ const required = [];
194
+ for (const arg of args) {
195
+ properties[arg.name] = {
196
+ ...normalizeGraphQlTypeRef(arg.type),
197
+ description: arg.description ?? undefined,
198
+ default: arg.defaultValue ?? undefined,
199
+ };
200
+ if (isGraphQlNonNull(arg.type))
201
+ required.push(arg.name);
202
+ }
203
+ return {
204
+ type: 'object',
205
+ required: required.length > 0 ? required : undefined,
206
+ properties,
207
+ };
208
+ }
209
+ function normalizeGraphQlType(type) {
210
+ if (type.kind === 'OBJECT' || type.kind === 'INTERFACE' || type.kind === 'INPUT_OBJECT') {
211
+ return normalizeGraphQlObjectType(type);
212
+ }
213
+ if (type.kind === 'ENUM') {
214
+ return {
215
+ type: 'string',
216
+ title: type.name ?? undefined,
217
+ description: type.description ?? undefined,
218
+ enum: type.enumValues?.map((value) => value.name),
219
+ };
220
+ }
221
+ if (type.kind === 'SCALAR') {
222
+ return {
223
+ ...normalizeGraphQlNamedScalar(type.name),
224
+ title: type.name ?? undefined,
225
+ description: type.description ?? undefined,
226
+ };
227
+ }
228
+ if (type.kind === 'UNION') {
229
+ return {
230
+ title: type.name ?? undefined,
231
+ description: type.description ?? undefined,
232
+ anyOf: type.possibleTypes?.map((possibleType) => normalizeGraphQlTypeRef(possibleType)),
233
+ };
234
+ }
235
+ return {
236
+ title: type.name ?? undefined,
237
+ description: type.description ?? undefined,
238
+ };
239
+ }
240
+ function normalizeGraphQlObjectType(type) {
241
+ const fields = type.kind === 'INPUT_OBJECT' ? type.inputFields : type.fields;
242
+ const properties = {};
243
+ const required = [];
244
+ for (const field of fields ?? []) {
245
+ const fieldType = 'type' in field ? field.type : undefined;
246
+ if (fieldType === undefined)
247
+ continue;
248
+ properties[field.name] = {
249
+ ...normalizeGraphQlTypeRef(fieldType),
250
+ description: field.description ?? undefined,
251
+ };
252
+ if (isGraphQlNonNull(fieldType))
253
+ required.push(field.name);
254
+ }
255
+ return {
256
+ type: 'object',
257
+ title: type.name ?? undefined,
258
+ description: type.description ?? undefined,
259
+ required: required.length > 0 ? required : undefined,
260
+ properties,
261
+ };
262
+ }
263
+ function normalizeGraphQlTypeRef(type) {
264
+ if (type.kind === 'NON_NULL' && type.ofType !== undefined && type.ofType !== null) {
265
+ return {
266
+ ...normalizeGraphQlTypeRef(type.ofType),
267
+ nullable: false,
268
+ };
269
+ }
270
+ if (type.kind === 'LIST' && type.ofType !== undefined && type.ofType !== null) {
271
+ return {
272
+ type: 'array',
273
+ items: normalizeGraphQlTypeRef(type.ofType),
274
+ };
275
+ }
276
+ if (type.kind === 'SCALAR') {
277
+ return normalizeGraphQlNamedScalar(type.name);
278
+ }
279
+ if (type.name !== undefined && type.name !== null) {
280
+ return { ref: { id: type.name } };
281
+ }
282
+ return {};
283
+ }
284
+ function normalizeGraphQlNamedScalar(name) {
285
+ if (name === 'Boolean')
286
+ return { type: 'boolean' };
287
+ if (name === 'Float')
288
+ return { type: 'number' };
289
+ if (name === 'ID' || name === 'String')
290
+ return { type: 'string' };
291
+ if (name === 'Int')
292
+ return { type: 'integer' };
293
+ return {
294
+ type: 'string',
295
+ format: name ?? undefined,
296
+ };
297
+ }
298
+ function isGraphQlNonNull(type) {
299
+ return type.kind === 'NON_NULL';
300
+ }
301
+ function isNamedGraphQlType(type) {
302
+ return type.name !== undefined && type.name !== null;
303
+ }
304
+ function createGraphQlOperationMetadata(operation) {
305
+ const metadata = toMetadataRecord(operation.metadata);
306
+ metadata.kind = operation.kind;
307
+ if (operation.document !== undefined) {
308
+ metadata.document = operation.document;
309
+ }
310
+ if (operation.selectionPath !== undefined) {
311
+ metadata.selectionPath = operation.selectionPath;
312
+ }
313
+ return metadata;
314
+ }
315
+ function toMetadataRecord(value) {
316
+ if (!isDataContractRecord(value))
317
+ return {};
318
+ const metadata = {};
319
+ for (const [key, item] of Object.entries(value)) {
320
+ metadata[key] = item;
321
+ }
322
+ return metadata;
323
+ }
324
+ function isDataContractRecord(value) {
325
+ return (value !== undefined && typeof value === 'object' && value !== null && !Array.isArray(value));
326
+ }
327
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/graphql/index.ts"],"names":[],"mappings":"AAeA,MAAM,CAAC,MAAM,2BAA2B,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA8BzC,CAAC;AAkFH,MAAM,UAAU,iCAAiC;IAC/C,OAAO;QACL,KAAK,EAAE,2BAA2B;QAClC,aAAa,EAAE,+BAA+B;KAC/C,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,2BAA2B,CAAC,IAA0B,EAAE,IAAY;IAClF,MAAM,cAAc,GAAG,IAAI;SACxB,OAAO,CAAC,gBAAgB,EAAE,GAAG,CAAC;SAC9B,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC;SACvB,WAAW,EAAE,CAAC;IAEjB,OAAO,cAAc,CAAC,MAAM,GAAG,CAAC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AQ,CAAC,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC;IAE/B,IAAI,SAAS,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;QACrC,QAAQ,CAAC,QAAQ,GAAG,SAAS,CAAC,QAAQ,CAAC;IACzC,CAAC;IAED,IAAI,SAAS,CAAC,aAAa,KAAK,SAAS,EAAE,CAAC;QAC1C,QAAQ,CAAC,aAAa,GAAG,SAAS,CAAC,aAAa,CAAC;IACnD,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAoC;IAC5D,IAAI,CAAC,oBAAoB,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAE5C,MAAM,QAAQ,GAAuB,EAAE,CAAC;IACxC,KAAK,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAChD,QAAQ,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;IACvB,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,SAAS,oBAAoB,CAAC,KAAoC;IAChE,OAAO,CACL,KAAK,KAAK,SAAS,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAC5F,CAAC;AACJ,CAAC","sourcesContent":["import type {\n CredentialRef,\n DataContractValue,\n DataEndpointConfig,\n DataOperationConfig,\n DataOperationIntent,\n DataOperationResponse,\n DataSchema,\n DataSchemaRegistry,\n DataSourceDiagnostic,\n DataSourceDiagnosticResult,\n GraphQlDataSourceConfig,\n OperationId,\n} from '@ankhorage/contracts/data';\n\nexport const GRAPHQL_INTROSPECTION_QUERY = `query AnkhorageGraphQlIntrospection {\n __schema {\n queryType { name }\n mutationType { name }\n subscriptionType { name }\n types {\n kind\n name\n description\n fields {\n name\n description\n args {\n name\n description\n type { kind name ofType { kind name ofType { kind name ofType { kind name } } } }\n defaultValue\n }\n type { kind name ofType { kind name ofType { kind name ofType { kind name } } } }\n }\n inputFields {\n name\n description\n type { kind name ofType { kind name ofType { kind name ofType { kind name } } } }\n defaultValue\n }\n enumValues { name description }\n possibleTypes { kind name }\n }\n }\n}`;\n\nexport type GraphQlOperationKind = 'mutation' | 'query' | 'subscription';\n\ntype DataContractRecord = Record<string, DataContractValue>;\n\nexport interface GraphQlIntrospectionTypeRef {\n readonly kind: string;\n readonly name?: string | null;\n readonly ofType?: GraphQlIntrospectionTypeRef | null;\n}\n\nexport interface GraphQlIntrospectionInputValue {\n readonly name: string;\n readonly description?: string | null;\n readonly type: GraphQlIntrospectionTypeRef;\n readonly defaultValue?: string | null;\n}\n\nexport interface GraphQlIntrospectionField {\n readonly name: string;\n readonly description?: string | null;\n readonly args?: readonly GraphQlIntrospectionInputValue[] | null;\n readonly type: GraphQlIntrospectionTypeRef;\n}\n\nexport interface GraphQlIntrospectionEnumValue {\n readonly name: string;\n readonly description?: string | null;\n}\n\nexport interface GraphQlIntrospectionType {\n readonly kind: string;\n readonly name?: string | null;\n readonly description?: string | null;\n readonly fields?: readonly GraphQlIntrospectionField[] | null;\n readonly inputFields?: readonly GraphQlIntrospectionInputValue[] | null;\n readonly enumValues?: readonly GraphQlIntrospectionEnumValue[] | null;\n readonly possibleTypes?: readonly GraphQlIntrospectionTypeRef[] | null;\n}\n\nexport interface GraphQlIntrospectionSchema {\n readonly queryType?: { readonly name?: string | null } | null;\n readonly mutationType?: { readonly name?: string | null } | null;\n readonly subscriptionType?: { readonly name?: string | null } | null;\n readonly types?: readonly GraphQlIntrospectionType[] | null;\n}\n\nexport interface GraphQlIntrospectionResult {\n readonly __schema?: GraphQlIntrospectionSchema;\n}\n\nexport interface GraphQlOperationDefinition {\n readonly id: OperationId;\n readonly kind: GraphQlOperationKind;\n readonly name?: string;\n readonly description?: string;\n readonly document?: string;\n readonly variables?: DataSchema;\n readonly response?: DataSchema;\n readonly selectionPath?: string;\n readonly metadata?: DataContractValue;\n}\n\nexport interface GraphQlDataSourceDefinition {\n readonly id: string;\n readonly endpointUrl: string;\n readonly name?: string;\n readonly description?: string;\n readonly credential?: CredentialRef;\n readonly introspection?: GraphQlIntrospectionResult;\n readonly introspectionEnabled?: boolean;\n readonly schemaVersion?: string;\n readonly operations?: readonly GraphQlOperationDefinition[];\n readonly metadata?: DataContractValue;\n}\n\nexport interface GraphQlIntrospectionRequest {\n readonly query: typeof GRAPHQL_INTROSPECTION_QUERY;\n readonly operationName: 'AnkhorageGraphQlIntrospection';\n}\n\nexport function createGraphQlIntrospectionRequest(): GraphQlIntrospectionRequest {\n return {\n query: GRAPHQL_INTROSPECTION_QUERY,\n operationName: 'AnkhorageGraphQlIntrospection',\n };\n}\n\nexport function normalizeGraphQlOperationId(kind: GraphQlOperationKind, name: string): OperationId {\n const normalizedName = name\n .replace(/[^A-Za-z0-9]+/g, '-')\n .replace(/^-+|-+$/g, '')\n .toLowerCase();\n\n return normalizedName.length > 0 ? `${kind}.${normalizedName}` : `${kind}.operation`;\n}\n\nexport function createGraphQlDataSource(\n definition: GraphQlDataSourceDefinition,\n): DataSourceDiagnosticResult<GraphQlDataSourceConfig> {\n const diagnostics = validateGraphQlDataSource(definition);\n const hasErrors = diagnostics.some((diagnostic) => diagnostic.severity === 'error');\n\n if (hasErrors) return { ok: false, diagnostics };\n\n return {\n ok: true,\n data: normalizeGraphQlDataSource(definition),\n diagnostics,\n };\n}\n\nexport function validateGraphQlDataSource(\n definition: GraphQlDataSourceDefinition,\n): readonly DataSourceDiagnostic[] {\n const diagnostics: DataSourceDiagnostic[] = [];\n\n if (definition.endpointUrl.trim().length === 0) {\n diagnostics.push({\n code: 'invalid-config',\n dataSourceId: definition.id,\n message: 'GraphQL data source requires a non-empty endpointUrl.',\n path: 'endpointUrl',\n severity: 'error',\n });\n }\n\n if (definition.introspectionEnabled === false && definition.introspection !== undefined) {\n diagnostics.push({\n code: 'invalid-config',\n dataSourceId: definition.id,\n message: 'GraphQL introspection data was provided while introspection is disabled.',\n path: 'introspection',\n severity: 'warning',\n });\n }\n\n if (definition.introspectionEnabled !== false && definition.introspection === undefined) {\n diagnostics.push({\n code: 'missing-schema',\n dataSourceId: definition.id,\n message:\n 'GraphQL introspection result was not provided. Manual operations can still be used.',\n path: 'introspection',\n severity: 'info',\n });\n }\n\n return diagnostics;\n}\n\nexport function normalizeGraphQlDataSource(\n definition: GraphQlDataSourceDefinition,\n): GraphQlDataSourceConfig {\n const schemas = normalizeGraphQlIntrospectionSchemas(definition.introspection);\n const introspectionOperations = normalizeGraphQlIntrospectionOperations(definition.introspection);\n const manualOperations = definition.operations ?? [];\n const operations: Record<OperationId, DataOperationConfig> = {};\n\n for (const operation of [...introspectionOperations, ...manualOperations]) {\n operations[operation.id] = normalizeGraphQlOperation(operation);\n }\n\n const endpoint: DataEndpointConfig = {\n id: 'graphql',\n kind: 'graphql',\n baseUrl: definition.endpointUrl,\n credential: definition.credential,\n operations,\n metadata: {\n source: 'graphql',\n },\n };\n\n return {\n id: definition.id,\n kind: 'graphql',\n name: definition.name,\n description: definition.description,\n endpointUrl: definition.endpointUrl,\n credential: definition.credential,\n endpoints: {\n graphql: endpoint,\n },\n schemas,\n introspection: {\n enabled: definition.introspectionEnabled ?? definition.introspection !== undefined,\n schemaVersion: definition.schemaVersion,\n },\n metadata: definition.metadata,\n };\n}\n\nexport function normalizeGraphQlIntrospectionSchemas(\n introspection: GraphQlIntrospectionResult | undefined,\n): DataSchemaRegistry | undefined {\n const types = introspection?.__schema?.types?.filter(isNamedGraphQlType) ?? [];\n if (types.length === 0) return undefined;\n\n const schemas: Record<string, DataSchema> = {};\n\n for (const type of types) {\n if (type.name === undefined || type.name === null || type.name.startsWith('__')) continue;\n schemas[type.name] = normalizeGraphQlType(type);\n }\n\n return schemas;\n}\n\nexport function normalizeGraphQlIntrospectionOperations(\n introspection: GraphQlIntrospectionResult | undefined,\n): readonly GraphQlOperationDefinition[] {\n const schema = introspection?.__schema;\n if (schema === undefined) return [];\n\n const types = schema.types?.filter(isNamedGraphQlType) ?? [];\n const operations: GraphQlOperationDefinition[] = [];\n\n appendRootOperations(operations, 'query', schema.queryType?.name, types);\n appendRootOperations(operations, 'mutation', schema.mutationType?.name, types);\n appendRootOperations(operations, 'subscription', schema.subscriptionType?.name, types);\n\n return operations;\n}\n\nfunction appendRootOperations(\n operations: GraphQlOperationDefinition[],\n kind: GraphQlOperationKind,\n rootTypeName: string | null | undefined,\n types: readonly GraphQlIntrospectionType[],\n): void {\n if (rootTypeName === undefined || rootTypeName === null) return;\n\n const rootType = types.find((type) => type.name === rootTypeName);\n for (const field of rootType?.fields ?? []) {\n operations.push({\n id: normalizeGraphQlOperationId(kind, field.name),\n kind,\n name: field.name,\n description: field.description ?? undefined,\n variables: normalizeGraphQlVariablesSchema(field.args ?? []),\n response: normalizeGraphQlTypeRef(field.type),\n selectionPath: `$.data.${field.name}`,\n metadata: {\n rootType: rootTypeName,\n source: 'introspection',\n },\n });\n }\n}\n\nfunction normalizeGraphQlOperation(operation: GraphQlOperationDefinition): DataOperationConfig {\n const response: DataOperationResponse | undefined =\n operation.response === undefined\n ? undefined\n : {\n schema: operation.response,\n };\n\n return {\n id: operation.id,\n endpointId: 'graphql',\n name: operation.name,\n description: operation.description,\n protocol: 'graphql',\n intent: mapGraphQlOperationKindToIntent(operation.kind),\n request: {\n schema: operation.variables,\n },\n response,\n metadata: createGraphQlOperationMetadata(operation),\n };\n}\n\nfunction mapGraphQlOperationKindToIntent(kind: GraphQlOperationKind): DataOperationIntent {\n if (kind === 'query' || kind === 'subscription') return 'read';\n return 'action';\n}\n\nfunction normalizeGraphQlVariablesSchema(\n args: readonly GraphQlIntrospectionInputValue[],\n): DataSchema {\n const properties: Record<string, DataSchema> = {};\n const required: string[] = [];\n\n for (const arg of args) {\n properties[arg.name] = {\n ...normalizeGraphQlTypeRef(arg.type),\n description: arg.description ?? undefined,\n default: arg.defaultValue ?? undefined,\n };\n if (isGraphQlNonNull(arg.type)) required.push(arg.name);\n }\n\n return {\n type: 'object',\n required: required.length > 0 ? required : undefined,\n properties,\n };\n}\n\nfunction normalizeGraphQlType(type: GraphQlIntrospectionType): DataSchema {\n if (type.kind === 'OBJECT' || type.kind === 'INTERFACE' || type.kind === 'INPUT_OBJECT') {\n return normalizeGraphQlObjectType(type);\n }\n\n if (type.kind === 'ENUM') {\n return {\n type: 'string',\n title: type.name ?? undefined,\n description: type.description ?? undefined,\n enum: type.enumValues?.map((value) => value.name),\n };\n }\n\n if (type.kind === 'SCALAR') {\n return {\n ...normalizeGraphQlNamedScalar(type.name),\n title: type.name ?? undefined,\n description: type.description ?? undefined,\n };\n }\n\n if (type.kind === 'UNION') {\n return {\n title: type.name ?? undefined,\n description: type.description ?? undefined,\n anyOf: type.possibleTypes?.map((possibleType) => normalizeGraphQlTypeRef(possibleType)),\n };\n }\n\n return {\n title: type.name ?? undefined,\n description: type.description ?? undefined,\n };\n}\n\nfunction normalizeGraphQlObjectType(type: GraphQlIntrospectionType): DataSchema {\n const fields = type.kind === 'INPUT_OBJECT' ? type.inputFields : type.fields;\n const properties: Record<string, DataSchema> = {};\n const required: string[] = [];\n\n for (const field of fields ?? []) {\n const fieldType = 'type' in field ? field.type : undefined;\n if (fieldType === undefined) continue;\n\n properties[field.name] = {\n ...normalizeGraphQlTypeRef(fieldType),\n description: field.description ?? undefined,\n };\n\n if (isGraphQlNonNull(fieldType)) required.push(field.name);\n }\n\n return {\n type: 'object',\n title: type.name ?? undefined,\n description: type.description ?? undefined,\n required: required.length > 0 ? required : undefined,\n properties,\n };\n}\n\nfunction normalizeGraphQlTypeRef(type: GraphQlIntrospectionTypeRef): DataSchema {\n if (type.kind === 'NON_NULL' && type.ofType !== undefined && type.ofType !== null) {\n return {\n ...normalizeGraphQlTypeRef(type.ofType),\n nullable: false,\n };\n }\n\n if (type.kind === 'LIST' && type.ofType !== undefined && type.ofType !== null) {\n return {\n type: 'array',\n items: normalizeGraphQlTypeRef(type.ofType),\n };\n }\n\n if (type.kind === 'SCALAR') {\n return normalizeGraphQlNamedScalar(type.name);\n }\n\n if (type.name !== undefined && type.name !== null) {\n return { ref: { id: type.name } };\n }\n\n return {};\n}\n\nfunction normalizeGraphQlNamedScalar(name: string | null | undefined): DataSchema {\n if (name === 'Boolean') return { type: 'boolean' };\n if (name === 'Float') return { type: 'number' };\n if (name === 'ID' || name === 'String') return { type: 'string' };\n if (name === 'Int') return { type: 'integer' };\n\n return {\n type: 'string',\n format: name ?? undefined,\n };\n}\n\nfunction isGraphQlNonNull(type: GraphQlIntrospectionTypeRef): boolean {\n return type.kind === 'NON_NULL';\n}\n\nfunction isNamedGraphQlType(type: GraphQlIntrospectionType): boolean {\n return type.name !== undefined && type.name !== null;\n}\n\nfunction createGraphQlOperationMetadata(operation: GraphQlOperationDefinition): DataContractRecord {\n const metadata = toMetadataRecord(operation.metadata);\n metadata.kind = operation.kind;\n\n if (operation.document !== undefined) {\n metadata.document = operation.document;\n }\n\n if (operation.selectionPath !== undefined) {\n metadata.selectionPath = operation.selectionPath;\n }\n\n return metadata;\n}\n\nfunction toMetadataRecord(value: DataContractValue | undefined): DataContractRecord {\n if (!isDataContractRecord(value)) return {};\n\n const metadata: DataContractRecord = {};\n for (const [key, item] of Object.entries(value)) {\n metadata[key] = item;\n }\n\n return metadata;\n}\n\nfunction isDataContractRecord(value: DataContractValue | undefined): value is DataContractRecord {\n return (\n value !== undefined && typeof value === 'object' && value !== null && !Array.isArray(value)\n );\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,7 @@
1
1
  import type { DataSourceConfig, DataSourceKind } from '@ankhorage/contracts/data';
2
+ export * from './graphql';
3
+ export * from './openapi';
4
+ export * from './rest';
2
5
  export declare const DATA_SOURCES_PACKAGE_NAME: "@ankhorage/data-sources";
3
6
  export declare const SUPPORTED_DATA_SOURCE_KINDS: readonly ["database", "graphql", "managed-api", "openapi", "rest"];
4
7
  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,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,6 @@
1
+ export * from './graphql';
2
+ export * from './openapi';
3
+ export * from './rest';
1
4
  export const DATA_SOURCES_PACKAGE_NAME = '@ankhorage/data-sources';
2
5
  export const SUPPORTED_DATA_SOURCE_KINDS = [
3
6
  '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,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 './graphql';\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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