@aurabase/gen 0.5.2 → 0.5.4
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/README.md +49 -37
- package/dist/cli.cjs +181 -9
- package/dist/cli.d.cts +18 -1
- package/dist/cli.d.ts +18 -1
- package/dist/cli.js +180 -11
- package/dist/index.cjs +80 -0
- package/dist/index.js +80 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @aurabase/gen
|
|
2
2
|
|
|
3
|
-
Générateur de types TypeScript `Database` pour le SDK Aurabase : introspecte le schéma d'un projet et produit un fichier de types compatible avec l'inférence de `@aurabase/db
|
|
3
|
+
Générateur de types TypeScript `Database` pour le SDK Aurabase : introspecte le schéma d'un projet et produit un fichier de types complet avec helpers génériques (`Tables`, `TablesInsert`, `TablesUpdate`, `Enums`) compatible avec l'inférence de `@aurabase/db`.
|
|
4
4
|
|
|
5
5
|
 
|
|
6
6
|
|
|
@@ -14,71 +14,83 @@ Fait partie de l'écosystème du SDK **[@aurabase/aurabase-js](../aurabase)**, m
|
|
|
14
14
|
npm i -D @aurabase/gen
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
-
> S'installe typiquement en devDependency (ou s'exécute via `npx` sans installation)
|
|
17
|
+
> S'installe typiquement en devDependency (ou s'exécute via `npx` sans installation).
|
|
18
18
|
|
|
19
19
|
## Usage
|
|
20
20
|
|
|
21
21
|
### CLI `aurabase-gen`
|
|
22
22
|
|
|
23
|
+
Le CLI détecte automatiquement les variables d'environnement de votre projet (`.env`, `.env.local`, `.env.development`) :
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
# Détection automatique de AURABASE_URL et AURABASE_ANON_KEY / AURABASE_SERVICE_ROLE_KEY :
|
|
27
|
+
npx @aurabase/gen --out src/types/database.types.ts
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Ou en passant les paramètres explicitement :
|
|
31
|
+
|
|
23
32
|
```bash
|
|
24
|
-
npx aurabase
|
|
33
|
+
npx @aurabase/gen --url https://mon-projet.aurabase.cloud --key aura_anon_xxx --out database.types.ts
|
|
25
34
|
```
|
|
26
35
|
|
|
27
36
|
Options complètes :
|
|
28
37
|
|
|
29
38
|
```
|
|
30
|
-
aurabase-gen
|
|
39
|
+
aurabase-gen [options]
|
|
40
|
+
|
|
41
|
+
--url <url> URL du projet Aurabase (ex: https://mon-projet.aurabase.cloud)
|
|
42
|
+
[Auto-détection : AURABASE_URL, NEXT_PUBLIC_AURABASE_URL, VITE_AURABASE_URL]
|
|
43
|
+
--key <cle> Clé API du projet (anon ou service_role)
|
|
44
|
+
[Auto-détection : AURABASE_API_KEY, AURABASE_ANON_KEY, AURABASE_SERVICE_ROLE_KEY]
|
|
45
|
+
-o, --out <fichier> Fichier de destination (ex: src/types/database.types.ts)
|
|
46
|
+
Si omis, le résultat est écrit sur stdout.
|
|
47
|
+
-s, --schema <nom> Nom du schéma de base de données (défaut : 'public')
|
|
48
|
+
-t, --type-name <t> Nom de l'interface principale générée (défaut : 'Database')
|
|
49
|
+
--allow-empty Générer les types même si des tables n'ont pas de colonnes déclarées
|
|
50
|
+
-h, --help Afficher l'aide
|
|
51
|
+
-v, --version Afficher la version
|
|
31
52
|
```
|
|
32
53
|
|
|
33
|
-
|
|
54
|
+
### Type Helpers générés
|
|
34
55
|
|
|
35
|
-
|
|
56
|
+
Le fichier généré exporte l'interface principale `Database` ainsi que des type helpers de commodité pour vos composants et services :
|
|
36
57
|
|
|
37
58
|
```ts
|
|
38
|
-
import {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
realtime_enabled: false,
|
|
52
|
-
},
|
|
53
|
-
]
|
|
54
|
-
|
|
55
|
-
const source = generateDatabaseTypes(tables, { schemaName: 'public', typeName: 'Database' })
|
|
59
|
+
import type { Tables, TablesInsert, TablesUpdate, Enums } from './database.types'
|
|
60
|
+
|
|
61
|
+
// Type d'une ligne d'une table ou vue
|
|
62
|
+
type Post = Tables<'posts'>
|
|
63
|
+
|
|
64
|
+
// Type de la charge utile d'insertion (id, created_at optionnels)
|
|
65
|
+
type NewPost = TablesInsert<'posts'>
|
|
66
|
+
|
|
67
|
+
// Type de la charge utile de mise à jour (tous champs optionnels)
|
|
68
|
+
type PostUpdate = TablesUpdate<'posts'>
|
|
69
|
+
|
|
70
|
+
// Type d'une énumération Postgres
|
|
71
|
+
type UserRole = Enums<'user_role'>
|
|
56
72
|
```
|
|
57
73
|
|
|
58
|
-
### Workflow complet
|
|
74
|
+
### Workflow complet avec `@aurabase/db`
|
|
59
75
|
|
|
60
76
|
```bash
|
|
61
|
-
npx aurabase
|
|
77
|
+
npx @aurabase/gen --out src/types/database.types.ts
|
|
62
78
|
```
|
|
63
79
|
|
|
64
80
|
```ts
|
|
65
81
|
import { createClient } from '@aurabase/aurabase-js'
|
|
66
|
-
import type { Database } from './database.types'
|
|
82
|
+
import type { Database } from './database.types'
|
|
67
83
|
|
|
68
84
|
const aura = createClient<Database>('https://mon-projet.aurabase.cloud', 'aura_anon_xxx')
|
|
69
85
|
|
|
70
|
-
// select()
|
|
71
|
-
const { data } = await aura.db
|
|
86
|
+
// select(), filtres, embeds et mutations sont désormais typés et auto-complétés :
|
|
87
|
+
const { data, count, error } = await aura.db
|
|
88
|
+
.from('posts')
|
|
89
|
+
.select('id,title,author:users(name)', { count: 'exact' })
|
|
90
|
+
.eq('published', true)
|
|
91
|
+
.range(0, 9)
|
|
72
92
|
```
|
|
73
93
|
|
|
74
|
-
## Limitations
|
|
75
|
-
|
|
76
|
-
- `Views`, `Functions`, `Enums` et `CompositeTypes` sont toujours générés vides (`Record<string, never>`) — seules les `Tables` sont introspectées et typées.
|
|
77
|
-
- Un seul schéma à la fois (`--schema`, défaut `public`) : pas de génération multi-schémas en une seule invocation.
|
|
78
|
-
- Dépend de l'endpoint `/schema` exposé par `aura.db.schema()` côté backend — un projet ou une clé sans droit de lecture du schéma ne peut pas générer de types (erreur explicite, pas de repli silencieux).
|
|
79
|
-
- Pas de détection de types enum Postgres dédiés : un `col_type` non reconnu retombe sur `unknown`.
|
|
80
|
-
- Le fichier généré est un instantané : il ne se met pas à jour automatiquement quand le schéma change côté backend (pas de mode watch).
|
|
81
|
-
|
|
82
94
|
## Documentation
|
|
83
95
|
|
|
84
96
|
Référence complète du SDK (tous les services, types partagés, SSR) : [README racine](../../README.md).
|
package/dist/cli.cjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
var fs = require('fs');
|
|
5
|
+
var path = require('path');
|
|
5
6
|
var aurabaseJs = require('@aurabase/aurabase-js');
|
|
6
7
|
|
|
7
8
|
// src/generate.ts
|
|
@@ -260,10 +261,123 @@ export interface ${typeName} {
|
|
|
260
261
|
CompositeTypes: Record<string, never>
|
|
261
262
|
}
|
|
262
263
|
}
|
|
264
|
+
|
|
265
|
+
export type Tables<
|
|
266
|
+
PublicTableNameOrOptions extends
|
|
267
|
+
| keyof (${typeName}['${schemaName}']['Tables'] & ${typeName}['${schemaName}']['Views'])
|
|
268
|
+
| { schema: keyof ${typeName} },
|
|
269
|
+
TableName extends PublicTableNameOrOptions extends { schema: keyof ${typeName} }
|
|
270
|
+
? keyof (${typeName}[PublicTableNameOrOptions['schema']]['Tables'] &
|
|
271
|
+
${typeName}[PublicTableNameOrOptions['schema']]['Views'])
|
|
272
|
+
: never = never,
|
|
273
|
+
> = PublicTableNameOrOptions extends { schema: keyof ${typeName} }
|
|
274
|
+
? (${typeName}[PublicTableNameOrOptions['schema']]['Tables'] &
|
|
275
|
+
${typeName}[PublicTableNameOrOptions['schema']]['Views'])[TableName] extends {
|
|
276
|
+
Row: infer R
|
|
277
|
+
}
|
|
278
|
+
? R
|
|
279
|
+
: never
|
|
280
|
+
: PublicTableNameOrOptions extends keyof (${typeName}['${schemaName}']['Tables'] &
|
|
281
|
+
${typeName}['${schemaName}']['Views'])
|
|
282
|
+
? (${typeName}['${schemaName}']['Tables'] &
|
|
283
|
+
${typeName}['${schemaName}']['Views'])[PublicTableNameOrOptions] extends {
|
|
284
|
+
Row: infer R
|
|
285
|
+
}
|
|
286
|
+
? R
|
|
287
|
+
: never
|
|
288
|
+
: never
|
|
289
|
+
|
|
290
|
+
export type TablesInsert<
|
|
291
|
+
PublicTableNameOrOptions extends
|
|
292
|
+
| keyof ${typeName}['${schemaName}']['Tables']
|
|
293
|
+
| { schema: keyof ${typeName} },
|
|
294
|
+
TableName extends PublicTableNameOrOptions extends { schema: keyof ${typeName} }
|
|
295
|
+
? keyof ${typeName}[PublicTableNameOrOptions['schema']]['Tables']
|
|
296
|
+
: never = never,
|
|
297
|
+
> = PublicTableNameOrOptions extends { schema: keyof ${typeName} }
|
|
298
|
+
? ${typeName}[PublicTableNameOrOptions['schema']]['Tables'][TableName] extends {
|
|
299
|
+
Insert: infer I
|
|
300
|
+
}
|
|
301
|
+
? I
|
|
302
|
+
: never
|
|
303
|
+
: PublicTableNameOrOptions extends keyof ${typeName}['${schemaName}']['Tables']
|
|
304
|
+
? ${typeName}['${schemaName}']['Tables'][PublicTableNameOrOptions] extends {
|
|
305
|
+
Insert: infer I
|
|
306
|
+
}
|
|
307
|
+
? I
|
|
308
|
+
: never
|
|
309
|
+
: never
|
|
310
|
+
|
|
311
|
+
export type TablesUpdate<
|
|
312
|
+
PublicTableNameOrOptions extends
|
|
313
|
+
| keyof ${typeName}['${schemaName}']['Tables']
|
|
314
|
+
| { schema: keyof ${typeName} },
|
|
315
|
+
TableName extends PublicTableNameOrOptions extends { schema: keyof ${typeName} }
|
|
316
|
+
? keyof ${typeName}[PublicTableNameOrOptions['schema']]['Tables']
|
|
317
|
+
: never = never,
|
|
318
|
+
> = PublicTableNameOrOptions extends { schema: keyof ${typeName} }
|
|
319
|
+
? ${typeName}[PublicTableNameOrOptions['schema']]['Tables'][TableName] extends {
|
|
320
|
+
Update: infer U
|
|
321
|
+
}
|
|
322
|
+
? U
|
|
323
|
+
: never
|
|
324
|
+
: PublicTableNameOrOptions extends keyof ${typeName}['${schemaName}']['Tables']
|
|
325
|
+
? ${typeName}['${schemaName}']['Tables'][PublicTableNameOrOptions] extends {
|
|
326
|
+
Update: infer U
|
|
327
|
+
}
|
|
328
|
+
? U
|
|
329
|
+
: never
|
|
330
|
+
: never
|
|
331
|
+
|
|
332
|
+
export type Enums<
|
|
333
|
+
PublicEnumNameOrOptions extends
|
|
334
|
+
| keyof ${typeName}['${schemaName}']['Enums']
|
|
335
|
+
| { schema: keyof ${typeName} },
|
|
336
|
+
EnumName extends PublicEnumNameOrOptions extends { schema: keyof ${typeName} }
|
|
337
|
+
? keyof ${typeName}[PublicEnumNameOrOptions['schema']]['Enums']
|
|
338
|
+
: never = never,
|
|
339
|
+
> = PublicEnumNameOrOptions extends { schema: keyof ${typeName} }
|
|
340
|
+
? ${typeName}[PublicEnumNameOrOptions['schema']]['Enums'][EnumName]
|
|
341
|
+
: PublicEnumNameOrOptions extends keyof ${typeName}['${schemaName}']['Enums']
|
|
342
|
+
? ${typeName}['${schemaName}']['Enums'][PublicEnumNameOrOptions]
|
|
343
|
+
: never
|
|
263
344
|
`;
|
|
264
345
|
}
|
|
265
346
|
|
|
266
347
|
// src/cli.ts
|
|
348
|
+
var VERSION = "0.5.4";
|
|
349
|
+
function loadEnvFiles() {
|
|
350
|
+
const envCandidates = [".env.local", ".env.development.local", ".env.development", ".env"];
|
|
351
|
+
for (const file of envCandidates) {
|
|
352
|
+
const fullPath = path.resolve(process.cwd(), file);
|
|
353
|
+
if (fs.existsSync(fullPath)) {
|
|
354
|
+
try {
|
|
355
|
+
if (typeof process.loadEnvFile === "function") {
|
|
356
|
+
;
|
|
357
|
+
process.loadEnvFile(fullPath);
|
|
358
|
+
} else {
|
|
359
|
+
const content = fs.readFileSync(fullPath, "utf-8");
|
|
360
|
+
for (const line of content.split("\n")) {
|
|
361
|
+
const trimmed = line.trim();
|
|
362
|
+
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
363
|
+
const eqIdx = trimmed.indexOf("=");
|
|
364
|
+
if (eqIdx > 0) {
|
|
365
|
+
const k = trimmed.slice(0, eqIdx).trim();
|
|
366
|
+
let v = trimmed.slice(eqIdx + 1).trim();
|
|
367
|
+
if (v.startsWith('"') && v.endsWith('"') || v.startsWith("'") && v.endsWith("'")) {
|
|
368
|
+
v = v.slice(1, -1);
|
|
369
|
+
}
|
|
370
|
+
if (!process.env[k]) {
|
|
371
|
+
process.env[k] = v;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
} catch {
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
267
381
|
function diagnostiquerSchema(tables) {
|
|
268
382
|
if (tables.length === 0) {
|
|
269
383
|
return "Sch\xE9ma vide : aucune table. Les types g\xE9n\xE9r\xE9s seraient inutilisables.";
|
|
@@ -277,8 +391,9 @@ function diagnostiquerSchema(tables) {
|
|
|
277
391
|
function parseArgs(argv) {
|
|
278
392
|
const a = {};
|
|
279
393
|
for (let i = 0; i < argv.length; i++) {
|
|
394
|
+
const arg = argv[i];
|
|
280
395
|
const v = argv[i + 1];
|
|
281
|
-
switch (
|
|
396
|
+
switch (arg) {
|
|
282
397
|
case "--url":
|
|
283
398
|
a.url = v;
|
|
284
399
|
i++;
|
|
@@ -288,14 +403,17 @@ function parseArgs(argv) {
|
|
|
288
403
|
i++;
|
|
289
404
|
break;
|
|
290
405
|
case "--out":
|
|
406
|
+
case "-o":
|
|
291
407
|
a.out = v;
|
|
292
408
|
i++;
|
|
293
409
|
break;
|
|
294
410
|
case "--schema":
|
|
411
|
+
case "-s":
|
|
295
412
|
a.schema = v;
|
|
296
413
|
i++;
|
|
297
414
|
break;
|
|
298
415
|
case "--type-name":
|
|
416
|
+
case "-t":
|
|
299
417
|
a.typeName = v;
|
|
300
418
|
i++;
|
|
301
419
|
break;
|
|
@@ -303,18 +421,69 @@ function parseArgs(argv) {
|
|
|
303
421
|
case "--allow-empty":
|
|
304
422
|
a.allowEmpty = true;
|
|
305
423
|
break;
|
|
424
|
+
case "--help":
|
|
425
|
+
case "-h":
|
|
426
|
+
a.help = true;
|
|
427
|
+
break;
|
|
428
|
+
case "--version":
|
|
429
|
+
case "-v":
|
|
430
|
+
a.version = true;
|
|
431
|
+
break;
|
|
306
432
|
}
|
|
307
433
|
}
|
|
308
434
|
return a;
|
|
309
435
|
}
|
|
310
|
-
var
|
|
436
|
+
var HELP_TEXT = `
|
|
437
|
+
aurabase-gen (v${VERSION}) \u2014 G\xE9n\xE9rateur de types TypeScript pour Aurabase
|
|
438
|
+
|
|
439
|
+
USAGE :
|
|
440
|
+
npx @aurabase/gen [options]
|
|
441
|
+
aurabase-gen --url <projectUrl> --key <apiKey> [--out <fichier>]
|
|
442
|
+
|
|
443
|
+
OPTIONS :
|
|
444
|
+
--url <url> URL du projet Aurabase (ex: https://mon-projet.aurabase.cloud)
|
|
445
|
+
[Auto-d\xE9tection : AURABASE_URL, NEXT_PUBLIC_AURABASE_URL, VITE_AURABASE_URL]
|
|
446
|
+
--key <cle> Cl\xE9 API du projet (anon ou service_role)
|
|
447
|
+
[Auto-d\xE9tection : AURABASE_API_KEY, AURABASE_ANON_KEY, AURABASE_SERVICE_ROLE_KEY]
|
|
448
|
+
-o, --out <fichier> Fichier de destination (ex: src/types/database.types.ts)
|
|
449
|
+
Si omis, le r\xE9sultat est \xE9crit sur stdout.
|
|
450
|
+
-s, --schema <nom> Nom du sch\xE9ma de base de donn\xE9es (d\xE9faut : 'public')
|
|
451
|
+
-t, --type-name <t> Nom de l'interface principale g\xE9n\xE9r\xE9e (d\xE9faut : 'Database')
|
|
452
|
+
--allow-empty G\xE9n\xE9rer les types m\xEAme si des tables n'ont pas de colonnes d\xE9clar\xE9es
|
|
453
|
+
-h, --help Afficher cette aide
|
|
454
|
+
-v, --version Afficher la version
|
|
455
|
+
|
|
456
|
+
EXEMPLES :
|
|
457
|
+
# G\xE9n\xE9ration avec lecture automatique des variables d'environnement (.env / .env.local) :
|
|
458
|
+
npx @aurabase/gen --out src/types/database.types.ts
|
|
459
|
+
|
|
460
|
+
# Param\xE8tres explicites :
|
|
461
|
+
npx @aurabase/gen --url https://xyz.aurabase.cloud --key aura_anon_123 --out db.types.ts
|
|
462
|
+
`;
|
|
311
463
|
async function main() {
|
|
464
|
+
loadEnvFiles();
|
|
312
465
|
const args = parseArgs(process.argv.slice(2));
|
|
313
|
-
if (
|
|
314
|
-
console.
|
|
466
|
+
if (args.help) {
|
|
467
|
+
console.log(HELP_TEXT.trim());
|
|
468
|
+
process.exit(0);
|
|
469
|
+
}
|
|
470
|
+
if (args.version) {
|
|
471
|
+
console.log(`aurabase-gen v${VERSION}`);
|
|
472
|
+
process.exit(0);
|
|
473
|
+
}
|
|
474
|
+
const url = args.url ?? process.env.AURABASE_URL ?? process.env.NEXT_PUBLIC_AURABASE_URL ?? process.env.VITE_AURABASE_URL;
|
|
475
|
+
const key = args.key ?? process.env.AURABASE_SERVICE_ROLE_KEY ?? process.env.AURABASE_API_KEY ?? process.env.AURABASE_ANON_KEY ?? process.env.NEXT_PUBLIC_AURABASE_ANON_KEY ?? process.env.VITE_AURABASE_ANON_KEY;
|
|
476
|
+
if (!url || !key) {
|
|
477
|
+
console.error("[aurabase-gen] Erreur : URL et/ou cl\xE9 API du projet manquantes.\n");
|
|
478
|
+
console.error("Sp\xE9cifiez-les via les arguments CLI (--url et --key) ou dans vos variables d\u2019environnement (.env / .env.local) :");
|
|
479
|
+
console.error(" AURABASE_URL=https://<slug>.aurabase.cloud");
|
|
480
|
+
console.error(" AURABASE_ANON_KEY=aura_anon_...\n");
|
|
481
|
+
console.error("Ex\xE9cutez `npx @aurabase/gen --help` pour afficher toutes les options disponibles.");
|
|
315
482
|
process.exit(1);
|
|
316
483
|
}
|
|
317
|
-
const
|
|
484
|
+
const schemaName = args.schema ?? process.env.AURABASE_SCHEMA ?? "public";
|
|
485
|
+
const outPath = args.out ?? process.env.AURABASE_TYPES_OUT;
|
|
486
|
+
const client = aurabaseJs.createClient(url, key);
|
|
318
487
|
const { data, error } = await client.db.schema();
|
|
319
488
|
if (error) {
|
|
320
489
|
console.error(`[aurabase-gen] Erreur de r\xE9cup\xE9ration du sch\xE9ma : ${error.message}`);
|
|
@@ -332,16 +501,16 @@ async function main() {
|
|
|
332
501
|
console.error(`[aurabase-gen] Avertissement (--allow-empty) : ${probleme}`);
|
|
333
502
|
}
|
|
334
503
|
const output = generateDatabaseTypes(tables, {
|
|
335
|
-
schemaName
|
|
504
|
+
schemaName,
|
|
336
505
|
typeName: args.typeName,
|
|
337
506
|
functions,
|
|
338
507
|
enums,
|
|
339
508
|
views
|
|
340
509
|
});
|
|
341
|
-
if (
|
|
342
|
-
fs.writeFileSync(
|
|
510
|
+
if (outPath) {
|
|
511
|
+
fs.writeFileSync(outPath, output);
|
|
343
512
|
console.error(
|
|
344
|
-
`[aurabase-gen] \u2713 Types \xE9crits dans ${
|
|
513
|
+
`[aurabase-gen] \u2713 Types \xE9crits dans ${outPath} (${tables.length} table(s), ${functions.length} fonction(s), ${enums.length} enum(s), ${views.length} vue(s)).`
|
|
345
514
|
);
|
|
346
515
|
} else {
|
|
347
516
|
process.stdout.write(output);
|
|
@@ -354,4 +523,7 @@ if (process.argv[1] && /aurabase-gen|cli\.(ts|js|mjs|cjs)$/.test(process.argv[1]
|
|
|
354
523
|
});
|
|
355
524
|
}
|
|
356
525
|
|
|
526
|
+
exports.VERSION = VERSION;
|
|
357
527
|
exports.diagnostiquerSchema = diagnostiquerSchema;
|
|
528
|
+
exports.loadEnvFiles = loadEnvFiles;
|
|
529
|
+
exports.parseArgs = parseArgs;
|
package/dist/cli.d.cts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
declare const VERSION = "0.5.4";
|
|
3
|
+
/**
|
|
4
|
+
* Charge les fichiers .env locaux s'ils existent dans le répertoire courant.
|
|
5
|
+
* Tente .env.local, .env.development.local, .env.development, .env par ordre de priorité.
|
|
6
|
+
*/
|
|
7
|
+
declare function loadEnvFiles(): void;
|
|
2
8
|
/**
|
|
3
9
|
* A10 — refuse de faire passer pour un succès un typage qui ne garantit rien.
|
|
4
10
|
*
|
|
@@ -13,5 +19,16 @@ declare function diagnostiquerSchema(tables: Array<{
|
|
|
13
19
|
name: string;
|
|
14
20
|
columns?: unknown[];
|
|
15
21
|
}>): string | null;
|
|
22
|
+
interface Args {
|
|
23
|
+
url?: string;
|
|
24
|
+
key?: string;
|
|
25
|
+
out?: string;
|
|
26
|
+
schema?: string;
|
|
27
|
+
typeName?: string;
|
|
28
|
+
allowEmpty?: boolean;
|
|
29
|
+
help?: boolean;
|
|
30
|
+
version?: boolean;
|
|
31
|
+
}
|
|
32
|
+
declare function parseArgs(argv: string[]): Args;
|
|
16
33
|
|
|
17
|
-
export { diagnostiquerSchema };
|
|
34
|
+
export { VERSION, diagnostiquerSchema, loadEnvFiles, parseArgs };
|
package/dist/cli.d.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
declare const VERSION = "0.5.4";
|
|
3
|
+
/**
|
|
4
|
+
* Charge les fichiers .env locaux s'ils existent dans le répertoire courant.
|
|
5
|
+
* Tente .env.local, .env.development.local, .env.development, .env par ordre de priorité.
|
|
6
|
+
*/
|
|
7
|
+
declare function loadEnvFiles(): void;
|
|
2
8
|
/**
|
|
3
9
|
* A10 — refuse de faire passer pour un succès un typage qui ne garantit rien.
|
|
4
10
|
*
|
|
@@ -13,5 +19,16 @@ declare function diagnostiquerSchema(tables: Array<{
|
|
|
13
19
|
name: string;
|
|
14
20
|
columns?: unknown[];
|
|
15
21
|
}>): string | null;
|
|
22
|
+
interface Args {
|
|
23
|
+
url?: string;
|
|
24
|
+
key?: string;
|
|
25
|
+
out?: string;
|
|
26
|
+
schema?: string;
|
|
27
|
+
typeName?: string;
|
|
28
|
+
allowEmpty?: boolean;
|
|
29
|
+
help?: boolean;
|
|
30
|
+
version?: boolean;
|
|
31
|
+
}
|
|
32
|
+
declare function parseArgs(argv: string[]): Args;
|
|
16
33
|
|
|
17
|
-
export { diagnostiquerSchema };
|
|
34
|
+
export { VERSION, diagnostiquerSchema, loadEnvFiles, parseArgs };
|
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { writeFileSync } from 'fs';
|
|
2
|
+
import { writeFileSync, existsSync, readFileSync } from 'fs';
|
|
3
|
+
import { resolve } from 'path';
|
|
3
4
|
import { createClient } from '@aurabase/aurabase-js';
|
|
4
5
|
|
|
5
6
|
// src/generate.ts
|
|
@@ -258,10 +259,123 @@ export interface ${typeName} {
|
|
|
258
259
|
CompositeTypes: Record<string, never>
|
|
259
260
|
}
|
|
260
261
|
}
|
|
262
|
+
|
|
263
|
+
export type Tables<
|
|
264
|
+
PublicTableNameOrOptions extends
|
|
265
|
+
| keyof (${typeName}['${schemaName}']['Tables'] & ${typeName}['${schemaName}']['Views'])
|
|
266
|
+
| { schema: keyof ${typeName} },
|
|
267
|
+
TableName extends PublicTableNameOrOptions extends { schema: keyof ${typeName} }
|
|
268
|
+
? keyof (${typeName}[PublicTableNameOrOptions['schema']]['Tables'] &
|
|
269
|
+
${typeName}[PublicTableNameOrOptions['schema']]['Views'])
|
|
270
|
+
: never = never,
|
|
271
|
+
> = PublicTableNameOrOptions extends { schema: keyof ${typeName} }
|
|
272
|
+
? (${typeName}[PublicTableNameOrOptions['schema']]['Tables'] &
|
|
273
|
+
${typeName}[PublicTableNameOrOptions['schema']]['Views'])[TableName] extends {
|
|
274
|
+
Row: infer R
|
|
275
|
+
}
|
|
276
|
+
? R
|
|
277
|
+
: never
|
|
278
|
+
: PublicTableNameOrOptions extends keyof (${typeName}['${schemaName}']['Tables'] &
|
|
279
|
+
${typeName}['${schemaName}']['Views'])
|
|
280
|
+
? (${typeName}['${schemaName}']['Tables'] &
|
|
281
|
+
${typeName}['${schemaName}']['Views'])[PublicTableNameOrOptions] extends {
|
|
282
|
+
Row: infer R
|
|
283
|
+
}
|
|
284
|
+
? R
|
|
285
|
+
: never
|
|
286
|
+
: never
|
|
287
|
+
|
|
288
|
+
export type TablesInsert<
|
|
289
|
+
PublicTableNameOrOptions extends
|
|
290
|
+
| keyof ${typeName}['${schemaName}']['Tables']
|
|
291
|
+
| { schema: keyof ${typeName} },
|
|
292
|
+
TableName extends PublicTableNameOrOptions extends { schema: keyof ${typeName} }
|
|
293
|
+
? keyof ${typeName}[PublicTableNameOrOptions['schema']]['Tables']
|
|
294
|
+
: never = never,
|
|
295
|
+
> = PublicTableNameOrOptions extends { schema: keyof ${typeName} }
|
|
296
|
+
? ${typeName}[PublicTableNameOrOptions['schema']]['Tables'][TableName] extends {
|
|
297
|
+
Insert: infer I
|
|
298
|
+
}
|
|
299
|
+
? I
|
|
300
|
+
: never
|
|
301
|
+
: PublicTableNameOrOptions extends keyof ${typeName}['${schemaName}']['Tables']
|
|
302
|
+
? ${typeName}['${schemaName}']['Tables'][PublicTableNameOrOptions] extends {
|
|
303
|
+
Insert: infer I
|
|
304
|
+
}
|
|
305
|
+
? I
|
|
306
|
+
: never
|
|
307
|
+
: never
|
|
308
|
+
|
|
309
|
+
export type TablesUpdate<
|
|
310
|
+
PublicTableNameOrOptions extends
|
|
311
|
+
| keyof ${typeName}['${schemaName}']['Tables']
|
|
312
|
+
| { schema: keyof ${typeName} },
|
|
313
|
+
TableName extends PublicTableNameOrOptions extends { schema: keyof ${typeName} }
|
|
314
|
+
? keyof ${typeName}[PublicTableNameOrOptions['schema']]['Tables']
|
|
315
|
+
: never = never,
|
|
316
|
+
> = PublicTableNameOrOptions extends { schema: keyof ${typeName} }
|
|
317
|
+
? ${typeName}[PublicTableNameOrOptions['schema']]['Tables'][TableName] extends {
|
|
318
|
+
Update: infer U
|
|
319
|
+
}
|
|
320
|
+
? U
|
|
321
|
+
: never
|
|
322
|
+
: PublicTableNameOrOptions extends keyof ${typeName}['${schemaName}']['Tables']
|
|
323
|
+
? ${typeName}['${schemaName}']['Tables'][PublicTableNameOrOptions] extends {
|
|
324
|
+
Update: infer U
|
|
325
|
+
}
|
|
326
|
+
? U
|
|
327
|
+
: never
|
|
328
|
+
: never
|
|
329
|
+
|
|
330
|
+
export type Enums<
|
|
331
|
+
PublicEnumNameOrOptions extends
|
|
332
|
+
| keyof ${typeName}['${schemaName}']['Enums']
|
|
333
|
+
| { schema: keyof ${typeName} },
|
|
334
|
+
EnumName extends PublicEnumNameOrOptions extends { schema: keyof ${typeName} }
|
|
335
|
+
? keyof ${typeName}[PublicEnumNameOrOptions['schema']]['Enums']
|
|
336
|
+
: never = never,
|
|
337
|
+
> = PublicEnumNameOrOptions extends { schema: keyof ${typeName} }
|
|
338
|
+
? ${typeName}[PublicEnumNameOrOptions['schema']]['Enums'][EnumName]
|
|
339
|
+
: PublicEnumNameOrOptions extends keyof ${typeName}['${schemaName}']['Enums']
|
|
340
|
+
? ${typeName}['${schemaName}']['Enums'][PublicEnumNameOrOptions]
|
|
341
|
+
: never
|
|
261
342
|
`;
|
|
262
343
|
}
|
|
263
344
|
|
|
264
345
|
// src/cli.ts
|
|
346
|
+
var VERSION = "0.5.4";
|
|
347
|
+
function loadEnvFiles() {
|
|
348
|
+
const envCandidates = [".env.local", ".env.development.local", ".env.development", ".env"];
|
|
349
|
+
for (const file of envCandidates) {
|
|
350
|
+
const fullPath = resolve(process.cwd(), file);
|
|
351
|
+
if (existsSync(fullPath)) {
|
|
352
|
+
try {
|
|
353
|
+
if (typeof process.loadEnvFile === "function") {
|
|
354
|
+
;
|
|
355
|
+
process.loadEnvFile(fullPath);
|
|
356
|
+
} else {
|
|
357
|
+
const content = readFileSync(fullPath, "utf-8");
|
|
358
|
+
for (const line of content.split("\n")) {
|
|
359
|
+
const trimmed = line.trim();
|
|
360
|
+
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
361
|
+
const eqIdx = trimmed.indexOf("=");
|
|
362
|
+
if (eqIdx > 0) {
|
|
363
|
+
const k = trimmed.slice(0, eqIdx).trim();
|
|
364
|
+
let v = trimmed.slice(eqIdx + 1).trim();
|
|
365
|
+
if (v.startsWith('"') && v.endsWith('"') || v.startsWith("'") && v.endsWith("'")) {
|
|
366
|
+
v = v.slice(1, -1);
|
|
367
|
+
}
|
|
368
|
+
if (!process.env[k]) {
|
|
369
|
+
process.env[k] = v;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
} catch {
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}
|
|
265
379
|
function diagnostiquerSchema(tables) {
|
|
266
380
|
if (tables.length === 0) {
|
|
267
381
|
return "Sch\xE9ma vide : aucune table. Les types g\xE9n\xE9r\xE9s seraient inutilisables.";
|
|
@@ -275,8 +389,9 @@ function diagnostiquerSchema(tables) {
|
|
|
275
389
|
function parseArgs(argv) {
|
|
276
390
|
const a = {};
|
|
277
391
|
for (let i = 0; i < argv.length; i++) {
|
|
392
|
+
const arg = argv[i];
|
|
278
393
|
const v = argv[i + 1];
|
|
279
|
-
switch (
|
|
394
|
+
switch (arg) {
|
|
280
395
|
case "--url":
|
|
281
396
|
a.url = v;
|
|
282
397
|
i++;
|
|
@@ -286,14 +401,17 @@ function parseArgs(argv) {
|
|
|
286
401
|
i++;
|
|
287
402
|
break;
|
|
288
403
|
case "--out":
|
|
404
|
+
case "-o":
|
|
289
405
|
a.out = v;
|
|
290
406
|
i++;
|
|
291
407
|
break;
|
|
292
408
|
case "--schema":
|
|
409
|
+
case "-s":
|
|
293
410
|
a.schema = v;
|
|
294
411
|
i++;
|
|
295
412
|
break;
|
|
296
413
|
case "--type-name":
|
|
414
|
+
case "-t":
|
|
297
415
|
a.typeName = v;
|
|
298
416
|
i++;
|
|
299
417
|
break;
|
|
@@ -301,18 +419,69 @@ function parseArgs(argv) {
|
|
|
301
419
|
case "--allow-empty":
|
|
302
420
|
a.allowEmpty = true;
|
|
303
421
|
break;
|
|
422
|
+
case "--help":
|
|
423
|
+
case "-h":
|
|
424
|
+
a.help = true;
|
|
425
|
+
break;
|
|
426
|
+
case "--version":
|
|
427
|
+
case "-v":
|
|
428
|
+
a.version = true;
|
|
429
|
+
break;
|
|
304
430
|
}
|
|
305
431
|
}
|
|
306
432
|
return a;
|
|
307
433
|
}
|
|
308
|
-
var
|
|
434
|
+
var HELP_TEXT = `
|
|
435
|
+
aurabase-gen (v${VERSION}) \u2014 G\xE9n\xE9rateur de types TypeScript pour Aurabase
|
|
436
|
+
|
|
437
|
+
USAGE :
|
|
438
|
+
npx @aurabase/gen [options]
|
|
439
|
+
aurabase-gen --url <projectUrl> --key <apiKey> [--out <fichier>]
|
|
440
|
+
|
|
441
|
+
OPTIONS :
|
|
442
|
+
--url <url> URL du projet Aurabase (ex: https://mon-projet.aurabase.cloud)
|
|
443
|
+
[Auto-d\xE9tection : AURABASE_URL, NEXT_PUBLIC_AURABASE_URL, VITE_AURABASE_URL]
|
|
444
|
+
--key <cle> Cl\xE9 API du projet (anon ou service_role)
|
|
445
|
+
[Auto-d\xE9tection : AURABASE_API_KEY, AURABASE_ANON_KEY, AURABASE_SERVICE_ROLE_KEY]
|
|
446
|
+
-o, --out <fichier> Fichier de destination (ex: src/types/database.types.ts)
|
|
447
|
+
Si omis, le r\xE9sultat est \xE9crit sur stdout.
|
|
448
|
+
-s, --schema <nom> Nom du sch\xE9ma de base de donn\xE9es (d\xE9faut : 'public')
|
|
449
|
+
-t, --type-name <t> Nom de l'interface principale g\xE9n\xE9r\xE9e (d\xE9faut : 'Database')
|
|
450
|
+
--allow-empty G\xE9n\xE9rer les types m\xEAme si des tables n'ont pas de colonnes d\xE9clar\xE9es
|
|
451
|
+
-h, --help Afficher cette aide
|
|
452
|
+
-v, --version Afficher la version
|
|
453
|
+
|
|
454
|
+
EXEMPLES :
|
|
455
|
+
# G\xE9n\xE9ration avec lecture automatique des variables d'environnement (.env / .env.local) :
|
|
456
|
+
npx @aurabase/gen --out src/types/database.types.ts
|
|
457
|
+
|
|
458
|
+
# Param\xE8tres explicites :
|
|
459
|
+
npx @aurabase/gen --url https://xyz.aurabase.cloud --key aura_anon_123 --out db.types.ts
|
|
460
|
+
`;
|
|
309
461
|
async function main() {
|
|
462
|
+
loadEnvFiles();
|
|
310
463
|
const args = parseArgs(process.argv.slice(2));
|
|
311
|
-
if (
|
|
312
|
-
console.
|
|
464
|
+
if (args.help) {
|
|
465
|
+
console.log(HELP_TEXT.trim());
|
|
466
|
+
process.exit(0);
|
|
467
|
+
}
|
|
468
|
+
if (args.version) {
|
|
469
|
+
console.log(`aurabase-gen v${VERSION}`);
|
|
470
|
+
process.exit(0);
|
|
471
|
+
}
|
|
472
|
+
const url = args.url ?? process.env.AURABASE_URL ?? process.env.NEXT_PUBLIC_AURABASE_URL ?? process.env.VITE_AURABASE_URL;
|
|
473
|
+
const key = args.key ?? process.env.AURABASE_SERVICE_ROLE_KEY ?? process.env.AURABASE_API_KEY ?? process.env.AURABASE_ANON_KEY ?? process.env.NEXT_PUBLIC_AURABASE_ANON_KEY ?? process.env.VITE_AURABASE_ANON_KEY;
|
|
474
|
+
if (!url || !key) {
|
|
475
|
+
console.error("[aurabase-gen] Erreur : URL et/ou cl\xE9 API du projet manquantes.\n");
|
|
476
|
+
console.error("Sp\xE9cifiez-les via les arguments CLI (--url et --key) ou dans vos variables d\u2019environnement (.env / .env.local) :");
|
|
477
|
+
console.error(" AURABASE_URL=https://<slug>.aurabase.cloud");
|
|
478
|
+
console.error(" AURABASE_ANON_KEY=aura_anon_...\n");
|
|
479
|
+
console.error("Ex\xE9cutez `npx @aurabase/gen --help` pour afficher toutes les options disponibles.");
|
|
313
480
|
process.exit(1);
|
|
314
481
|
}
|
|
315
|
-
const
|
|
482
|
+
const schemaName = args.schema ?? process.env.AURABASE_SCHEMA ?? "public";
|
|
483
|
+
const outPath = args.out ?? process.env.AURABASE_TYPES_OUT;
|
|
484
|
+
const client = createClient(url, key);
|
|
316
485
|
const { data, error } = await client.db.schema();
|
|
317
486
|
if (error) {
|
|
318
487
|
console.error(`[aurabase-gen] Erreur de r\xE9cup\xE9ration du sch\xE9ma : ${error.message}`);
|
|
@@ -330,16 +499,16 @@ async function main() {
|
|
|
330
499
|
console.error(`[aurabase-gen] Avertissement (--allow-empty) : ${probleme}`);
|
|
331
500
|
}
|
|
332
501
|
const output = generateDatabaseTypes(tables, {
|
|
333
|
-
schemaName
|
|
502
|
+
schemaName,
|
|
334
503
|
typeName: args.typeName,
|
|
335
504
|
functions,
|
|
336
505
|
enums,
|
|
337
506
|
views
|
|
338
507
|
});
|
|
339
|
-
if (
|
|
340
|
-
writeFileSync(
|
|
508
|
+
if (outPath) {
|
|
509
|
+
writeFileSync(outPath, output);
|
|
341
510
|
console.error(
|
|
342
|
-
`[aurabase-gen] \u2713 Types \xE9crits dans ${
|
|
511
|
+
`[aurabase-gen] \u2713 Types \xE9crits dans ${outPath} (${tables.length} table(s), ${functions.length} fonction(s), ${enums.length} enum(s), ${views.length} vue(s)).`
|
|
343
512
|
);
|
|
344
513
|
} else {
|
|
345
514
|
process.stdout.write(output);
|
|
@@ -352,4 +521,4 @@ if (process.argv[1] && /aurabase-gen|cli\.(ts|js|mjs|cjs)$/.test(process.argv[1]
|
|
|
352
521
|
});
|
|
353
522
|
}
|
|
354
523
|
|
|
355
|
-
export { diagnostiquerSchema };
|
|
524
|
+
export { VERSION, diagnostiquerSchema, loadEnvFiles, parseArgs };
|
package/dist/index.cjs
CHANGED
|
@@ -256,6 +256,86 @@ export interface ${typeName} {
|
|
|
256
256
|
CompositeTypes: Record<string, never>
|
|
257
257
|
}
|
|
258
258
|
}
|
|
259
|
+
|
|
260
|
+
export type Tables<
|
|
261
|
+
PublicTableNameOrOptions extends
|
|
262
|
+
| keyof (${typeName}['${schemaName}']['Tables'] & ${typeName}['${schemaName}']['Views'])
|
|
263
|
+
| { schema: keyof ${typeName} },
|
|
264
|
+
TableName extends PublicTableNameOrOptions extends { schema: keyof ${typeName} }
|
|
265
|
+
? keyof (${typeName}[PublicTableNameOrOptions['schema']]['Tables'] &
|
|
266
|
+
${typeName}[PublicTableNameOrOptions['schema']]['Views'])
|
|
267
|
+
: never = never,
|
|
268
|
+
> = PublicTableNameOrOptions extends { schema: keyof ${typeName} }
|
|
269
|
+
? (${typeName}[PublicTableNameOrOptions['schema']]['Tables'] &
|
|
270
|
+
${typeName}[PublicTableNameOrOptions['schema']]['Views'])[TableName] extends {
|
|
271
|
+
Row: infer R
|
|
272
|
+
}
|
|
273
|
+
? R
|
|
274
|
+
: never
|
|
275
|
+
: PublicTableNameOrOptions extends keyof (${typeName}['${schemaName}']['Tables'] &
|
|
276
|
+
${typeName}['${schemaName}']['Views'])
|
|
277
|
+
? (${typeName}['${schemaName}']['Tables'] &
|
|
278
|
+
${typeName}['${schemaName}']['Views'])[PublicTableNameOrOptions] extends {
|
|
279
|
+
Row: infer R
|
|
280
|
+
}
|
|
281
|
+
? R
|
|
282
|
+
: never
|
|
283
|
+
: never
|
|
284
|
+
|
|
285
|
+
export type TablesInsert<
|
|
286
|
+
PublicTableNameOrOptions extends
|
|
287
|
+
| keyof ${typeName}['${schemaName}']['Tables']
|
|
288
|
+
| { schema: keyof ${typeName} },
|
|
289
|
+
TableName extends PublicTableNameOrOptions extends { schema: keyof ${typeName} }
|
|
290
|
+
? keyof ${typeName}[PublicTableNameOrOptions['schema']]['Tables']
|
|
291
|
+
: never = never,
|
|
292
|
+
> = PublicTableNameOrOptions extends { schema: keyof ${typeName} }
|
|
293
|
+
? ${typeName}[PublicTableNameOrOptions['schema']]['Tables'][TableName] extends {
|
|
294
|
+
Insert: infer I
|
|
295
|
+
}
|
|
296
|
+
? I
|
|
297
|
+
: never
|
|
298
|
+
: PublicTableNameOrOptions extends keyof ${typeName}['${schemaName}']['Tables']
|
|
299
|
+
? ${typeName}['${schemaName}']['Tables'][PublicTableNameOrOptions] extends {
|
|
300
|
+
Insert: infer I
|
|
301
|
+
}
|
|
302
|
+
? I
|
|
303
|
+
: never
|
|
304
|
+
: never
|
|
305
|
+
|
|
306
|
+
export type TablesUpdate<
|
|
307
|
+
PublicTableNameOrOptions extends
|
|
308
|
+
| keyof ${typeName}['${schemaName}']['Tables']
|
|
309
|
+
| { schema: keyof ${typeName} },
|
|
310
|
+
TableName extends PublicTableNameOrOptions extends { schema: keyof ${typeName} }
|
|
311
|
+
? keyof ${typeName}[PublicTableNameOrOptions['schema']]['Tables']
|
|
312
|
+
: never = never,
|
|
313
|
+
> = PublicTableNameOrOptions extends { schema: keyof ${typeName} }
|
|
314
|
+
? ${typeName}[PublicTableNameOrOptions['schema']]['Tables'][TableName] extends {
|
|
315
|
+
Update: infer U
|
|
316
|
+
}
|
|
317
|
+
? U
|
|
318
|
+
: never
|
|
319
|
+
: PublicTableNameOrOptions extends keyof ${typeName}['${schemaName}']['Tables']
|
|
320
|
+
? ${typeName}['${schemaName}']['Tables'][PublicTableNameOrOptions] extends {
|
|
321
|
+
Update: infer U
|
|
322
|
+
}
|
|
323
|
+
? U
|
|
324
|
+
: never
|
|
325
|
+
: never
|
|
326
|
+
|
|
327
|
+
export type Enums<
|
|
328
|
+
PublicEnumNameOrOptions extends
|
|
329
|
+
| keyof ${typeName}['${schemaName}']['Enums']
|
|
330
|
+
| { schema: keyof ${typeName} },
|
|
331
|
+
EnumName extends PublicEnumNameOrOptions extends { schema: keyof ${typeName} }
|
|
332
|
+
? keyof ${typeName}[PublicEnumNameOrOptions['schema']]['Enums']
|
|
333
|
+
: never = never,
|
|
334
|
+
> = PublicEnumNameOrOptions extends { schema: keyof ${typeName} }
|
|
335
|
+
? ${typeName}[PublicEnumNameOrOptions['schema']]['Enums'][EnumName]
|
|
336
|
+
: PublicEnumNameOrOptions extends keyof ${typeName}['${schemaName}']['Enums']
|
|
337
|
+
? ${typeName}['${schemaName}']['Enums'][PublicEnumNameOrOptions]
|
|
338
|
+
: never
|
|
259
339
|
`;
|
|
260
340
|
}
|
|
261
341
|
|
package/dist/index.js
CHANGED
|
@@ -254,6 +254,86 @@ export interface ${typeName} {
|
|
|
254
254
|
CompositeTypes: Record<string, never>
|
|
255
255
|
}
|
|
256
256
|
}
|
|
257
|
+
|
|
258
|
+
export type Tables<
|
|
259
|
+
PublicTableNameOrOptions extends
|
|
260
|
+
| keyof (${typeName}['${schemaName}']['Tables'] & ${typeName}['${schemaName}']['Views'])
|
|
261
|
+
| { schema: keyof ${typeName} },
|
|
262
|
+
TableName extends PublicTableNameOrOptions extends { schema: keyof ${typeName} }
|
|
263
|
+
? keyof (${typeName}[PublicTableNameOrOptions['schema']]['Tables'] &
|
|
264
|
+
${typeName}[PublicTableNameOrOptions['schema']]['Views'])
|
|
265
|
+
: never = never,
|
|
266
|
+
> = PublicTableNameOrOptions extends { schema: keyof ${typeName} }
|
|
267
|
+
? (${typeName}[PublicTableNameOrOptions['schema']]['Tables'] &
|
|
268
|
+
${typeName}[PublicTableNameOrOptions['schema']]['Views'])[TableName] extends {
|
|
269
|
+
Row: infer R
|
|
270
|
+
}
|
|
271
|
+
? R
|
|
272
|
+
: never
|
|
273
|
+
: PublicTableNameOrOptions extends keyof (${typeName}['${schemaName}']['Tables'] &
|
|
274
|
+
${typeName}['${schemaName}']['Views'])
|
|
275
|
+
? (${typeName}['${schemaName}']['Tables'] &
|
|
276
|
+
${typeName}['${schemaName}']['Views'])[PublicTableNameOrOptions] extends {
|
|
277
|
+
Row: infer R
|
|
278
|
+
}
|
|
279
|
+
? R
|
|
280
|
+
: never
|
|
281
|
+
: never
|
|
282
|
+
|
|
283
|
+
export type TablesInsert<
|
|
284
|
+
PublicTableNameOrOptions extends
|
|
285
|
+
| keyof ${typeName}['${schemaName}']['Tables']
|
|
286
|
+
| { schema: keyof ${typeName} },
|
|
287
|
+
TableName extends PublicTableNameOrOptions extends { schema: keyof ${typeName} }
|
|
288
|
+
? keyof ${typeName}[PublicTableNameOrOptions['schema']]['Tables']
|
|
289
|
+
: never = never,
|
|
290
|
+
> = PublicTableNameOrOptions extends { schema: keyof ${typeName} }
|
|
291
|
+
? ${typeName}[PublicTableNameOrOptions['schema']]['Tables'][TableName] extends {
|
|
292
|
+
Insert: infer I
|
|
293
|
+
}
|
|
294
|
+
? I
|
|
295
|
+
: never
|
|
296
|
+
: PublicTableNameOrOptions extends keyof ${typeName}['${schemaName}']['Tables']
|
|
297
|
+
? ${typeName}['${schemaName}']['Tables'][PublicTableNameOrOptions] extends {
|
|
298
|
+
Insert: infer I
|
|
299
|
+
}
|
|
300
|
+
? I
|
|
301
|
+
: never
|
|
302
|
+
: never
|
|
303
|
+
|
|
304
|
+
export type TablesUpdate<
|
|
305
|
+
PublicTableNameOrOptions extends
|
|
306
|
+
| keyof ${typeName}['${schemaName}']['Tables']
|
|
307
|
+
| { schema: keyof ${typeName} },
|
|
308
|
+
TableName extends PublicTableNameOrOptions extends { schema: keyof ${typeName} }
|
|
309
|
+
? keyof ${typeName}[PublicTableNameOrOptions['schema']]['Tables']
|
|
310
|
+
: never = never,
|
|
311
|
+
> = PublicTableNameOrOptions extends { schema: keyof ${typeName} }
|
|
312
|
+
? ${typeName}[PublicTableNameOrOptions['schema']]['Tables'][TableName] extends {
|
|
313
|
+
Update: infer U
|
|
314
|
+
}
|
|
315
|
+
? U
|
|
316
|
+
: never
|
|
317
|
+
: PublicTableNameOrOptions extends keyof ${typeName}['${schemaName}']['Tables']
|
|
318
|
+
? ${typeName}['${schemaName}']['Tables'][PublicTableNameOrOptions] extends {
|
|
319
|
+
Update: infer U
|
|
320
|
+
}
|
|
321
|
+
? U
|
|
322
|
+
: never
|
|
323
|
+
: never
|
|
324
|
+
|
|
325
|
+
export type Enums<
|
|
326
|
+
PublicEnumNameOrOptions extends
|
|
327
|
+
| keyof ${typeName}['${schemaName}']['Enums']
|
|
328
|
+
| { schema: keyof ${typeName} },
|
|
329
|
+
EnumName extends PublicEnumNameOrOptions extends { schema: keyof ${typeName} }
|
|
330
|
+
? keyof ${typeName}[PublicEnumNameOrOptions['schema']]['Enums']
|
|
331
|
+
: never = never,
|
|
332
|
+
> = PublicEnumNameOrOptions extends { schema: keyof ${typeName} }
|
|
333
|
+
? ${typeName}[PublicEnumNameOrOptions['schema']]['Enums'][EnumName]
|
|
334
|
+
: PublicEnumNameOrOptions extends keyof ${typeName}['${schemaName}']['Enums']
|
|
335
|
+
? ${typeName}['${schemaName}']['Enums'][PublicEnumNameOrOptions]
|
|
336
|
+
: never
|
|
257
337
|
`;
|
|
258
338
|
}
|
|
259
339
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aurabase/gen",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.4",
|
|
4
4
|
"description": "Générateur de types TypeScript Database pour le SDK Aurabase (CLI aurabase-gen)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -49,8 +49,8 @@
|
|
|
49
49
|
"types"
|
|
50
50
|
],
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@aurabase/core": "0.5.
|
|
53
|
-
"@aurabase/aurabase-js": "0.5.
|
|
52
|
+
"@aurabase/core": "0.5.4",
|
|
53
|
+
"@aurabase/aurabase-js": "0.5.4"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"tsup": "^8.0.0",
|