@ankhorage/contracts 1.8.0 → 1.10.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/dist/data/diagnostics.d.ts +22 -0
- package/dist/data/diagnostics.d.ts.map +1 -0
- package/dist/data/diagnostics.js +2 -0
- package/dist/data/diagnostics.js.map +1 -0
- package/dist/data/endpoints.d.ts +18 -0
- package/dist/data/endpoints.d.ts.map +1 -0
- package/dist/data/endpoints.js +2 -0
- package/dist/data/endpoints.js.map +1 -0
- package/dist/data/ids.d.ts +7 -0
- package/dist/data/ids.d.ts.map +1 -0
- package/dist/data/ids.js +2 -0
- package/dist/data/ids.js.map +1 -0
- package/dist/data/index.d.ts +9 -0
- package/dist/data/index.d.ts.map +1 -0
- package/dist/data/index.js +9 -0
- package/dist/data/index.js.map +1 -0
- package/dist/data/operations.d.ts +49 -0
- package/dist/data/operations.d.ts.map +1 -0
- package/dist/data/operations.js +2 -0
- package/dist/data/operations.js.map +1 -0
- package/dist/data/refs.d.ts +18 -0
- package/dist/data/refs.d.ts.map +1 -0
- package/dist/data/refs.js +2 -0
- package/dist/data/refs.js.map +1 -0
- package/dist/data/schemas.d.ts +34 -0
- package/dist/data/schemas.d.ts.map +1 -0
- package/dist/data/schemas.js +2 -0
- package/dist/data/schemas.js.map +1 -0
- package/dist/data/sources.d.ts +57 -0
- package/dist/data/sources.d.ts.map +1 -0
- package/dist/data/sources.js +2 -0
- package/dist/data/sources.js.map +1 -0
- package/dist/data/values.d.ts +5 -0
- package/dist/data/values.d.ts.map +1 -0
- package/dist/data/values.js +2 -0
- package/dist/data/values.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/ui.d.ts +72 -0
- package/dist/ui.d.ts.map +1 -0
- package/dist/ui.js +2 -0
- package/dist/ui.js.map +1 -0
- package/package.json +9 -1
- package/src/data/data.test.ts +305 -0
- package/src/data/diagnostics.ts +41 -0
- package/src/data/endpoints.ts +20 -0
- package/src/data/ids.ts +6 -0
- package/src/data/index.ts +8 -0
- package/src/data/operations.ts +66 -0
- package/src/data/refs.ts +21 -0
- package/src/data/schemas.ts +46 -0
- package/src/data/sources.ts +72 -0
- package/src/data/values.ts +11 -0
- package/src/index.ts +2 -0
- package/src/ui.test.ts +193 -0
- package/src/ui.ts +113 -0
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
import { describe, expect, it } from 'bun:test';
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
DataSourceConfig,
|
|
5
|
+
DataSourceDiagnostic,
|
|
6
|
+
GraphQlDataSourceConfig,
|
|
7
|
+
ManagedApiDataSourceConfig,
|
|
8
|
+
OpenApiDataSourceConfig,
|
|
9
|
+
RestDataSourceConfig,
|
|
10
|
+
} from './index';
|
|
11
|
+
|
|
12
|
+
function assertSerializable<TValue>(value: TValue): void {
|
|
13
|
+
expect(JSON.parse(JSON.stringify(value))).toEqual(value);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
describe('data source contracts', () => {
|
|
17
|
+
it('serializes a manual REST data source with read and create operations', () => {
|
|
18
|
+
const source: RestDataSourceConfig = {
|
|
19
|
+
id: 'cms-rest',
|
|
20
|
+
kind: 'rest',
|
|
21
|
+
name: 'CMS REST API',
|
|
22
|
+
baseUrl: 'https://cms.example.com',
|
|
23
|
+
credential: {
|
|
24
|
+
id: 'cms-api-key',
|
|
25
|
+
kind: 'apiKey',
|
|
26
|
+
label: 'CMS API key',
|
|
27
|
+
},
|
|
28
|
+
schemas: {
|
|
29
|
+
post: {
|
|
30
|
+
type: 'object',
|
|
31
|
+
required: ['id', 'title'],
|
|
32
|
+
properties: {
|
|
33
|
+
id: { type: 'string' },
|
|
34
|
+
title: { type: 'string' },
|
|
35
|
+
published: { type: 'boolean', default: false },
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
endpoints: {
|
|
40
|
+
posts: {
|
|
41
|
+
id: 'posts',
|
|
42
|
+
kind: 'http',
|
|
43
|
+
path: '/posts',
|
|
44
|
+
operations: {
|
|
45
|
+
'posts.list': {
|
|
46
|
+
id: 'posts.list',
|
|
47
|
+
endpointId: 'posts',
|
|
48
|
+
protocol: 'http',
|
|
49
|
+
intent: 'read',
|
|
50
|
+
method: 'GET',
|
|
51
|
+
path: '/posts',
|
|
52
|
+
request: {
|
|
53
|
+
parameters: [
|
|
54
|
+
{
|
|
55
|
+
name: 'limit',
|
|
56
|
+
location: 'query',
|
|
57
|
+
schema: { type: 'integer', default: 20 },
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
},
|
|
61
|
+
response: {
|
|
62
|
+
status: 200,
|
|
63
|
+
schema: {
|
|
64
|
+
type: 'array',
|
|
65
|
+
items: { ref: { id: 'post' } },
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
pagination: {
|
|
69
|
+
kind: 'limit-offset',
|
|
70
|
+
limitParameter: 'limit',
|
|
71
|
+
offsetParameter: 'offset',
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
'posts.create': {
|
|
75
|
+
id: 'posts.create',
|
|
76
|
+
endpointId: 'posts',
|
|
77
|
+
protocol: 'http',
|
|
78
|
+
intent: 'create',
|
|
79
|
+
method: 'POST',
|
|
80
|
+
path: '/posts',
|
|
81
|
+
request: {
|
|
82
|
+
contentType: 'application/json',
|
|
83
|
+
schema: { ref: { id: 'post' } },
|
|
84
|
+
},
|
|
85
|
+
response: {
|
|
86
|
+
status: 201,
|
|
87
|
+
schemaRef: { id: 'post' },
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
assertSerializable(source);
|
|
96
|
+
expect(source.endpoints.posts?.operations['posts.list']?.intent).toBe('read');
|
|
97
|
+
expect(source.endpoints.posts?.operations['posts.create']?.intent).toBe('create');
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('serializes an imported OpenAPI data source', () => {
|
|
101
|
+
const source: OpenApiDataSourceConfig = {
|
|
102
|
+
id: 'shop-openapi',
|
|
103
|
+
kind: 'openapi',
|
|
104
|
+
name: 'Shop OpenAPI',
|
|
105
|
+
baseUrl: 'https://shop.example.com/api',
|
|
106
|
+
import: {
|
|
107
|
+
url: 'https://shop.example.com/openapi.json',
|
|
108
|
+
version: '2026-05-19',
|
|
109
|
+
},
|
|
110
|
+
endpoints: {
|
|
111
|
+
products: {
|
|
112
|
+
id: 'products',
|
|
113
|
+
kind: 'http',
|
|
114
|
+
path: '/products/{productId}',
|
|
115
|
+
operations: {
|
|
116
|
+
getProduct: {
|
|
117
|
+
id: 'getProduct',
|
|
118
|
+
endpointId: 'products',
|
|
119
|
+
protocol: 'http',
|
|
120
|
+
intent: 'read',
|
|
121
|
+
method: 'GET',
|
|
122
|
+
path: '/products/{productId}',
|
|
123
|
+
request: {
|
|
124
|
+
parameters: [
|
|
125
|
+
{
|
|
126
|
+
name: 'productId',
|
|
127
|
+
location: 'path',
|
|
128
|
+
required: true,
|
|
129
|
+
schema: { type: 'string' },
|
|
130
|
+
},
|
|
131
|
+
],
|
|
132
|
+
},
|
|
133
|
+
response: {
|
|
134
|
+
status: 200,
|
|
135
|
+
schema: {
|
|
136
|
+
type: 'object',
|
|
137
|
+
properties: {
|
|
138
|
+
id: { type: 'string' },
|
|
139
|
+
name: { type: 'string' },
|
|
140
|
+
price: { type: 'number' },
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
assertSerializable(source);
|
|
151
|
+
expect(source.import?.url).toContain('openapi.json');
|
|
152
|
+
expect(
|
|
153
|
+
source.endpoints.products?.operations.getProduct?.request?.parameters?.[0]?.location,
|
|
154
|
+
).toBe('path');
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it('serializes a GraphQL data source with query and mutation operations', () => {
|
|
158
|
+
const source: GraphQlDataSourceConfig = {
|
|
159
|
+
id: 'content-graphql',
|
|
160
|
+
kind: 'graphql',
|
|
161
|
+
endpointUrl: 'https://content.example.com/graphql',
|
|
162
|
+
introspection: {
|
|
163
|
+
enabled: true,
|
|
164
|
+
schemaVersion: '2026-05-19',
|
|
165
|
+
},
|
|
166
|
+
endpoints: {
|
|
167
|
+
graphql: {
|
|
168
|
+
id: 'graphql',
|
|
169
|
+
kind: 'graphql',
|
|
170
|
+
operations: {
|
|
171
|
+
PostsQuery: {
|
|
172
|
+
id: 'PostsQuery',
|
|
173
|
+
endpointId: 'graphql',
|
|
174
|
+
protocol: 'graphql',
|
|
175
|
+
intent: 'read',
|
|
176
|
+
request: {
|
|
177
|
+
schema: {
|
|
178
|
+
type: 'object',
|
|
179
|
+
properties: {
|
|
180
|
+
search: { type: 'string' },
|
|
181
|
+
},
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
response: {
|
|
185
|
+
schema: {
|
|
186
|
+
type: 'object',
|
|
187
|
+
properties: {
|
|
188
|
+
posts: {
|
|
189
|
+
type: 'array',
|
|
190
|
+
items: { type: 'object' },
|
|
191
|
+
},
|
|
192
|
+
},
|
|
193
|
+
},
|
|
194
|
+
},
|
|
195
|
+
},
|
|
196
|
+
CreatePost: {
|
|
197
|
+
id: 'CreatePost',
|
|
198
|
+
endpointId: 'graphql',
|
|
199
|
+
protocol: 'graphql',
|
|
200
|
+
intent: 'create',
|
|
201
|
+
request: {
|
|
202
|
+
schema: {
|
|
203
|
+
type: 'object',
|
|
204
|
+
required: ['title'],
|
|
205
|
+
properties: {
|
|
206
|
+
title: { type: 'string' },
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
response: {
|
|
211
|
+
schema: {
|
|
212
|
+
type: 'object',
|
|
213
|
+
properties: {
|
|
214
|
+
createPost: { type: 'object' },
|
|
215
|
+
},
|
|
216
|
+
},
|
|
217
|
+
},
|
|
218
|
+
},
|
|
219
|
+
},
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
assertSerializable(source);
|
|
225
|
+
expect(source.endpoints.graphql?.operations.PostsQuery?.protocol).toBe('graphql');
|
|
226
|
+
expect(source.endpoints.graphql?.operations.CreatePost?.intent).toBe('create');
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
it('serializes a managed API backed by a database adapter reference', () => {
|
|
230
|
+
const source: ManagedApiDataSourceConfig = {
|
|
231
|
+
id: 'app-managed-api',
|
|
232
|
+
kind: 'managed-api',
|
|
233
|
+
name: 'App managed API',
|
|
234
|
+
adapter: {
|
|
235
|
+
id: 'primary-db',
|
|
236
|
+
kind: 'database',
|
|
237
|
+
packageName: '@ankhorage/supabase-db',
|
|
238
|
+
},
|
|
239
|
+
resources: [
|
|
240
|
+
{
|
|
241
|
+
name: 'posts',
|
|
242
|
+
collection: {
|
|
243
|
+
name: 'posts',
|
|
244
|
+
schema: 'public',
|
|
245
|
+
primaryKey: 'id',
|
|
246
|
+
fields: [
|
|
247
|
+
{ name: 'id', type: 'uuid', required: true, unique: true },
|
|
248
|
+
{ name: 'title', type: 'text', required: true },
|
|
249
|
+
{ name: 'published', type: 'boolean', defaultValue: false },
|
|
250
|
+
],
|
|
251
|
+
},
|
|
252
|
+
operations: ['list', 'read', 'create', 'update', 'delete'],
|
|
253
|
+
},
|
|
254
|
+
],
|
|
255
|
+
endpoints: {
|
|
256
|
+
posts: {
|
|
257
|
+
id: 'posts',
|
|
258
|
+
kind: 'database',
|
|
259
|
+
operations: {
|
|
260
|
+
'posts.list': {
|
|
261
|
+
id: 'posts.list',
|
|
262
|
+
endpointId: 'posts',
|
|
263
|
+
protocol: 'database',
|
|
264
|
+
intent: 'read',
|
|
265
|
+
},
|
|
266
|
+
'posts.delete': {
|
|
267
|
+
id: 'posts.delete',
|
|
268
|
+
endpointId: 'posts',
|
|
269
|
+
protocol: 'database',
|
|
270
|
+
intent: 'delete',
|
|
271
|
+
},
|
|
272
|
+
},
|
|
273
|
+
},
|
|
274
|
+
},
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
assertSerializable(source);
|
|
278
|
+
expect(source.adapter.kind).toBe('database');
|
|
279
|
+
expect(source.resources[0]?.collection.fields.map((field) => field.name)).toEqual([
|
|
280
|
+
'id',
|
|
281
|
+
'title',
|
|
282
|
+
'published',
|
|
283
|
+
]);
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
it('accepts a provider-neutral data source registry and diagnostics', () => {
|
|
287
|
+
const source: DataSourceConfig = {
|
|
288
|
+
id: 'public-rest',
|
|
289
|
+
kind: 'rest',
|
|
290
|
+
baseUrl: 'https://public.example.com',
|
|
291
|
+
endpoints: {},
|
|
292
|
+
};
|
|
293
|
+
const diagnostic: DataSourceDiagnostic = {
|
|
294
|
+
code: 'missing-operation',
|
|
295
|
+
severity: 'error',
|
|
296
|
+
message: 'Operation not found.',
|
|
297
|
+
dataSourceId: 'public-rest',
|
|
298
|
+
endpointId: 'posts',
|
|
299
|
+
operationId: 'posts.list',
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
assertSerializable({ source, diagnostic });
|
|
303
|
+
expect(diagnostic.code).toBe('missing-operation');
|
|
304
|
+
});
|
|
305
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { DataSourceId, EndpointId, OperationId } from './ids';
|
|
2
|
+
|
|
3
|
+
export type DataDiagnosticSeverity = 'error' | 'info' | 'warning';
|
|
4
|
+
|
|
5
|
+
export type DataDiagnosticCode =
|
|
6
|
+
| 'ambiguous-server'
|
|
7
|
+
| 'duplicate-operation-id'
|
|
8
|
+
| 'invalid-config'
|
|
9
|
+
| 'missing-adapter'
|
|
10
|
+
| 'missing-credential'
|
|
11
|
+
| 'missing-data-source'
|
|
12
|
+
| 'missing-endpoint'
|
|
13
|
+
| 'missing-operation'
|
|
14
|
+
| 'missing-schema'
|
|
15
|
+
| 'network-error'
|
|
16
|
+
| 'parse-error'
|
|
17
|
+
| 'unsupported-auth-scheme'
|
|
18
|
+
| 'unsupported-schema'
|
|
19
|
+
| (string & {});
|
|
20
|
+
|
|
21
|
+
export interface DataSourceDiagnostic {
|
|
22
|
+
readonly code: DataDiagnosticCode;
|
|
23
|
+
readonly message: string;
|
|
24
|
+
readonly severity: DataDiagnosticSeverity;
|
|
25
|
+
readonly dataSourceId?: DataSourceId;
|
|
26
|
+
readonly endpointId?: EndpointId;
|
|
27
|
+
readonly operationId?: OperationId;
|
|
28
|
+
readonly path?: string;
|
|
29
|
+
readonly hint?: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export type DataSourceDiagnosticResult<TData> =
|
|
33
|
+
| {
|
|
34
|
+
readonly ok: true;
|
|
35
|
+
readonly data: TData;
|
|
36
|
+
readonly diagnostics?: readonly DataSourceDiagnostic[];
|
|
37
|
+
}
|
|
38
|
+
| {
|
|
39
|
+
readonly ok: false;
|
|
40
|
+
readonly diagnostics: readonly DataSourceDiagnostic[];
|
|
41
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { EndpointId, OperationId } from './ids';
|
|
2
|
+
import type { DataOperationConfig } from './operations';
|
|
3
|
+
import type { CredentialRef } from './refs';
|
|
4
|
+
import type { DataContractValue } from './values';
|
|
5
|
+
|
|
6
|
+
export type DataEndpointKind = 'database' | 'graphql' | 'http' | (string & {});
|
|
7
|
+
|
|
8
|
+
export interface DataEndpointConfig {
|
|
9
|
+
readonly id: EndpointId;
|
|
10
|
+
readonly kind: DataEndpointKind;
|
|
11
|
+
readonly name?: string;
|
|
12
|
+
readonly description?: string;
|
|
13
|
+
readonly baseUrl?: string;
|
|
14
|
+
readonly path?: string;
|
|
15
|
+
readonly credential?: CredentialRef;
|
|
16
|
+
readonly operations: Readonly<Record<OperationId, DataOperationConfig>>;
|
|
17
|
+
readonly metadata?: DataContractValue;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export type DataEndpointRegistry = Readonly<Record<EndpointId, DataEndpointConfig>>;
|
package/src/data/ids.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { EndpointId, OperationId } from './ids';
|
|
2
|
+
import type { CredentialRef } from './refs';
|
|
3
|
+
import type { DataSchemaSlot } from './schemas';
|
|
4
|
+
import type { DataContractValue } from './values';
|
|
5
|
+
|
|
6
|
+
export type DataOperationIntent = 'action' | 'create' | 'delete' | 'read' | 'update';
|
|
7
|
+
|
|
8
|
+
export type DataOperationMethod =
|
|
9
|
+
| 'DELETE'
|
|
10
|
+
| 'GET'
|
|
11
|
+
| 'HEAD'
|
|
12
|
+
| 'OPTIONS'
|
|
13
|
+
| 'PATCH'
|
|
14
|
+
| 'POST'
|
|
15
|
+
| 'PUT'
|
|
16
|
+
| (string & {});
|
|
17
|
+
|
|
18
|
+
export type DataOperationProtocol = 'database' | 'graphql' | 'http' | (string & {});
|
|
19
|
+
|
|
20
|
+
export type DataOperationParameterLocation = 'body' | 'cookie' | 'header' | 'path' | 'query';
|
|
21
|
+
|
|
22
|
+
export interface DataOperationParameter extends DataSchemaSlot {
|
|
23
|
+
readonly name: string;
|
|
24
|
+
readonly location: DataOperationParameterLocation;
|
|
25
|
+
readonly required?: boolean;
|
|
26
|
+
readonly description?: string;
|
|
27
|
+
readonly default?: DataContractValue;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface DataOperationRequest extends DataSchemaSlot {
|
|
31
|
+
readonly parameters?: readonly DataOperationParameter[];
|
|
32
|
+
readonly contentType?: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface DataOperationResponse extends DataSchemaSlot {
|
|
36
|
+
readonly status?: number | string;
|
|
37
|
+
readonly contentType?: string;
|
|
38
|
+
readonly description?: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface DataOperationPagination {
|
|
42
|
+
readonly kind: 'cursor' | 'limit-offset' | 'page' | 'unknown' | (string & {});
|
|
43
|
+
readonly cursorPath?: string;
|
|
44
|
+
readonly limitParameter?: string;
|
|
45
|
+
readonly offsetParameter?: string;
|
|
46
|
+
readonly pageParameter?: string;
|
|
47
|
+
readonly pageSizeParameter?: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface DataOperationConfig {
|
|
51
|
+
readonly id: OperationId;
|
|
52
|
+
readonly endpointId?: EndpointId;
|
|
53
|
+
readonly name?: string;
|
|
54
|
+
readonly description?: string;
|
|
55
|
+
readonly protocol: DataOperationProtocol;
|
|
56
|
+
readonly intent: DataOperationIntent;
|
|
57
|
+
readonly method?: DataOperationMethod;
|
|
58
|
+
readonly path?: string;
|
|
59
|
+
readonly request?: DataOperationRequest;
|
|
60
|
+
readonly response?: DataOperationResponse;
|
|
61
|
+
readonly pagination?: DataOperationPagination;
|
|
62
|
+
readonly credential?: CredentialRef;
|
|
63
|
+
readonly metadata?: DataContractValue;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export type DataOperationRegistry = Readonly<Record<OperationId, DataOperationConfig>>;
|
package/src/data/refs.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { AdapterId, CredentialId } from './ids';
|
|
2
|
+
import type { DataContractValue } from './values';
|
|
3
|
+
|
|
4
|
+
export type CredentialKind = 'apiKey' | 'basic' | 'bearer' | 'custom' | 'oauth2';
|
|
5
|
+
|
|
6
|
+
export interface CredentialRef {
|
|
7
|
+
readonly id: CredentialId;
|
|
8
|
+
readonly kind: CredentialKind | (string & {});
|
|
9
|
+
readonly label?: string;
|
|
10
|
+
readonly scope?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type AdapterKind = 'auth' | 'database' | 'storage' | 'transport' | (string & {});
|
|
14
|
+
|
|
15
|
+
export interface AdapterRef {
|
|
16
|
+
readonly id: AdapterId;
|
|
17
|
+
readonly kind: AdapterKind;
|
|
18
|
+
readonly packageName?: string;
|
|
19
|
+
readonly exportName?: string;
|
|
20
|
+
readonly config?: DataContractValue;
|
|
21
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { SchemaId } from './ids';
|
|
2
|
+
import type { DataContractValue } from './values';
|
|
3
|
+
|
|
4
|
+
export type DataSchemaPrimitiveType =
|
|
5
|
+
| 'array'
|
|
6
|
+
| 'boolean'
|
|
7
|
+
| 'integer'
|
|
8
|
+
| 'null'
|
|
9
|
+
| 'number'
|
|
10
|
+
| 'object'
|
|
11
|
+
| 'string';
|
|
12
|
+
|
|
13
|
+
export interface DataSchemaRef {
|
|
14
|
+
readonly id: SchemaId;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface DataSchemaProperty {
|
|
18
|
+
readonly description?: string;
|
|
19
|
+
readonly schema: DataSchema;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface DataSchema {
|
|
23
|
+
readonly type?: DataSchemaPrimitiveType | readonly DataSchemaPrimitiveType[];
|
|
24
|
+
readonly title?: string;
|
|
25
|
+
readonly description?: string;
|
|
26
|
+
readonly enum?: readonly DataContractValue[];
|
|
27
|
+
readonly const?: DataContractValue;
|
|
28
|
+
readonly default?: DataContractValue;
|
|
29
|
+
readonly format?: string;
|
|
30
|
+
readonly nullable?: boolean;
|
|
31
|
+
readonly required?: readonly string[];
|
|
32
|
+
readonly properties?: Readonly<Record<string, DataSchema>>;
|
|
33
|
+
readonly additionalProperties?: boolean | DataSchema;
|
|
34
|
+
readonly items?: DataSchema;
|
|
35
|
+
readonly allOf?: readonly DataSchema[];
|
|
36
|
+
readonly anyOf?: readonly DataSchema[];
|
|
37
|
+
readonly oneOf?: readonly DataSchema[];
|
|
38
|
+
readonly ref?: DataSchemaRef;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export type DataSchemaRegistry = Readonly<Record<SchemaId, DataSchema>>;
|
|
42
|
+
|
|
43
|
+
export interface DataSchemaSlot {
|
|
44
|
+
readonly schema?: DataSchema;
|
|
45
|
+
readonly schemaRef?: DataSchemaRef;
|
|
46
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { DbCollectionDefinition } from '../db';
|
|
2
|
+
import type { DataEndpointRegistry } from './endpoints';
|
|
3
|
+
import type { DataSourceId } from './ids';
|
|
4
|
+
import type { AdapterRef, CredentialRef } from './refs';
|
|
5
|
+
import type { DataSchemaRegistry } from './schemas';
|
|
6
|
+
import type { DataContractValue } from './values';
|
|
7
|
+
|
|
8
|
+
export type DataSourceKind = 'database' | 'graphql' | 'managed-api' | 'openapi' | 'rest';
|
|
9
|
+
|
|
10
|
+
export interface DataSourceBaseConfig {
|
|
11
|
+
readonly id: DataSourceId;
|
|
12
|
+
readonly kind: DataSourceKind;
|
|
13
|
+
readonly name?: string;
|
|
14
|
+
readonly description?: string;
|
|
15
|
+
readonly credential?: CredentialRef;
|
|
16
|
+
readonly endpoints: DataEndpointRegistry;
|
|
17
|
+
readonly schemas?: DataSchemaRegistry;
|
|
18
|
+
readonly metadata?: DataContractValue;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface RestDataSourceConfig extends DataSourceBaseConfig {
|
|
22
|
+
readonly kind: 'rest';
|
|
23
|
+
readonly baseUrl: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface OpenApiImportRef {
|
|
27
|
+
readonly url?: string;
|
|
28
|
+
readonly documentId?: string;
|
|
29
|
+
readonly version?: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface OpenApiDataSourceConfig extends DataSourceBaseConfig {
|
|
33
|
+
readonly kind: 'openapi';
|
|
34
|
+
readonly baseUrl?: string;
|
|
35
|
+
readonly import?: OpenApiImportRef;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface GraphQlDataSourceConfig extends DataSourceBaseConfig {
|
|
39
|
+
readonly kind: 'graphql';
|
|
40
|
+
readonly endpointUrl: string;
|
|
41
|
+
readonly introspection?: {
|
|
42
|
+
readonly enabled: boolean;
|
|
43
|
+
readonly schemaVersion?: string;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface DatabaseDataSourceConfig extends DataSourceBaseConfig {
|
|
48
|
+
readonly kind: 'database';
|
|
49
|
+
readonly adapter: AdapterRef;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface ManagedApiResourceConfig {
|
|
53
|
+
readonly name: string;
|
|
54
|
+
readonly collection: DbCollectionDefinition;
|
|
55
|
+
readonly operations?: readonly ('create' | 'delete' | 'list' | 'read' | 'update')[];
|
|
56
|
+
readonly metadata?: DataContractValue;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface ManagedApiDataSourceConfig extends DataSourceBaseConfig {
|
|
60
|
+
readonly kind: 'managed-api';
|
|
61
|
+
readonly adapter: AdapterRef;
|
|
62
|
+
readonly resources: readonly ManagedApiResourceConfig[];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export type DataSourceConfig =
|
|
66
|
+
| DatabaseDataSourceConfig
|
|
67
|
+
| GraphQlDataSourceConfig
|
|
68
|
+
| ManagedApiDataSourceConfig
|
|
69
|
+
| OpenApiDataSourceConfig
|
|
70
|
+
| RestDataSourceConfig;
|
|
71
|
+
|
|
72
|
+
export type DataSourceRegistry = Readonly<Record<DataSourceId, DataSourceConfig>>;
|