@aurabase/aurabase-js 0.3.1 → 0.4.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.
Files changed (86) hide show
  1. package/README.md +26 -795
  2. package/{packages/aurabase/dist/AuraClient-DAtDbfPB.d.ts → dist/AuraClient-BcFE8u1v.d.cts} +1 -1
  3. package/{packages/aurabase/dist/AuraClient-DAtDbfPB.d.cts → dist/AuraClient-BcFE8u1v.d.ts} +1 -1
  4. package/{packages/aurabase/dist → dist}/index.d.cts +1 -1
  5. package/{packages/aurabase/dist → dist}/index.d.ts +1 -1
  6. package/{packages/aurabase/dist → dist}/ssr.d.cts +1 -1
  7. package/{packages/aurabase/dist → dist}/ssr.d.ts +1 -1
  8. package/package.json +72 -82
  9. package/.changeset/config.json +0 -11
  10. package/CHANGELOG.md +0 -30
  11. package/packages/ai/LICENSE +0 -21
  12. package/packages/ai/README.md +0 -106
  13. package/packages/ai/dist/index.cjs +0 -229
  14. package/packages/ai/dist/index.d.cts +0 -139
  15. package/packages/ai/dist/index.d.ts +0 -139
  16. package/packages/ai/dist/index.js +0 -226
  17. package/packages/ai/package.json +0 -61
  18. package/packages/aurabase/LICENSE +0 -21
  19. package/packages/aurabase/README.md +0 -64
  20. package/packages/aurabase/package.json +0 -80
  21. package/packages/aurabase/vitest.e2e.config.ts +0 -9
  22. package/packages/auth/LICENSE +0 -21
  23. package/packages/auth/README.md +0 -215
  24. package/packages/auth/dist/index.cjs +0 -1175
  25. package/packages/auth/dist/index.d.cts +0 -397
  26. package/packages/auth/dist/index.d.ts +0 -397
  27. package/packages/auth/dist/index.js +0 -1170
  28. package/packages/auth/package.json +0 -61
  29. package/packages/core/LICENSE +0 -21
  30. package/packages/core/README.md +0 -132
  31. package/packages/core/dist/index.cjs +0 -695
  32. package/packages/core/dist/index.d.cts +0 -1137
  33. package/packages/core/dist/index.d.ts +0 -1137
  34. package/packages/core/dist/index.js +0 -673
  35. package/packages/core/package.json +0 -57
  36. package/packages/db/LICENSE +0 -21
  37. package/packages/db/README.md +0 -152
  38. package/packages/db/VENDORED.md +0 -93
  39. package/packages/db/dist/index.cjs +0 -544
  40. package/packages/db/dist/index.d.cts +0 -1111
  41. package/packages/db/dist/index.d.ts +0 -1111
  42. package/packages/db/dist/index.js +0 -541
  43. package/packages/db/package.json +0 -62
  44. package/packages/functions/LICENSE +0 -21
  45. package/packages/functions/README.md +0 -96
  46. package/packages/functions/dist/index.cjs +0 -173
  47. package/packages/functions/dist/index.d.cts +0 -81
  48. package/packages/functions/dist/index.d.ts +0 -81
  49. package/packages/functions/dist/index.js +0 -168
  50. package/packages/functions/package.json +0 -60
  51. package/packages/gen/LICENSE +0 -21
  52. package/packages/gen/README.md +0 -84
  53. package/packages/gen/dist/cli.cjs +0 -334
  54. package/packages/gen/dist/cli.d.cts +0 -1
  55. package/packages/gen/dist/cli.d.ts +0 -1
  56. package/packages/gen/dist/cli.js +0 -332
  57. package/packages/gen/dist/index.cjs +0 -257
  58. package/packages/gen/dist/index.d.cts +0 -12
  59. package/packages/gen/dist/index.d.ts +0 -12
  60. package/packages/gen/dist/index.js +0 -255
  61. package/packages/gen/package.json +0 -66
  62. package/packages/notifications/LICENSE +0 -21
  63. package/packages/notifications/README.md +0 -134
  64. package/packages/notifications/dist/index.cjs +0 -128
  65. package/packages/notifications/dist/index.d.cts +0 -81
  66. package/packages/notifications/dist/index.d.ts +0 -81
  67. package/packages/notifications/dist/index.js +0 -125
  68. package/packages/notifications/package.json +0 -60
  69. package/packages/realtime/LICENSE +0 -21
  70. package/packages/realtime/README.md +0 -183
  71. package/packages/realtime/dist/index.cjs +0 -977
  72. package/packages/realtime/dist/index.d.cts +0 -259
  73. package/packages/realtime/dist/index.d.ts +0 -259
  74. package/packages/realtime/dist/index.js +0 -973
  75. package/packages/realtime/package.json +0 -60
  76. package/packages/storage/LICENSE +0 -21
  77. package/packages/storage/README.md +0 -141
  78. package/packages/storage/dist/index.cjs +0 -333
  79. package/packages/storage/dist/index.d.cts +0 -185
  80. package/packages/storage/dist/index.d.ts +0 -185
  81. package/packages/storage/dist/index.js +0 -329
  82. package/packages/storage/package.json +0 -60
  83. /package/{packages/aurabase/dist → dist}/index.cjs +0 -0
  84. /package/{packages/aurabase/dist → dist}/index.js +0 -0
  85. /package/{packages/aurabase/dist → dist}/ssr.cjs +0 -0
  86. /package/{packages/aurabase/dist → dist}/ssr.js +0 -0
@@ -1,332 +0,0 @@
1
- #!/usr/bin/env node
2
- import { writeFileSync } from 'fs';
3
- import { createClient } from 'aurabase';
4
-
5
- // src/generate.ts
6
- function enumRef(name, ctx) {
7
- return ctx.enumNames.has(name) ? `${ctx.typeName}['${ctx.schemaName}']['Enums']['${name}']` : (
8
- // Enum inconnu du bloc Enums → auto-référence non résoluble → repli textuel.
9
- "string"
10
- );
11
- }
12
- function mapColType(colType, ctx) {
13
- if (typeof colType === "string") {
14
- switch (colType) {
15
- case "text":
16
- case "varchar":
17
- case "bpchar":
18
- case "uuid":
19
- case "timestamp":
20
- case "timestamptz":
21
- case "date":
22
- case "time":
23
- case "bytea":
24
- case "numeric":
25
- return "string";
26
- case "int":
27
- case "int2":
28
- case "int4":
29
- case "int8":
30
- case "bigint":
31
- case "float":
32
- case "float4":
33
- case "float8":
34
- return "number";
35
- case "bool":
36
- return "boolean";
37
- case "json":
38
- case "jsonb":
39
- return "Json";
40
- default:
41
- return "unknown";
42
- }
43
- }
44
- if (colType && typeof colType === "object") {
45
- if ("array" in colType) return `${mapColType(colType.array, ctx)}[]`;
46
- if ("vector" in colType) return "number[]";
47
- if ("enum" in colType) return enumRef(String(colType.enum), ctx);
48
- }
49
- return "unknown";
50
- }
51
- function mapPgType(raw, ctx) {
52
- if (raw.startsWith("_")) return `${mapPgType(raw.slice(1), ctx)}[]`;
53
- switch (raw) {
54
- case "int2":
55
- case "int4":
56
- case "int8":
57
- case "float4":
58
- case "float8":
59
- return "number";
60
- case "numeric":
61
- return "string";
62
- case "bool":
63
- return "boolean";
64
- case "text":
65
- case "varchar":
66
- case "bpchar":
67
- case "citext":
68
- case "uuid":
69
- case "date":
70
- case "time":
71
- case "timetz":
72
- case "timestamp":
73
- case "timestamptz":
74
- case "bytea":
75
- return "string";
76
- case "json":
77
- case "jsonb":
78
- return "Json";
79
- case "void":
80
- return "undefined";
81
- case "record":
82
- return "unknown";
83
- default:
84
- return ctx.enumNames.has(raw) ? enumRef(raw, ctx) : "unknown";
85
- }
86
- }
87
- function tsType(col, ctx) {
88
- const base = mapColType(col.col_type, ctx);
89
- return col.nullable ? `${base} | null` : base;
90
- }
91
- function genRow(cols, ctx) {
92
- return cols.map((c) => ` ${c.name}: ${tsType(c, ctx)}`).join("\n");
93
- }
94
- var AUTO_COLS = /* @__PURE__ */ new Set(["id", "created_at", "updated_at"]);
95
- function isInsertOptional(col) {
96
- return col.nullable || col.default_val != null || AUTO_COLS.has(col.name);
97
- }
98
- function genInsert(cols, ctx) {
99
- return cols.map((c) => ` ${c.name}${isInsertOptional(c) ? "?" : ""}: ${tsType(c, ctx)}`).join("\n");
100
- }
101
- function genUpdate(cols, ctx) {
102
- return cols.map((c) => ` ${c.name}?: ${tsType(c, ctx)}`).join("\n");
103
- }
104
- function genRelationships(t) {
105
- const fks = t.columns.filter((c) => c.references);
106
- if (fks.length === 0) return "[]";
107
- const groups = /* @__PURE__ */ new Map();
108
- for (const c of fks) {
109
- const ref = c.references;
110
- const name = ref.constraint_name ?? `${t.name}_${c.name}_fkey`;
111
- const key = ref.constraint_name ?? `\0synthetic\0${c.name}`;
112
- let g = groups.get(key);
113
- if (!g) {
114
- g = { name, columns: [], refTable: ref.table, refColumns: [], cols: [] };
115
- groups.set(key, g);
116
- }
117
- g.columns.push(c.name);
118
- g.refColumns.push(ref.column);
119
- g.cols.push(c);
120
- }
121
- const entries = [...groups.values()].map((g) => {
122
- const isOneToOne = g.cols.every((c) => c.unique || t.primary_key === c.name);
123
- const cols = g.columns.map((c) => `'${c}'`).join(", ");
124
- const refCols = g.refColumns.map((c) => `'${c}'`).join(", ");
125
- return ` {
126
- foreignKeyName: '${g.name}'
127
- columns: [${cols}]
128
- isOneToOne: ${isOneToOne}
129
- referencedRelation: '${g.refTable}'
130
- referencedColumns: [${refCols}]
131
- }`;
132
- });
133
- return `[
134
- ${entries.join(",\n")}
135
- ]`;
136
- }
137
- function genFunctionArgs(fn, ctx) {
138
- const inputArgs = fn.args.filter((a) => a.mode.toUpperCase() !== "OUT");
139
- if (inputArgs.length === 0) return "Record<string, never>";
140
- const entries = inputArgs.map((a) => `${a.name}: ${mapPgType(a.data_type, ctx)}`).join("; ");
141
- return `{ ${entries} }`;
142
- }
143
- function mapReturnType(fn, ctx) {
144
- const base = mapPgType(fn.returns, ctx);
145
- if (!fn.is_set_returning) return base;
146
- return base === "unknown" ? "Record<string, unknown>[]" : `${base}[]`;
147
- }
148
- function genSetofOptions(fn, ctx) {
149
- if (!fn.is_set_returning) return null;
150
- const to = ctx.relationNames.has(fn.returns) ? fn.returns : fn.name;
151
- return `{ isSetofReturn: true; isOneToOne: false; to: '${to}'; from: '*' }`;
152
- }
153
- function genFunctionsBody(functions, ctx) {
154
- if (functions.length === 0) return "Record<string, never>";
155
- const groups = /* @__PURE__ */ new Map();
156
- for (const fn of functions) {
157
- const g = groups.get(fn.name);
158
- if (g) g.push(fn);
159
- else groups.set(fn.name, [fn]);
160
- }
161
- const entries = [...groups.values()].map((overloads) => {
162
- const argsUnion = uniq(overloads.map((fn) => genFunctionArgs(fn, ctx))).join(" | ");
163
- const returnsUnion = uniq(overloads.map((fn) => mapReturnType(fn, ctx))).join(" | ");
164
- const lines = [
165
- ` ${overloads[0].name}: {`,
166
- ` Args: ${argsUnion}`,
167
- ` Returns: ${returnsUnion}`
168
- ];
169
- if (overloads.length === 1) {
170
- const setofOptions = genSetofOptions(overloads[0], ctx);
171
- if (setofOptions) lines.push(` SetofOptions: ${setofOptions}`);
172
- }
173
- lines.push(" }");
174
- return lines.join("\n");
175
- });
176
- return `{
177
- ${entries.join("\n")}
178
- }`;
179
- }
180
- function uniq(items) {
181
- return [...new Set(items)];
182
- }
183
- function genEnumsBody(enums) {
184
- if (enums.length === 0) return "Record<string, never>";
185
- const entries = enums.map((e) => {
186
- const union = e.values.length === 0 ? "never" : e.values.map((v) => `'${v}'`).join(" | ");
187
- return ` ${e.name}: ${union}`;
188
- });
189
- return `{
190
- ${entries.join("\n")}
191
- }`;
192
- }
193
- function genViewsBody(views, ctx) {
194
- if (views.length === 0) return "Record<string, never>";
195
- const entries = views.map(
196
- (v) => ` ${v.name}: {
197
- Row: {
198
- ${genRow(v.columns, ctx)}
199
- }
200
- Relationships: []
201
- }`
202
- );
203
- return `{
204
- ${entries.join("\n")}
205
- }`;
206
- }
207
- var HEADER = `// ============================================================
208
- // Types TypeScript auto-g\xE9n\xE9r\xE9s par Aurabase (@aurabase/gen)
209
- // NE PAS MODIFIER \u2014 r\xE9g\xE9n\xE9rer avec \`npx @aurabase/gen\`
210
- // ============================================================
211
- `;
212
- function generateDatabaseTypes(tables, options = {}) {
213
- const schemaName = options.schemaName ?? "public";
214
- const typeName = options.typeName ?? "Database";
215
- const enums = options.enums ?? [];
216
- const views = options.views ?? [];
217
- const relationNames = new Set([...tables, ...views].map((r) => r.name));
218
- const ctx = { typeName, schemaName, enumNames: new Set(enums.map((e) => e.name)), relationNames };
219
- const functionsBody = genFunctionsBody(options.functions ?? [], ctx);
220
- const enumsBody = genEnumsBody(enums);
221
- const viewsBody = genViewsBody(views, ctx);
222
- const tablesBody = tables.length === 0 ? "Record<string, never>" : `{
223
- ${tables.map(
224
- (t) => ` ${t.name}: {
225
- Row: {
226
- ${genRow(t.columns, ctx)}
227
- }
228
- Insert: {
229
- ${genInsert(t.columns, ctx)}
230
- }
231
- Update: {
232
- ${genUpdate(t.columns, ctx)}
233
- }
234
- Relationships: ${genRelationships(t)}
235
- }`
236
- ).join("\n")}
237
- }`;
238
- return `${HEADER}
239
- export type Json =
240
- | string
241
- | number
242
- | boolean
243
- | null
244
- | { [key: string]: Json | undefined }
245
- | Json[]
246
-
247
- export interface ${typeName} {
248
- ${schemaName}: {
249
- Tables: ${tablesBody}
250
- Views: ${viewsBody}
251
- Functions: ${functionsBody}
252
- Enums: ${enumsBody}
253
- CompositeTypes: Record<string, never>
254
- }
255
- }
256
- `;
257
- }
258
-
259
- // src/cli.ts
260
- function parseArgs(argv) {
261
- const a = {};
262
- for (let i = 0; i < argv.length; i++) {
263
- const v = argv[i + 1];
264
- switch (argv[i]) {
265
- case "--url":
266
- a.url = v;
267
- i++;
268
- break;
269
- case "--project":
270
- a.project = v;
271
- i++;
272
- break;
273
- case "--key":
274
- a.key = v;
275
- i++;
276
- break;
277
- case "--out":
278
- a.out = v;
279
- i++;
280
- break;
281
- case "--schema":
282
- a.schema = v;
283
- i++;
284
- break;
285
- case "--type-name":
286
- a.typeName = v;
287
- i++;
288
- break;
289
- }
290
- }
291
- return a;
292
- }
293
- var USAGE = `Usage: aurabase-gen --url <baseUrl> --project <id> [--key <apiKey>] [--out database.types.ts] [--schema public] [--type-name Database]`;
294
- async function main() {
295
- const args = parseArgs(process.argv.slice(2));
296
- if (!args.url || !args.project) {
297
- console.error(USAGE);
298
- process.exit(1);
299
- }
300
- const client = createClient(args.url, args.project, args.key);
301
- const { data, error } = await client.db.schema();
302
- if (error) {
303
- console.error(`[aurabase-gen] Erreur de r\xE9cup\xE9ration du sch\xE9ma : ${error.message}`);
304
- process.exit(1);
305
- }
306
- const tables = data?.tables ?? [];
307
- const functions = data?.functions ?? [];
308
- const enums = data?.enums ?? [];
309
- const views = data?.views ?? [];
310
- if (tables.length === 0) {
311
- console.error("[aurabase-gen] Avertissement : sch\xE9ma vide (aucune table).");
312
- }
313
- const output = generateDatabaseTypes(tables, {
314
- schemaName: args.schema,
315
- typeName: args.typeName,
316
- functions,
317
- enums,
318
- views
319
- });
320
- if (args.out) {
321
- writeFileSync(args.out, output);
322
- console.error(
323
- `[aurabase-gen] \u2713 Types \xE9crits dans ${args.out} (${tables.length} table(s), ${functions.length} fonction(s), ${enums.length} enum(s), ${views.length} vue(s)).`
324
- );
325
- } else {
326
- process.stdout.write(output);
327
- }
328
- }
329
- main().catch((e) => {
330
- console.error("[aurabase-gen]", e instanceof Error ? e.message : e);
331
- process.exit(1);
332
- });
@@ -1,257 +0,0 @@
1
- 'use strict';
2
-
3
- // src/generate.ts
4
- function enumRef(name, ctx) {
5
- return ctx.enumNames.has(name) ? `${ctx.typeName}['${ctx.schemaName}']['Enums']['${name}']` : (
6
- // Enum inconnu du bloc Enums → auto-référence non résoluble → repli textuel.
7
- "string"
8
- );
9
- }
10
- function mapColType(colType, ctx) {
11
- if (typeof colType === "string") {
12
- switch (colType) {
13
- case "text":
14
- case "varchar":
15
- case "bpchar":
16
- case "uuid":
17
- case "timestamp":
18
- case "timestamptz":
19
- case "date":
20
- case "time":
21
- case "bytea":
22
- case "numeric":
23
- return "string";
24
- case "int":
25
- case "int2":
26
- case "int4":
27
- case "int8":
28
- case "bigint":
29
- case "float":
30
- case "float4":
31
- case "float8":
32
- return "number";
33
- case "bool":
34
- return "boolean";
35
- case "json":
36
- case "jsonb":
37
- return "Json";
38
- default:
39
- return "unknown";
40
- }
41
- }
42
- if (colType && typeof colType === "object") {
43
- if ("array" in colType) return `${mapColType(colType.array, ctx)}[]`;
44
- if ("vector" in colType) return "number[]";
45
- if ("enum" in colType) return enumRef(String(colType.enum), ctx);
46
- }
47
- return "unknown";
48
- }
49
- function mapPgType(raw, ctx) {
50
- if (raw.startsWith("_")) return `${mapPgType(raw.slice(1), ctx)}[]`;
51
- switch (raw) {
52
- case "int2":
53
- case "int4":
54
- case "int8":
55
- case "float4":
56
- case "float8":
57
- return "number";
58
- case "numeric":
59
- return "string";
60
- case "bool":
61
- return "boolean";
62
- case "text":
63
- case "varchar":
64
- case "bpchar":
65
- case "citext":
66
- case "uuid":
67
- case "date":
68
- case "time":
69
- case "timetz":
70
- case "timestamp":
71
- case "timestamptz":
72
- case "bytea":
73
- return "string";
74
- case "json":
75
- case "jsonb":
76
- return "Json";
77
- case "void":
78
- return "undefined";
79
- case "record":
80
- return "unknown";
81
- default:
82
- return ctx.enumNames.has(raw) ? enumRef(raw, ctx) : "unknown";
83
- }
84
- }
85
- function tsType(col, ctx) {
86
- const base = mapColType(col.col_type, ctx);
87
- return col.nullable ? `${base} | null` : base;
88
- }
89
- function genRow(cols, ctx) {
90
- return cols.map((c) => ` ${c.name}: ${tsType(c, ctx)}`).join("\n");
91
- }
92
- var AUTO_COLS = /* @__PURE__ */ new Set(["id", "created_at", "updated_at"]);
93
- function isInsertOptional(col) {
94
- return col.nullable || col.default_val != null || AUTO_COLS.has(col.name);
95
- }
96
- function genInsert(cols, ctx) {
97
- return cols.map((c) => ` ${c.name}${isInsertOptional(c) ? "?" : ""}: ${tsType(c, ctx)}`).join("\n");
98
- }
99
- function genUpdate(cols, ctx) {
100
- return cols.map((c) => ` ${c.name}?: ${tsType(c, ctx)}`).join("\n");
101
- }
102
- function genRelationships(t) {
103
- const fks = t.columns.filter((c) => c.references);
104
- if (fks.length === 0) return "[]";
105
- const groups = /* @__PURE__ */ new Map();
106
- for (const c of fks) {
107
- const ref = c.references;
108
- const name = ref.constraint_name ?? `${t.name}_${c.name}_fkey`;
109
- const key = ref.constraint_name ?? `\0synthetic\0${c.name}`;
110
- let g = groups.get(key);
111
- if (!g) {
112
- g = { name, columns: [], refTable: ref.table, refColumns: [], cols: [] };
113
- groups.set(key, g);
114
- }
115
- g.columns.push(c.name);
116
- g.refColumns.push(ref.column);
117
- g.cols.push(c);
118
- }
119
- const entries = [...groups.values()].map((g) => {
120
- const isOneToOne = g.cols.every((c) => c.unique || t.primary_key === c.name);
121
- const cols = g.columns.map((c) => `'${c}'`).join(", ");
122
- const refCols = g.refColumns.map((c) => `'${c}'`).join(", ");
123
- return ` {
124
- foreignKeyName: '${g.name}'
125
- columns: [${cols}]
126
- isOneToOne: ${isOneToOne}
127
- referencedRelation: '${g.refTable}'
128
- referencedColumns: [${refCols}]
129
- }`;
130
- });
131
- return `[
132
- ${entries.join(",\n")}
133
- ]`;
134
- }
135
- function genFunctionArgs(fn, ctx) {
136
- const inputArgs = fn.args.filter((a) => a.mode.toUpperCase() !== "OUT");
137
- if (inputArgs.length === 0) return "Record<string, never>";
138
- const entries = inputArgs.map((a) => `${a.name}: ${mapPgType(a.data_type, ctx)}`).join("; ");
139
- return `{ ${entries} }`;
140
- }
141
- function mapReturnType(fn, ctx) {
142
- const base = mapPgType(fn.returns, ctx);
143
- if (!fn.is_set_returning) return base;
144
- return base === "unknown" ? "Record<string, unknown>[]" : `${base}[]`;
145
- }
146
- function genSetofOptions(fn, ctx) {
147
- if (!fn.is_set_returning) return null;
148
- const to = ctx.relationNames.has(fn.returns) ? fn.returns : fn.name;
149
- return `{ isSetofReturn: true; isOneToOne: false; to: '${to}'; from: '*' }`;
150
- }
151
- function genFunctionsBody(functions, ctx) {
152
- if (functions.length === 0) return "Record<string, never>";
153
- const groups = /* @__PURE__ */ new Map();
154
- for (const fn of functions) {
155
- const g = groups.get(fn.name);
156
- if (g) g.push(fn);
157
- else groups.set(fn.name, [fn]);
158
- }
159
- const entries = [...groups.values()].map((overloads) => {
160
- const argsUnion = uniq(overloads.map((fn) => genFunctionArgs(fn, ctx))).join(" | ");
161
- const returnsUnion = uniq(overloads.map((fn) => mapReturnType(fn, ctx))).join(" | ");
162
- const lines = [
163
- ` ${overloads[0].name}: {`,
164
- ` Args: ${argsUnion}`,
165
- ` Returns: ${returnsUnion}`
166
- ];
167
- if (overloads.length === 1) {
168
- const setofOptions = genSetofOptions(overloads[0], ctx);
169
- if (setofOptions) lines.push(` SetofOptions: ${setofOptions}`);
170
- }
171
- lines.push(" }");
172
- return lines.join("\n");
173
- });
174
- return `{
175
- ${entries.join("\n")}
176
- }`;
177
- }
178
- function uniq(items) {
179
- return [...new Set(items)];
180
- }
181
- function genEnumsBody(enums) {
182
- if (enums.length === 0) return "Record<string, never>";
183
- const entries = enums.map((e) => {
184
- const union = e.values.length === 0 ? "never" : e.values.map((v) => `'${v}'`).join(" | ");
185
- return ` ${e.name}: ${union}`;
186
- });
187
- return `{
188
- ${entries.join("\n")}
189
- }`;
190
- }
191
- function genViewsBody(views, ctx) {
192
- if (views.length === 0) return "Record<string, never>";
193
- const entries = views.map(
194
- (v) => ` ${v.name}: {
195
- Row: {
196
- ${genRow(v.columns, ctx)}
197
- }
198
- Relationships: []
199
- }`
200
- );
201
- return `{
202
- ${entries.join("\n")}
203
- }`;
204
- }
205
- var HEADER = `// ============================================================
206
- // Types TypeScript auto-g\xE9n\xE9r\xE9s par Aurabase (@aurabase/gen)
207
- // NE PAS MODIFIER \u2014 r\xE9g\xE9n\xE9rer avec \`npx @aurabase/gen\`
208
- // ============================================================
209
- `;
210
- function generateDatabaseTypes(tables, options = {}) {
211
- const schemaName = options.schemaName ?? "public";
212
- const typeName = options.typeName ?? "Database";
213
- const enums = options.enums ?? [];
214
- const views = options.views ?? [];
215
- const relationNames = new Set([...tables, ...views].map((r) => r.name));
216
- const ctx = { typeName, schemaName, enumNames: new Set(enums.map((e) => e.name)), relationNames };
217
- const functionsBody = genFunctionsBody(options.functions ?? [], ctx);
218
- const enumsBody = genEnumsBody(enums);
219
- const viewsBody = genViewsBody(views, ctx);
220
- const tablesBody = tables.length === 0 ? "Record<string, never>" : `{
221
- ${tables.map(
222
- (t) => ` ${t.name}: {
223
- Row: {
224
- ${genRow(t.columns, ctx)}
225
- }
226
- Insert: {
227
- ${genInsert(t.columns, ctx)}
228
- }
229
- Update: {
230
- ${genUpdate(t.columns, ctx)}
231
- }
232
- Relationships: ${genRelationships(t)}
233
- }`
234
- ).join("\n")}
235
- }`;
236
- return `${HEADER}
237
- export type Json =
238
- | string
239
- | number
240
- | boolean
241
- | null
242
- | { [key: string]: Json | undefined }
243
- | Json[]
244
-
245
- export interface ${typeName} {
246
- ${schemaName}: {
247
- Tables: ${tablesBody}
248
- Views: ${viewsBody}
249
- Functions: ${functionsBody}
250
- Enums: ${enumsBody}
251
- CompositeTypes: Record<string, never>
252
- }
253
- }
254
- `;
255
- }
256
-
257
- exports.generateDatabaseTypes = generateDatabaseTypes;
@@ -1,12 +0,0 @@
1
- import { SchemaFunction, SchemaEnum, SchemaTable } from '@aurabase/core';
2
-
3
- interface GenerateOptions {
4
- schemaName?: string;
5
- typeName?: string;
6
- functions?: SchemaFunction[];
7
- enums?: SchemaEnum[];
8
- views?: SchemaTable[];
9
- }
10
- declare function generateDatabaseTypes(tables: SchemaTable[], options?: GenerateOptions): string;
11
-
12
- export { type GenerateOptions, generateDatabaseTypes };
@@ -1,12 +0,0 @@
1
- import { SchemaFunction, SchemaEnum, SchemaTable } from '@aurabase/core';
2
-
3
- interface GenerateOptions {
4
- schemaName?: string;
5
- typeName?: string;
6
- functions?: SchemaFunction[];
7
- enums?: SchemaEnum[];
8
- views?: SchemaTable[];
9
- }
10
- declare function generateDatabaseTypes(tables: SchemaTable[], options?: GenerateOptions): string;
11
-
12
- export { type GenerateOptions, generateDatabaseTypes };