@ankhorage/infra 0.0.0 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/README.md +1 -1
- package/dist/adapters/minikube/index.js +4 -4
- package/dist/adapters/minikube/index.js.map +1 -1
- package/dist/{datasets.d.ts → apis.d.ts} +4 -4
- package/dist/apis.d.ts.map +1 -0
- package/dist/apis.js +354 -0
- package/dist/apis.js.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/adapters/minikube/index.ts +4 -4
- package/src/apis.test.ts +211 -0
- package/src/apis.ts +534 -0
- package/src/index.ts +2 -2
- package/dist/datasets.d.ts.map +0 -1
- package/dist/datasets.js +0 -397
- package/dist/datasets.js.map +0 -1
- package/src/datasets.test.ts +0 -178
- package/src/datasets.ts +0 -562
package/src/datasets.test.ts
DELETED
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
import type { AppManifest } from '@ankhorage/contracts';
|
|
2
|
-
import { describe, expect, test } from 'bun:test';
|
|
3
|
-
|
|
4
|
-
import { generateInfrastructure } from './index';
|
|
5
|
-
import type { InfraManifestInput } from './types';
|
|
6
|
-
|
|
7
|
-
describe('dataset infrastructure generation', () => {
|
|
8
|
-
test('generates provider-neutral dataset, seed, API, and OpenAPI artifacts', () => {
|
|
9
|
-
const manifest: InfraManifestInput = {
|
|
10
|
-
deployment: {
|
|
11
|
-
target: 'minikube',
|
|
12
|
-
monitoring: false,
|
|
13
|
-
},
|
|
14
|
-
database: {
|
|
15
|
-
provider: 'supabase',
|
|
16
|
-
tier: 'dev',
|
|
17
|
-
},
|
|
18
|
-
plugins: [],
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const appManifest: Pick<
|
|
22
|
-
AppManifest,
|
|
23
|
-
'data' | 'metadata' | 'navigator' | 'screens' | 'settings'
|
|
24
|
-
> = {
|
|
25
|
-
metadata: {
|
|
26
|
-
name: 'Cards',
|
|
27
|
-
slug: 'cards',
|
|
28
|
-
version: '1.0.0',
|
|
29
|
-
themeId: 'default',
|
|
30
|
-
},
|
|
31
|
-
data: {
|
|
32
|
-
datasets: {
|
|
33
|
-
poker_situations: {
|
|
34
|
-
id: 'poker_situations',
|
|
35
|
-
label: 'Poker situations',
|
|
36
|
-
description: 'App-owned poker trainer situations.',
|
|
37
|
-
collection: {
|
|
38
|
-
name: 'poker_situations',
|
|
39
|
-
primaryKey: 'id',
|
|
40
|
-
fields: [
|
|
41
|
-
{ name: 'id', type: 'uuid', required: true, unique: true },
|
|
42
|
-
{ name: 'title', type: 'text', required: true },
|
|
43
|
-
{ name: 'description', type: 'text', required: true },
|
|
44
|
-
{ name: 'availableActions', type: 'json' },
|
|
45
|
-
{ name: 'correctAction', type: 'text' },
|
|
46
|
-
],
|
|
47
|
-
},
|
|
48
|
-
operations: ['list', 'read', 'create'],
|
|
49
|
-
seed: [
|
|
50
|
-
{
|
|
51
|
-
title: 'Button faces a raise',
|
|
52
|
-
description: 'Choose the best action with position and stack depth in mind.',
|
|
53
|
-
availableActions: [
|
|
54
|
-
{ label: 'Fold', value: 'fold' },
|
|
55
|
-
{ label: 'Call', value: 'call' },
|
|
56
|
-
{ label: 'Raise', value: 'raise' },
|
|
57
|
-
],
|
|
58
|
-
correctAction: 'raise',
|
|
59
|
-
},
|
|
60
|
-
],
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
navigator: {
|
|
65
|
-
type: 'stack',
|
|
66
|
-
routes: [],
|
|
67
|
-
},
|
|
68
|
-
screens: {},
|
|
69
|
-
settings: {
|
|
70
|
-
localization: {
|
|
71
|
-
defaultLocale: 'en',
|
|
72
|
-
locales: ['en'],
|
|
73
|
-
},
|
|
74
|
-
authFlow: {
|
|
75
|
-
signInRoute: '/sign-in',
|
|
76
|
-
signUpRoute: '/sign-up',
|
|
77
|
-
signOutRoute: '/sign-out',
|
|
78
|
-
unauthorizedRoute: '/sign-in',
|
|
79
|
-
postSignInRoute: '/',
|
|
80
|
-
},
|
|
81
|
-
},
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
const result = generateInfrastructure(manifest, { namespaceHint: 'cards', appManifest });
|
|
85
|
-
const rerun = generateInfrastructure(manifest, { namespaceHint: 'cards', appManifest });
|
|
86
|
-
const paths = result.files.map((file) => file.path);
|
|
87
|
-
|
|
88
|
-
expect(result.files).toEqual(rerun.files);
|
|
89
|
-
expect(paths).toContain('infra/minikube/db/datasets.json');
|
|
90
|
-
expect(paths).toContain('infra/minikube/db/dataset-seed.json');
|
|
91
|
-
expect(paths).toContain('infra/minikube/db/migrations/001_datasets.sql');
|
|
92
|
-
expect(paths).toContain('infra/minikube/db/seeds/001_dataset_seed.sql');
|
|
93
|
-
expect(paths).toContain('infra/minikube/db/README.md');
|
|
94
|
-
expect(paths).toContain('src/generated/datasets/collections.ts');
|
|
95
|
-
expect(paths).toContain('src/generated/datasets/appDatasetApi.ts');
|
|
96
|
-
expect(paths).toContain('src/generated/datasets/datasetApiHandlers.ts');
|
|
97
|
-
expect(paths).toContain('src/generated/datasets/openapi.json');
|
|
98
|
-
|
|
99
|
-
const collectionsFile = result.files.find(
|
|
100
|
-
(file) => file.path === 'src/generated/datasets/collections.ts',
|
|
101
|
-
);
|
|
102
|
-
expect(collectionsFile?.content).toContain('GENERATED_DATASETS');
|
|
103
|
-
expect(collectionsFile?.content).toContain('poker_situations');
|
|
104
|
-
expect(collectionsFile?.content).toContain('availableActions');
|
|
105
|
-
|
|
106
|
-
const apiFile = result.files.find(
|
|
107
|
-
(file) => file.path === 'src/generated/datasets/appDatasetApi.ts',
|
|
108
|
-
);
|
|
109
|
-
expect(apiFile?.content).toContain('poker_situations.list');
|
|
110
|
-
expect(apiFile?.content).toContain('/api/datasets/poker_situations');
|
|
111
|
-
expect(apiFile?.content).toContain('poker_situations.read');
|
|
112
|
-
expect(apiFile?.content).toContain('/api/datasets/poker_situations/{id}');
|
|
113
|
-
|
|
114
|
-
const handlersFile = result.files.find(
|
|
115
|
-
(file) => file.path === 'src/generated/datasets/datasetApiHandlers.ts',
|
|
116
|
-
);
|
|
117
|
-
expect(handlersFile?.content).toContain('handleGeneratedDatasetList');
|
|
118
|
-
expect(handlersFile?.content).toContain('handleGeneratedDatasetCreate');
|
|
119
|
-
expect(handlersFile?.content).toContain('createGeneratedDatasetMemoryStore');
|
|
120
|
-
expect(handlersFile?.content).toContain('poker_situations');
|
|
121
|
-
|
|
122
|
-
const openApiFile = result.files.find(
|
|
123
|
-
(file) => file.path === 'src/generated/datasets/openapi.json',
|
|
124
|
-
);
|
|
125
|
-
expect(openApiFile?.content).toContain('Generated app dataset API');
|
|
126
|
-
expect(openApiFile?.content).toContain('poker_situations.create');
|
|
127
|
-
expect(openApiFile?.content).toContain('x-ankh-dataset');
|
|
128
|
-
|
|
129
|
-
const migrationFile = result.files.find(
|
|
130
|
-
(file) => file.path === 'infra/minikube/db/migrations/001_datasets.sql',
|
|
131
|
-
);
|
|
132
|
-
expect(migrationFile?.content).toContain('create extension if not exists pgcrypto');
|
|
133
|
-
expect(migrationFile?.content).toContain(
|
|
134
|
-
'create table if not exists "public"."poker_situations"',
|
|
135
|
-
);
|
|
136
|
-
expect(migrationFile?.content).toContain('"id" uuid default gen_random_uuid() primary key');
|
|
137
|
-
expect(migrationFile?.content).toContain('"availableActions" jsonb');
|
|
138
|
-
|
|
139
|
-
const seedFile = result.files.find(
|
|
140
|
-
(file) => file.path === 'infra/minikube/db/dataset-seed.json',
|
|
141
|
-
);
|
|
142
|
-
expect(seedFile?.content).toContain('Button faces a raise');
|
|
143
|
-
expect(seedFile?.content).toContain('correctAction');
|
|
144
|
-
expect(seedFile?.content).toContain('"id"');
|
|
145
|
-
|
|
146
|
-
const seedSqlFile = result.files.find(
|
|
147
|
-
(file) => file.path === 'infra/minikube/db/seeds/001_dataset_seed.sql',
|
|
148
|
-
);
|
|
149
|
-
expect(seedSqlFile?.content).toContain('insert into "public"."poker_situations"');
|
|
150
|
-
expect(seedSqlFile?.content).toContain('Button faces a raise');
|
|
151
|
-
expect(seedSqlFile?.content).toContain('on conflict ("id") do nothing');
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
test('reports selected state adapter dependencies', () => {
|
|
155
|
-
const manifest: InfraManifestInput = {
|
|
156
|
-
deployment: {
|
|
157
|
-
target: 'minikube',
|
|
158
|
-
monitoring: false,
|
|
159
|
-
},
|
|
160
|
-
state: {
|
|
161
|
-
provider: 'legend',
|
|
162
|
-
persistence: 'none',
|
|
163
|
-
},
|
|
164
|
-
plugins: [],
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
const result = generateInfrastructure(manifest, { namespaceHint: 'cards' });
|
|
168
|
-
|
|
169
|
-
expect(result.meta.providers).toContain('legend');
|
|
170
|
-
expect(result.dependencies).toEqual([
|
|
171
|
-
{
|
|
172
|
-
name: '@ankhorage/state-legend',
|
|
173
|
-
version: '^0.1.0',
|
|
174
|
-
reason: 'Selected by infra.state.provider=legend.',
|
|
175
|
-
},
|
|
176
|
-
]);
|
|
177
|
-
});
|
|
178
|
-
});
|