@ankhorage/data-sources 0.1.0 → 0.3.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 +9 -1
- package/dist/graphql/index.d.ts +83 -0
- package/dist/graphql/index.d.ts.map +1 -0
- package/dist/graphql/index.js +327 -0
- package/dist/graphql/index.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/managed-api/index.d.ts +30 -0
- package/dist/managed-api/index.d.ts.map +1 -0
- package/dist/managed-api/index.js +257 -0
- package/dist/managed-api/index.js.map +1 -0
- package/package.json +1 -1
- package/src/graphql/index.test.ts +202 -0
- package/src/graphql/index.ts +486 -0
- package/src/index.ts +2 -0
- package/src/managed-api/index.test.ts +181 -0
- package/src/managed-api/index.ts +364 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @ankhorage/data-sources
|
|
2
2
|
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- f4266e8: Add managed API generation helpers that derive normalized database endpoint and CRUD operation configs from provider-neutral adapter references and collection definitions.
|
|
8
|
+
|
|
9
|
+
## 0.2.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- 504dc55: Add dependency-free GraphQL introspection normalization helpers and serializable GraphQL operation modeling.
|
|
14
|
+
|
|
3
15
|
## 0.1.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
# @ankhorage/data-sources
|
|
5
5
|
|
|
6
|
-
         
|
|
7
7
|
|
|
8
8
|
Provider-neutral data source and endpoint system for APIs, databases, and runtime bindings.
|
|
9
9
|
|
|
@@ -15,9 +15,13 @@ 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
|
+
- [createManagedApiResourceSchema sequence](././paradox/diagrams/sequences/create-managed-api-resource-schema.mmd)
|
|
18
19
|
- [createManualRestDataSource sequence](././paradox/diagrams/sequences/create-manual-rest-data-source.mmd)
|
|
20
|
+
- [normalizeGraphQlIntrospectionOperations sequence](././paradox/diagrams/sequences/normalize-graph-ql-introspection-operations.mmd)
|
|
21
|
+
- [normalizeGraphQlIntrospectionSchemas sequence](././paradox/diagrams/sequences/normalize-graph-ql-introspection-schemas.mmd)
|
|
19
22
|
- [normalizeManualRestDataSource sequence](././paradox/diagrams/sequences/normalize-manual-rest-data-source.mmd)
|
|
20
23
|
- [normalizeOpenApiSchema sequence](././paradox/diagrams/sequences/normalize-open-api-schema.mmd)
|
|
24
|
+
- [validateManagedApiDefinition sequence](././paradox/diagrams/sequences/validate-managed-api-definition.mmd)
|
|
21
25
|
- [validateManualRestDataSource sequence](././paradox/diagrams/sequences/validate-manual-rest-data-source.mmd)
|
|
22
26
|
|
|
23
27
|
## Architecture preview
|
|
@@ -30,7 +34,11 @@ graph TD
|
|
|
30
34
|
package__ankhorage_data_sources["@ankhorage/data-sources"]
|
|
31
35
|
entrypoint_src_index_ts["src/index.ts"]
|
|
32
36
|
package__ankhorage_data_sources --> entrypoint_src_index_ts
|
|
37
|
+
module_src_graphql_index_ts["src/graphql/index.ts"]
|
|
38
|
+
package__ankhorage_data_sources -.-> module_src_graphql_index_ts
|
|
33
39
|
module_src_index_ts["src/index.ts"]
|
|
40
|
+
module_src_managed_api_index_ts["src/managed-api/index.ts"]
|
|
41
|
+
package__ankhorage_data_sources -.-> module_src_managed_api_index_ts
|
|
34
42
|
module_src_openapi_index_ts["src/openapi/index.ts"]
|
|
35
43
|
package__ankhorage_data_sources -.-> module_src_openapi_index_ts
|
|
36
44
|
module_src_rest_index_ts["src/rest/index.ts"]
|
|
@@ -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,CAA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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,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\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,6 @@
|
|
|
1
1
|
import type { DataSourceConfig, DataSourceKind } from '@ankhorage/contracts/data';
|
|
2
|
+
export * from './graphql';
|
|
3
|
+
export * from './managed-api';
|
|
2
4
|
export * from './openapi';
|
|
3
5
|
export * from './rest';
|
|
4
6
|
export declare const DATA_SOURCES_PACKAGE_NAME: "@ankhorage/data-sources";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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,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"}
|
|
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,eAAe,CAAC;AAC9B,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
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AAEvB,MAAM,CAAC,MAAM,yBAAyB,GAAG,yBAAkC,CAAC;AAE5E,MAAM,CAAC,MAAM,2BAA2B,GAAG;IACzC,UAAU;IACV,SAAS;IACT,aAAa;IACb,SAAS;IACT,MAAM;CACsC,CAAC;AAO/C,MAAM,UAAU,yBAAyB;IACvC,OAAO;QACL,WAAW,EAAE,yBAAyB;QACtC,cAAc,EAAE,2BAA2B;KAC5C,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,yBAAyB,CAAC,IAAY;IACpD,OAAO,2BAA2B,CAAC,IAAI,CAAC,CAAC,aAAa,EAAE,EAAE,CAAC,aAAa,KAAK,IAAI,CAAC,CAAC;AACrF,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,MAAwB;IACxD,OAAO,MAAM,CAAC,IAAI,CAAC;AACrB,CAAC","sourcesContent":["import type { DataSourceConfig, DataSourceKind } from '@ankhorage/contracts/data';\n\nexport * from './openapi';\nexport * from './rest';\n\nexport const DATA_SOURCES_PACKAGE_NAME = '@ankhorage/data-sources' as const;\n\nexport const SUPPORTED_DATA_SOURCE_KINDS = [\n 'database',\n 'graphql',\n 'managed-api',\n 'openapi',\n 'rest',\n] as const satisfies readonly DataSourceKind[];\n\nexport interface DataSourcesPackageInfo {\n readonly packageName: typeof DATA_SOURCES_PACKAGE_NAME;\n readonly supportedKinds: typeof SUPPORTED_DATA_SOURCE_KINDS;\n}\n\nexport function getDataSourcesPackageInfo(): DataSourcesPackageInfo {\n return {\n packageName: DATA_SOURCES_PACKAGE_NAME,\n supportedKinds: SUPPORTED_DATA_SOURCE_KINDS,\n };\n}\n\nexport function isSupportedDataSourceKind(kind: string): kind is DataSourceKind {\n return SUPPORTED_DATA_SOURCE_KINDS.some((supportedKind) => supportedKind === kind);\n}\n\nexport function getDataSourceKind(source: DataSourceConfig): DataSourceKind {\n return source.kind;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,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 './managed-api';\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,30 @@
|
|
|
1
|
+
import type { AdapterRef, DataEndpointConfig, DataOperationConfig, DataSchema, DataSourceDiagnostic, DataSourceDiagnosticResult, ManagedApiDataSourceConfig, OperationId } from '@ankhorage/contracts/data';
|
|
2
|
+
import type { DbCollectionDefinition } from '@ankhorage/contracts/db';
|
|
3
|
+
export declare const MANAGED_API_CRUD_OPERATIONS: readonly ["list", "read", "create", "update", "delete"];
|
|
4
|
+
export type ManagedApiCrudOperation = (typeof MANAGED_API_CRUD_OPERATIONS)[number];
|
|
5
|
+
export interface ManagedApiOperationPolicyRef {
|
|
6
|
+
readonly id: string;
|
|
7
|
+
readonly operation?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface ManagedApiGenerationResourceDefinition {
|
|
10
|
+
readonly name: string;
|
|
11
|
+
readonly collection: DbCollectionDefinition;
|
|
12
|
+
readonly operations?: readonly ManagedApiCrudOperation[];
|
|
13
|
+
readonly policies?: readonly ManagedApiOperationPolicyRef[];
|
|
14
|
+
}
|
|
15
|
+
export interface ManagedApiGenerationDefinition {
|
|
16
|
+
readonly id: string;
|
|
17
|
+
readonly adapter: AdapterRef;
|
|
18
|
+
readonly name?: string;
|
|
19
|
+
readonly description?: string;
|
|
20
|
+
readonly resources: readonly ManagedApiGenerationResourceDefinition[];
|
|
21
|
+
}
|
|
22
|
+
export declare function createManagedApiDataSource(definition: ManagedApiGenerationDefinition): DataSourceDiagnosticResult<ManagedApiDataSourceConfig>;
|
|
23
|
+
export declare function validateManagedApiDefinition(definition: ManagedApiGenerationDefinition): readonly DataSourceDiagnostic[];
|
|
24
|
+
export declare function normalizeManagedApiDataSource(definition: ManagedApiGenerationDefinition): ManagedApiDataSourceConfig;
|
|
25
|
+
export declare function createManagedApiEndpoint(definition: ManagedApiGenerationDefinition, resource: ManagedApiGenerationResourceDefinition, operations?: readonly ManagedApiCrudOperation[]): DataEndpointConfig;
|
|
26
|
+
export declare function createManagedApiOperation(definition: ManagedApiGenerationDefinition, resource: ManagedApiGenerationResourceDefinition, operation: ManagedApiCrudOperation): DataOperationConfig;
|
|
27
|
+
export declare function getManagedApiOperations(resource: ManagedApiGenerationResourceDefinition): readonly ManagedApiCrudOperation[];
|
|
28
|
+
export declare function createManagedApiOperationId(resourceName: string, operation: ManagedApiCrudOperation): OperationId;
|
|
29
|
+
export declare function createManagedApiResourceSchema(collection: DbCollectionDefinition): DataSchema;
|
|
30
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/managed-api/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EAEV,kBAAkB,EAClB,mBAAmB,EAGnB,UAAU,EACV,oBAAoB,EACpB,0BAA0B,EAC1B,0BAA0B,EAE1B,WAAW,EACZ,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EACV,sBAAsB,EAGvB,MAAM,yBAAyB,CAAC;AAEjC,eAAO,MAAM,2BAA2B,yDAA0D,CAAC;AAEnG,MAAM,MAAM,uBAAuB,GAAG,CAAC,OAAO,2BAA2B,CAAC,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