@revealui/db 0.2.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/LICENSE +22 -0
- package/README.md +137 -0
- package/dist/audit-store.d.ts +56 -0
- package/dist/audit-store.d.ts.map +1 -0
- package/dist/audit-store.js +120 -0
- package/dist/audit-store.js.map +1 -0
- package/dist/client/index.d.ts +214 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +396 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/types.d.ts +109 -0
- package/dist/client/types.d.ts.map +1 -0
- package/dist/client/types.js +10 -0
- package/dist/client/types.js.map +1 -0
- package/dist/crypto.d.ts +27 -0
- package/dist/crypto.d.ts.map +1 -0
- package/dist/crypto.js +68 -0
- package/dist/crypto.js.map +1 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/log-transport.d.ts +20 -0
- package/dist/log-transport.d.ts.map +1 -0
- package/dist/log-transport.js +49 -0
- package/dist/log-transport.js.map +1 -0
- package/dist/pool.d.ts +36 -0
- package/dist/pool.d.ts.map +1 -0
- package/dist/pool.js +218 -0
- package/dist/pool.js.map +1 -0
- package/dist/queries/boards.d.ts +138 -0
- package/dist/queries/boards.d.ts.map +1 -0
- package/dist/queries/boards.js +87 -0
- package/dist/queries/boards.js.map +1 -0
- package/dist/queries/code-provenance.d.ts +250 -0
- package/dist/queries/code-provenance.d.ts.map +1 -0
- package/dist/queries/code-provenance.js +130 -0
- package/dist/queries/code-provenance.js.map +1 -0
- package/dist/queries/optimized-queries.d.ts +89 -0
- package/dist/queries/optimized-queries.d.ts.map +1 -0
- package/dist/queries/optimized-queries.js +371 -0
- package/dist/queries/optimized-queries.js.map +1 -0
- package/dist/queries/ticket-comments.d.ts +37 -0
- package/dist/queries/ticket-comments.d.ts.map +1 -0
- package/dist/queries/ticket-comments.js +52 -0
- package/dist/queries/ticket-comments.js.map +1 -0
- package/dist/queries/ticket-labels.d.ts +69 -0
- package/dist/queries/ticket-labels.d.ts.map +1 -0
- package/dist/queries/ticket-labels.js +51 -0
- package/dist/queries/ticket-labels.js.map +1 -0
- package/dist/queries/tickets.d.ts +301 -0
- package/dist/queries/tickets.d.ts.map +1 -0
- package/dist/queries/tickets.js +89 -0
- package/dist/queries/tickets.js.map +1 -0
- package/dist/queries/todos.d.ts +37 -0
- package/dist/queries/todos.d.ts.map +1 -0
- package/dist/queries/todos.js +37 -0
- package/dist/queries/todos.js.map +1 -0
- package/dist/schema/agents.d.ts +1413 -0
- package/dist/schema/agents.d.ts.map +1 -0
- package/dist/schema/agents.js +207 -0
- package/dist/schema/agents.js.map +1 -0
- package/dist/schema/api-keys.d.ts +298 -0
- package/dist/schema/api-keys.d.ts.map +1 -0
- package/dist/schema/api-keys.js +53 -0
- package/dist/schema/api-keys.js.map +1 -0
- package/dist/schema/app-logs.d.ts +168 -0
- package/dist/schema/app-logs.d.ts.map +1 -0
- package/dist/schema/app-logs.js +25 -0
- package/dist/schema/app-logs.js.map +1 -0
- package/dist/schema/audit-log.d.ts +174 -0
- package/dist/schema/audit-log.d.ts.map +1 -0
- package/dist/schema/audit-log.js +37 -0
- package/dist/schema/audit-log.js.map +1 -0
- package/dist/schema/cms.d.ts +1015 -0
- package/dist/schema/cms.d.ts.map +1 -0
- package/dist/schema/cms.js +137 -0
- package/dist/schema/cms.js.map +1 -0
- package/dist/schema/code-provenance.d.ts +488 -0
- package/dist/schema/code-provenance.d.ts.map +1 -0
- package/dist/schema/code-provenance.js +72 -0
- package/dist/schema/code-provenance.js.map +1 -0
- package/dist/schema/collab-edits.d.ts +165 -0
- package/dist/schema/collab-edits.d.ts.map +1 -0
- package/dist/schema/collab-edits.js +21 -0
- package/dist/schema/collab-edits.js.map +1 -0
- package/dist/schema/crdt-operations.d.ts +153 -0
- package/dist/schema/crdt-operations.d.ts.map +1 -0
- package/dist/schema/crdt-operations.js +30 -0
- package/dist/schema/crdt-operations.js.map +1 -0
- package/dist/schema/error-events.d.ts +223 -0
- package/dist/schema/error-events.d.ts.map +1 -0
- package/dist/schema/error-events.js +44 -0
- package/dist/schema/error-events.js.map +1 -0
- package/dist/schema/index.d.ts +130 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +310 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/schema/licenses.d.ts +189 -0
- package/dist/schema/licenses.d.ts.map +1 -0
- package/dist/schema/licenses.js +39 -0
- package/dist/schema/licenses.js.map +1 -0
- package/dist/schema/node-ids.d.ts +122 -0
- package/dist/schema/node-ids.d.ts.map +1 -0
- package/dist/schema/node-ids.js +25 -0
- package/dist/schema/node-ids.js.map +1 -0
- package/dist/schema/pages.d.ts +488 -0
- package/dist/schema/pages.d.ts.map +1 -0
- package/dist/schema/pages.js +70 -0
- package/dist/schema/pages.js.map +1 -0
- package/dist/schema/password-reset-tokens.d.ts +137 -0
- package/dist/schema/password-reset-tokens.d.ts.map +1 -0
- package/dist/schema/password-reset-tokens.js +26 -0
- package/dist/schema/password-reset-tokens.js.map +1 -0
- package/dist/schema/query.d.ts +11 -0
- package/dist/schema/query.d.ts.map +1 -0
- package/dist/schema/query.js +11 -0
- package/dist/schema/query.js.map +1 -0
- package/dist/schema/rate-limits.d.ts +212 -0
- package/dist/schema/rate-limits.d.ts.map +1 -0
- package/dist/schema/rate-limits.js +38 -0
- package/dist/schema/rate-limits.js.map +1 -0
- package/dist/schema/rest.d.ts +31 -0
- package/dist/schema/rest.d.ts.map +1 -0
- package/dist/schema/rest.js +37 -0
- package/dist/schema/rest.js.map +1 -0
- package/dist/schema/sites.d.ts +365 -0
- package/dist/schema/sites.d.ts.map +1 -0
- package/dist/schema/sites.js +62 -0
- package/dist/schema/sites.js.map +1 -0
- package/dist/schema/tickets.d.ts +1118 -0
- package/dist/schema/tickets.d.ts.map +1 -0
- package/dist/schema/tickets.js +150 -0
- package/dist/schema/tickets.js.map +1 -0
- package/dist/schema/todos.d.ts +98 -0
- package/dist/schema/todos.d.ts.map +1 -0
- package/dist/schema/todos.js +12 -0
- package/dist/schema/todos.js.map +1 -0
- package/dist/schema/users.d.ts +503 -0
- package/dist/schema/users.d.ts.map +1 -0
- package/dist/schema/users.js +75 -0
- package/dist/schema/users.js.map +1 -0
- package/dist/schema/vector.d.ts +9 -0
- package/dist/schema/vector.d.ts.map +1 -0
- package/dist/schema/vector.js +9 -0
- package/dist/schema/vector.js.map +1 -0
- package/dist/schema/waitlist.d.ts +151 -0
- package/dist/schema/waitlist.d.ts.map +1 -0
- package/dist/schema/waitlist.js +17 -0
- package/dist/schema/waitlist.js.map +1 -0
- package/dist/schema/yjs-documents.d.ts +116 -0
- package/dist/schema/yjs-documents.d.ts.map +1 -0
- package/dist/schema/yjs-documents.js +15 -0
- package/dist/schema/yjs-documents.js.map +1 -0
- package/dist/types/database.d.ts +740 -0
- package/dist/types/database.d.ts.map +1 -0
- package/dist/types/database.js +151 -0
- package/dist/types/database.js.map +1 -0
- package/dist/types/discover.d.ts +83 -0
- package/dist/types/discover.d.ts.map +1 -0
- package/dist/types/discover.js +271 -0
- package/dist/types/discover.js.map +1 -0
- package/dist/types/extract-relationships.d.ts +115 -0
- package/dist/types/extract-relationships.d.ts.map +1 -0
- package/dist/types/extract-relationships.js +455 -0
- package/dist/types/extract-relationships.js.map +1 -0
- package/dist/types/generate-contracts.d.ts +19 -0
- package/dist/types/generate-contracts.d.ts.map +1 -0
- package/dist/types/generate-contracts.js +128 -0
- package/dist/types/generate-contracts.js.map +1 -0
- package/dist/types/generate-zod-schemas.d.ts +20 -0
- package/dist/types/generate-zod-schemas.d.ts.map +1 -0
- package/dist/types/generate-zod-schemas.js +128 -0
- package/dist/types/generate-zod-schemas.js.map +1 -0
- package/dist/types/generate.d.ts +17 -0
- package/dist/types/generate.d.ts.map +1 -0
- package/dist/types/generate.js +298 -0
- package/dist/types/generate.js.map +1 -0
- package/dist/types/index.d.ts +19 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +19 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/introspect.d.ts +75 -0
- package/dist/types/introspect.d.ts.map +1 -0
- package/dist/types/introspect.js +187 -0
- package/dist/types/introspect.js.map +1 -0
- package/dist/types/stripe-schema.d.ts +893 -0
- package/dist/types/stripe-schema.d.ts.map +1 -0
- package/dist/types/stripe-schema.js +112 -0
- package/dist/types/stripe-schema.js.map +1 -0
- package/package.json +154 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
#!/usr/bin/env tsx
|
|
2
|
+
/**
|
|
3
|
+
* Contract Wrapper Generator
|
|
4
|
+
*
|
|
5
|
+
* Generates Contract wrappers for all auto-generated Zod schemas.
|
|
6
|
+
* Contracts provide a unified interface combining TypeScript types,
|
|
7
|
+
* Zod schemas, and runtime validation.
|
|
8
|
+
*
|
|
9
|
+
* Generated contracts include:
|
|
10
|
+
* - RowContract: For database row types
|
|
11
|
+
* - InsertContract: For database insert types
|
|
12
|
+
*
|
|
13
|
+
* Output: packages/contracts/src/generated/contracts.ts
|
|
14
|
+
*/
|
|
15
|
+
// Control verbose logging
|
|
16
|
+
const VERBOSE_LOGGING = process.env.DB_VERBOSE !== 'false' &&
|
|
17
|
+
(process.env.NODE_ENV !== 'production' || process.env.CI !== 'true');
|
|
18
|
+
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
19
|
+
import { dirname, join } from 'node:path';
|
|
20
|
+
import { fileURLToPath } from 'node:url';
|
|
21
|
+
import { logger } from '@revealui/utils/logger';
|
|
22
|
+
import { discoverTables, validateTables } from './discover.js';
|
|
23
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
24
|
+
const __dirname = dirname(__filename);
|
|
25
|
+
/**
|
|
26
|
+
* Convert camelCase to PascalCase for type names
|
|
27
|
+
*/
|
|
28
|
+
function toPascalCase(str) {
|
|
29
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Generate Contract wrappers file from discovered tables
|
|
33
|
+
*/
|
|
34
|
+
export function generateContracts() {
|
|
35
|
+
// Discover all tables
|
|
36
|
+
const discoveryResult = discoverTables();
|
|
37
|
+
const { tables, errors: discoveryErrors } = discoveryResult;
|
|
38
|
+
// Log discovery errors (warnings)
|
|
39
|
+
if (discoveryErrors.length > 0) {
|
|
40
|
+
for (const error of discoveryErrors) {
|
|
41
|
+
const location = error.position
|
|
42
|
+
? `${error.file}:${error.position.line}:${error.position.column}`
|
|
43
|
+
: error.file;
|
|
44
|
+
logger.warn(`⚠️ ${location}: ${error.message}${error.context ? ` (${error.context})` : ''}`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
// Validate tables
|
|
48
|
+
const validation = validateTables(tables);
|
|
49
|
+
if (!validation.valid) {
|
|
50
|
+
throw new Error(`Table validation failed:\n${validation.errors.map((e) => ` - ${e}`).join('\n')}`);
|
|
51
|
+
}
|
|
52
|
+
// Generate file header
|
|
53
|
+
const header = `/**
|
|
54
|
+
* Auto-generated Contract wrappers
|
|
55
|
+
*
|
|
56
|
+
* DO NOT EDIT - Regenerate with: pnpm generate:all
|
|
57
|
+
* Generated: ${new Date().toISOString()}
|
|
58
|
+
*
|
|
59
|
+
* This file provides Contract wrappers for all database tables.
|
|
60
|
+
* Contracts combine TypeScript types, Zod schemas, and runtime validation
|
|
61
|
+
* into a single unified interface.
|
|
62
|
+
*
|
|
63
|
+
* These base contracts can be extended in entity contracts to add
|
|
64
|
+
* business logic, computed fields, and custom validation rules.
|
|
65
|
+
*/
|
|
66
|
+
|
|
67
|
+
import { createContract } from '../foundation/contract.js'
|
|
68
|
+
import * as Schemas from '@revealui/contracts/generated/zod-schemas'
|
|
69
|
+
|
|
70
|
+
`;
|
|
71
|
+
// Generate contracts for each table
|
|
72
|
+
const contracts = tables
|
|
73
|
+
.map((table) => {
|
|
74
|
+
const pascalName = toPascalCase(table.variableName);
|
|
75
|
+
return `// =============================================================================
|
|
76
|
+
// ${pascalName} Contracts
|
|
77
|
+
// =============================================================================
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Contract for ${table.variableName} row (Select)
|
|
81
|
+
* Database table: ${table.tableName}
|
|
82
|
+
*/
|
|
83
|
+
export const ${pascalName}RowContract = createContract({
|
|
84
|
+
name: '${pascalName}Row',
|
|
85
|
+
version: '1',
|
|
86
|
+
description: 'Database row contract for ${table.tableName} table',
|
|
87
|
+
schema: Schemas.${pascalName}SelectSchema,
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Contract for ${table.variableName} insert
|
|
92
|
+
* Database table: ${table.tableName}
|
|
93
|
+
*/
|
|
94
|
+
export const ${pascalName}InsertContract = createContract({
|
|
95
|
+
name: '${pascalName}Insert',
|
|
96
|
+
version: '1',
|
|
97
|
+
description: 'Database insert contract for ${table.tableName} table',
|
|
98
|
+
schema: Schemas.${pascalName}InsertSchema,
|
|
99
|
+
})
|
|
100
|
+
`;
|
|
101
|
+
})
|
|
102
|
+
.join('\n');
|
|
103
|
+
// Combine header and contracts
|
|
104
|
+
const content = header + contracts;
|
|
105
|
+
// Write to contracts package
|
|
106
|
+
const outputPath = join(__dirname, '../../../contracts/src/generated/contracts.ts');
|
|
107
|
+
mkdirSync(dirname(outputPath), { recursive: true });
|
|
108
|
+
writeFileSync(outputPath, content, 'utf-8');
|
|
109
|
+
if (VERBOSE_LOGGING) {
|
|
110
|
+
logger.info(`✅ Generated Contract wrappers: ${outputPath}`);
|
|
111
|
+
logger.info(` - ${tables.length} tables processed`);
|
|
112
|
+
logger.info(` - ${tables.length * 2} contracts generated (Row + Insert)`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
// Run if executed directly
|
|
116
|
+
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
117
|
+
try {
|
|
118
|
+
generateContracts();
|
|
119
|
+
if (VERBOSE_LOGGING) {
|
|
120
|
+
logger.info('✨ Contract generation complete!');
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
logger.error('❌ Error generating contracts:', error instanceof Error ? error : undefined);
|
|
125
|
+
process.exit(1);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=generate-contracts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-contracts.js","sourceRoot":"","sources":["../../src/types/generate-contracts.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;GAYG;AAEH,0BAA0B;AAC1B,MAAM,eAAe,GACnB,OAAO,CAAC,GAAG,CAAC,UAAU,KAAK,OAAO;IAClC,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,IAAI,OAAO,CAAC,GAAG,CAAC,EAAE,KAAK,MAAM,CAAC,CAAA;AAEtE,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAClD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAC/C,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAE9D,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AACjD,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;AAErC;;GAEG;AACH,SAAS,YAAY,CAAC,GAAW;IAC/B,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;AACnD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB;IAC/B,sBAAsB;IACtB,MAAM,eAAe,GAAG,cAAc,EAAE,CAAA;IACxC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,GAAG,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,CAAC,CAAC,CAAC,CAAA;IACjB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/usr/bin/env tsx
|
|
2
|
+
/**
|
|
3
|
+
* Zod Schema Generator
|
|
4
|
+
*
|
|
5
|
+
* Generates Zod schemas from Drizzle table definitions using drizzle-zod.
|
|
6
|
+
* This ensures Drizzle schemas are the single source of truth.
|
|
7
|
+
*
|
|
8
|
+
* Generated schemas include:
|
|
9
|
+
* - SelectSchema: For reading rows from the database
|
|
10
|
+
* - InsertSchema: For inserting new rows
|
|
11
|
+
* - Row type: TypeScript type for Select
|
|
12
|
+
* - Insert type: TypeScript type for Insert
|
|
13
|
+
*
|
|
14
|
+
* Output: packages/contracts/src/generated/zod-schemas.ts
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Generate Zod schemas file from Drizzle tables
|
|
18
|
+
*/
|
|
19
|
+
export declare function generateZodSchemas(): void;
|
|
20
|
+
//# sourceMappingURL=generate-zod-schemas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-zod-schemas.d.ts","sourceRoot":"","sources":["../../src/types/generate-zod-schemas.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;GAaG;AAuBH;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,IAAI,CAwFzC"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
#!/usr/bin/env tsx
|
|
2
|
+
/**
|
|
3
|
+
* Zod Schema Generator
|
|
4
|
+
*
|
|
5
|
+
* Generates Zod schemas from Drizzle table definitions using drizzle-zod.
|
|
6
|
+
* This ensures Drizzle schemas are the single source of truth.
|
|
7
|
+
*
|
|
8
|
+
* Generated schemas include:
|
|
9
|
+
* - SelectSchema: For reading rows from the database
|
|
10
|
+
* - InsertSchema: For inserting new rows
|
|
11
|
+
* - Row type: TypeScript type for Select
|
|
12
|
+
* - Insert type: TypeScript type for Insert
|
|
13
|
+
*
|
|
14
|
+
* Output: packages/contracts/src/generated/zod-schemas.ts
|
|
15
|
+
*/
|
|
16
|
+
// Control verbose logging
|
|
17
|
+
const VERBOSE_LOGGING = process.env.DB_VERBOSE !== 'false' &&
|
|
18
|
+
(process.env.NODE_ENV !== 'production' || process.env.CI !== 'true');
|
|
19
|
+
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
20
|
+
import { dirname, join } from 'node:path';
|
|
21
|
+
import { fileURLToPath } from 'node:url';
|
|
22
|
+
import { logger } from '@revealui/utils/logger';
|
|
23
|
+
import { discoverTables, validateTables } from './discover.js';
|
|
24
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
25
|
+
const __dirname = dirname(__filename);
|
|
26
|
+
/**
|
|
27
|
+
* Convert camelCase to PascalCase for type names
|
|
28
|
+
*/
|
|
29
|
+
function toPascalCase(str) {
|
|
30
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Generate Zod schemas file from Drizzle tables
|
|
34
|
+
*/
|
|
35
|
+
export function generateZodSchemas() {
|
|
36
|
+
// Discover all tables
|
|
37
|
+
const discoveryResult = discoverTables();
|
|
38
|
+
const { tables, errors: discoveryErrors } = discoveryResult;
|
|
39
|
+
// Log discovery errors (warnings)
|
|
40
|
+
if (discoveryErrors.length > 0) {
|
|
41
|
+
for (const error of discoveryErrors) {
|
|
42
|
+
const location = error.position
|
|
43
|
+
? `${error.file}:${error.position.line}:${error.position.column}`
|
|
44
|
+
: error.file;
|
|
45
|
+
logger.warn(`⚠️ ${location}: ${error.message}${error.context ? ` (${error.context})` : ''}`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// Validate tables
|
|
49
|
+
const validation = validateTables(tables);
|
|
50
|
+
if (!validation.valid) {
|
|
51
|
+
throw new Error(`Table validation failed:\n${validation.errors.map((e) => ` - ${e}`).join('\n')}`);
|
|
52
|
+
}
|
|
53
|
+
// Generate file header
|
|
54
|
+
const header = `/**
|
|
55
|
+
* Auto-generated Zod schemas from Drizzle
|
|
56
|
+
*
|
|
57
|
+
* DO NOT EDIT - Regenerate with: pnpm generate:all
|
|
58
|
+
* Generated: ${new Date().toISOString()}
|
|
59
|
+
*
|
|
60
|
+
* This file provides Zod schemas for all database tables, generated
|
|
61
|
+
* directly from Drizzle table definitions using drizzle-zod.
|
|
62
|
+
* These schemas are used for runtime validation and form the base
|
|
63
|
+
* for entity contracts in @revealui/contracts/entities.
|
|
64
|
+
*/
|
|
65
|
+
|
|
66
|
+
import { createInsertSchema, createSelectSchema } from 'drizzle-zod'
|
|
67
|
+
import type { z } from 'zod'
|
|
68
|
+
import * as tables from '@revealui/db/schema'
|
|
69
|
+
|
|
70
|
+
`;
|
|
71
|
+
// Generate schemas for each table
|
|
72
|
+
const schemas = tables
|
|
73
|
+
.map((table) => {
|
|
74
|
+
const pascalName = toPascalCase(table.variableName);
|
|
75
|
+
return `// =============================================================================
|
|
76
|
+
// ${pascalName} Schemas
|
|
77
|
+
// =============================================================================
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Zod schema for selecting ${table.variableName} rows from database
|
|
81
|
+
* Generated from Drizzle table definition: tables.${table.variableName}
|
|
82
|
+
*/
|
|
83
|
+
export const ${pascalName}SelectSchema = createSelectSchema(tables.${table.variableName})
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Zod schema for inserting ${table.variableName} rows to database
|
|
87
|
+
* Generated from Drizzle table definition: tables.${table.variableName}
|
|
88
|
+
*/
|
|
89
|
+
export const ${pascalName}InsertSchema = createInsertSchema(tables.${table.variableName})
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* TypeScript type for ${table.variableName} row (Select)
|
|
93
|
+
*/
|
|
94
|
+
export type ${pascalName}Row = z.infer<typeof ${pascalName}SelectSchema>
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* TypeScript type for ${table.variableName} insert
|
|
98
|
+
*/
|
|
99
|
+
export type ${pascalName}Insert = z.infer<typeof ${pascalName}InsertSchema>
|
|
100
|
+
`;
|
|
101
|
+
})
|
|
102
|
+
.join('\n');
|
|
103
|
+
// Combine header and schemas
|
|
104
|
+
const content = header + schemas;
|
|
105
|
+
// Write to contracts package (where it will be consumed)
|
|
106
|
+
const outputPath = join(__dirname, '../../../contracts/src/generated/zod-schemas.ts');
|
|
107
|
+
mkdirSync(dirname(outputPath), { recursive: true });
|
|
108
|
+
writeFileSync(outputPath, content, 'utf-8');
|
|
109
|
+
if (VERBOSE_LOGGING) {
|
|
110
|
+
logger.info(`✅ Generated Zod schemas: ${outputPath}`);
|
|
111
|
+
logger.info(` - ${tables.length} tables processed`);
|
|
112
|
+
logger.info(` - ${tables.length * 2} schemas generated (Select + Insert)`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
// Run if executed directly
|
|
116
|
+
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
117
|
+
try {
|
|
118
|
+
generateZodSchemas();
|
|
119
|
+
if (VERBOSE_LOGGING) {
|
|
120
|
+
logger.info('✨ Zod schema generation complete!');
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
logger.error('❌ Error generating Zod schemas:', error instanceof Error ? error : undefined);
|
|
125
|
+
process.exit(1);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=generate-zod-schemas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-zod-schemas.js","sourceRoot":"","sources":["../../src/types/generate-zod-schemas.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;GAaG;AAEH,0BAA0B;AAC1B,MAAM,eAAe,GACnB,OAAO,CAAC,GAAG,CAAC,UAAU,KAAK,OAAO;IAClC,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,IAAI,OAAO,CAAC,GAAG,CAAC,EAAE,KAAK,MAAM,CAAC,CAAA;AAEtE,OAAO,EAAE,SAAS,EAAE,aAAa,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EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;IAE3C,IAAI,eAAe,EAAE,CAAC;QACpB,MAAM,CAAC,IAAI,CAAC,4BAA4B,UAAU,EAAE,CAAC,CAAA;QACrD,MAAM,CAAC,IAAI,CAAC,QAAQ,MAAM,CAAC,MAAM,mBAAmB,CAAC,CAAA;QACrD,MAAM,CAAC,IAAI,CAAC,QAAQ,MAAM,CAAC,MAAM,GAAG,CAAC,sCAAsC,CAAC,CAAA;IAC9E,CAAC;AACH,CAAC;AAED,2BAA2B;AAC3B,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,UAAU,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;IACpD,IAAI,CAAC;QACH,kBAAkB,EAAE,CAAA;QACpB,IAAI,eAAe,EAAE,CAAC;YACpB,MAAM,CAAC,IAAI,CAAC,mCAAmC,CAAC,CAAA;QAClD,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,KAAK,CAAC,iCAAiC,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;QAC3F,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACjB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/usr/bin/env tsx
|
|
2
|
+
/**
|
|
3
|
+
* Type Generator for NeonDB Database Types
|
|
4
|
+
*
|
|
5
|
+
* Generates a centralized Database type from Drizzle schemas that matches
|
|
6
|
+
* the Supabase Database type structure for feature parity.
|
|
7
|
+
*
|
|
8
|
+
* This script:
|
|
9
|
+
* 1. Imports all table schemas from ../core
|
|
10
|
+
* 2. Extracts table names and types
|
|
11
|
+
* 3. Generates Row, Insert, Update types for each table
|
|
12
|
+
* 4. Extracts relationships from relations
|
|
13
|
+
* 5. Generates Enums (if any)
|
|
14
|
+
* 6. Writes Database type to database.ts
|
|
15
|
+
*/
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=generate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../src/types/generate.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;GAaG"}
|
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
#!/usr/bin/env tsx
|
|
2
|
+
/**
|
|
3
|
+
* Type Generator for NeonDB Database Types
|
|
4
|
+
*
|
|
5
|
+
* Generates a centralized Database type from Drizzle schemas that matches
|
|
6
|
+
* the Supabase Database type structure for feature parity.
|
|
7
|
+
*
|
|
8
|
+
* This script:
|
|
9
|
+
* 1. Imports all table schemas from ../core
|
|
10
|
+
* 2. Extracts table names and types
|
|
11
|
+
* 3. Generates Row, Insert, Update types for each table
|
|
12
|
+
* 4. Extracts relationships from relations
|
|
13
|
+
* 5. Generates Enums (if any)
|
|
14
|
+
* 6. Writes Database type to database.ts
|
|
15
|
+
*/
|
|
16
|
+
// Control verbose logging for type generation
|
|
17
|
+
const VERBOSE_LOGGING = process.env.DB_VERBOSE !== 'false' &&
|
|
18
|
+
(process.env.NODE_ENV !== 'production' || process.env.CI !== 'true');
|
|
19
|
+
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
20
|
+
import { dirname, join } from 'node:path';
|
|
21
|
+
import { fileURLToPath } from 'node:url';
|
|
22
|
+
import { logger } from '@revealui/utils/logger';
|
|
23
|
+
import { discoverTables, validateTables } from './discover.js';
|
|
24
|
+
import { extractRelationships } from './extract-relationships.js';
|
|
25
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
26
|
+
const __dirname = dirname(__filename);
|
|
27
|
+
const rootDir = join(__dirname, '../../..');
|
|
28
|
+
const outputPath = join(__dirname, 'database.ts');
|
|
29
|
+
// Generate Database type file
|
|
30
|
+
const generateDatabaseType = () => {
|
|
31
|
+
// Discover all tables automatically
|
|
32
|
+
const discoveryResult = discoverTables();
|
|
33
|
+
const { tables, errors: discoveryErrors } = discoveryResult;
|
|
34
|
+
// Log discovery errors (warnings)
|
|
35
|
+
if (discoveryErrors.length > 0) {
|
|
36
|
+
for (const error of discoveryErrors) {
|
|
37
|
+
const location = error.position
|
|
38
|
+
? `${error.file}:${error.position.line}:${error.position.column}`
|
|
39
|
+
: error.file;
|
|
40
|
+
logger.warn(`⚠️ ${location}: ${error.message}${error.context ? ` (${error.context})` : ''}`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const validation = validateTables(tables);
|
|
44
|
+
if (!validation.valid) {
|
|
45
|
+
throw new Error(`Table validation failed:\n${validation.errors.map((e) => ` - ${e}`).join('\n')}`);
|
|
46
|
+
}
|
|
47
|
+
// Helper to convert camelCase to PascalCase for type names
|
|
48
|
+
const toPascalCase = (str) => {
|
|
49
|
+
return str.charAt(0).toUpperCase() + str.slice(1).replace(/([A-Z])/g, '$1');
|
|
50
|
+
};
|
|
51
|
+
// Generate imports
|
|
52
|
+
const imports = tables.map((t) => t.variableName).join(',\n ');
|
|
53
|
+
// Generate type definitions
|
|
54
|
+
const typeDefinitions = tables
|
|
55
|
+
.map((table) => {
|
|
56
|
+
const typeName = toPascalCase(table.variableName);
|
|
57
|
+
const comment = `// ${typeName.replace(/([A-Z])/g, ' $1').trim()}`;
|
|
58
|
+
return `${comment}
|
|
59
|
+
export type ${typeName}Row = typeof ${table.variableName}.$inferSelect
|
|
60
|
+
export type ${typeName}Insert = typeof ${table.variableName}.$inferInsert
|
|
61
|
+
export type ${typeName}Update = Partial<${typeName}Insert>`;
|
|
62
|
+
})
|
|
63
|
+
.join('\n\n');
|
|
64
|
+
const header = `/**
|
|
65
|
+
* Generated Database Type for NeonDB
|
|
66
|
+
*
|
|
67
|
+
* This file is auto-generated by packages/db/src/types/generate.ts
|
|
68
|
+
* DO NOT MODIFY MANUALLY - regenerate using: pnpm generate:types
|
|
69
|
+
*
|
|
70
|
+
* Generated: ${new Date().toISOString()}
|
|
71
|
+
*
|
|
72
|
+
* This type matches the Supabase Database type structure for feature parity.
|
|
73
|
+
* Tables are automatically discovered from packages/db/src/schema/*.ts
|
|
74
|
+
*/
|
|
75
|
+
|
|
76
|
+
import type {
|
|
77
|
+
${imports},
|
|
78
|
+
} from '../schema/index.js'
|
|
79
|
+
|
|
80
|
+
// =============================================================================
|
|
81
|
+
// Table Type Inferences
|
|
82
|
+
// =============================================================================
|
|
83
|
+
|
|
84
|
+
${typeDefinitions}
|
|
85
|
+
|
|
86
|
+
// =============================================================================
|
|
87
|
+
// Relationships
|
|
88
|
+
// =============================================================================
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Relationship type matching Supabase structure
|
|
92
|
+
*/
|
|
93
|
+
export type Relationship = {
|
|
94
|
+
foreignKeyName: string
|
|
95
|
+
columns: string[]
|
|
96
|
+
isOneToOne: boolean
|
|
97
|
+
referencedRelation: string
|
|
98
|
+
referencedColumns: string[]
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Relationship definitions matching Supabase structure (array format)
|
|
103
|
+
* These are derived from Drizzle relations in packages/db/src/schema/index.ts
|
|
104
|
+
*
|
|
105
|
+
* Note: isOneToOne is determined by Drizzle relation type:
|
|
106
|
+
* - one() = isOneToOne: true
|
|
107
|
+
* - many() = isOneToOne: false
|
|
108
|
+
*/
|
|
109
|
+
export type DatabaseRelationships = {
|
|
110
|
+
${tables.map((t) => ` ${t.variableName}: Relationship[]`).join('\n')}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Relationships will be inserted here
|
|
114
|
+
|
|
115
|
+
// =============================================================================
|
|
116
|
+
// Enums
|
|
117
|
+
// =============================================================================
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Database enums (currently none, but structure ready for future enums)
|
|
121
|
+
* When enums are added to Drizzle schemas, they will be included here
|
|
122
|
+
*/
|
|
123
|
+
export interface DatabaseEnums {
|
|
124
|
+
// Enums will be added here as they are defined in the schema
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// =============================================================================
|
|
128
|
+
// Main Database Type (Supabase-compatible structure)
|
|
129
|
+
// =============================================================================
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Centralized Database type matching Supabase structure
|
|
133
|
+
*
|
|
134
|
+
* This provides feature parity with Supabase's Database type:
|
|
135
|
+
* - Full type safety for all tables
|
|
136
|
+
* - Row, Insert, Update types for each table
|
|
137
|
+
* - Relationships information
|
|
138
|
+
* - Enums support
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* \`\`\`typescript
|
|
142
|
+
* import type { Database } from '@revealui/db/types'
|
|
143
|
+
*
|
|
144
|
+
* type User = Database['public']['Tables']['users']['Row']
|
|
145
|
+
* type NewUser = Database['public']['Tables']['users']['Insert']
|
|
146
|
+
* \`\`\`
|
|
147
|
+
*/
|
|
148
|
+
export type Database = {
|
|
149
|
+
public: {
|
|
150
|
+
Tables: {
|
|
151
|
+
${tables
|
|
152
|
+
.map((table) => {
|
|
153
|
+
const typeName = toPascalCase(table.variableName);
|
|
154
|
+
const relationshipsVar = `${table.variableName}Relationships`;
|
|
155
|
+
// Relationships are automatically extracted from Drizzle relations
|
|
156
|
+
return ` ${table.tableName}: {
|
|
157
|
+
Row: ${typeName}Row
|
|
158
|
+
Insert: ${typeName}Insert
|
|
159
|
+
Update: ${typeName}Update
|
|
160
|
+
Relationships: typeof ${relationshipsVar}
|
|
161
|
+
}`;
|
|
162
|
+
})
|
|
163
|
+
.join('\n')}
|
|
164
|
+
}
|
|
165
|
+
Enums: DatabaseEnums
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// =============================================================================
|
|
170
|
+
// Type Utilities (for convenience)
|
|
171
|
+
// =============================================================================
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Extract Row type for a table
|
|
175
|
+
*/
|
|
176
|
+
export type TableRow<T extends keyof Database['public']['Tables']> =
|
|
177
|
+
Database['public']['Tables'][T]['Row']
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Extract Insert type for a table
|
|
181
|
+
*/
|
|
182
|
+
export type TableInsert<T extends keyof Database['public']['Tables']> =
|
|
183
|
+
Database['public']['Tables'][T]['Insert']
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Extract Update type for a table
|
|
187
|
+
*/
|
|
188
|
+
export type TableUpdate<T extends keyof Database['public']['Tables']> =
|
|
189
|
+
Database['public']['Tables'][T]['Update']
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Extract Relationships for a table
|
|
193
|
+
*/
|
|
194
|
+
export type TableRelationships<T extends keyof Database['public']['Tables']> =
|
|
195
|
+
Database['public']['Tables'][T]['Relationships']
|
|
196
|
+
`;
|
|
197
|
+
// Extract relationships automatically from Drizzle relations
|
|
198
|
+
const extractionResult = extractRelationships(tables);
|
|
199
|
+
const extractedRelationships = extractionResult.relationships;
|
|
200
|
+
const extractionErrors = extractionResult.errors;
|
|
201
|
+
// Log extraction errors (warnings for missing relations, errors for critical issues)
|
|
202
|
+
if (extractionErrors.length > 0) {
|
|
203
|
+
for (const error of extractionErrors) {
|
|
204
|
+
const location = error.position
|
|
205
|
+
? `${error.file}:${error.position.line}:${error.position.column}`
|
|
206
|
+
: error.file;
|
|
207
|
+
logger.warn(`⚠️ ${location}: ${error.message}${error.context ? ` (${error.context})` : ''}`);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
const relationshipsMap = new Map();
|
|
211
|
+
// Build map of relationships by table variable name
|
|
212
|
+
for (const tableRel of extractedRelationships) {
|
|
213
|
+
relationshipsMap.set(tableRel.tableVariableName, tableRel.relationships);
|
|
214
|
+
}
|
|
215
|
+
// Validate relationships
|
|
216
|
+
const tableNameMap = new Map(); // variableName -> tableName
|
|
217
|
+
for (const table of tables) {
|
|
218
|
+
tableNameMap.set(table.variableName, table.tableName);
|
|
219
|
+
}
|
|
220
|
+
const relationshipErrors = [];
|
|
221
|
+
for (const tableRel of extractedRelationships) {
|
|
222
|
+
for (const rel of tableRel.relationships) {
|
|
223
|
+
// Validate referenced table exists
|
|
224
|
+
const referencedTableExists = Array.from(tableNameMap.values()).includes(rel.referencedRelation);
|
|
225
|
+
if (!referencedTableExists) {
|
|
226
|
+
relationshipErrors.push(`Relationship on ${tableRel.tableVariableName} references unknown table: ${rel.referencedRelation}`);
|
|
227
|
+
}
|
|
228
|
+
// Validate columns are not empty
|
|
229
|
+
if (rel.columns.length === 0) {
|
|
230
|
+
relationshipErrors.push(`Relationship on ${tableRel.tableVariableName} has empty columns array`);
|
|
231
|
+
}
|
|
232
|
+
// Validate referenced columns are not empty
|
|
233
|
+
if (rel.referencedColumns.length === 0) {
|
|
234
|
+
relationshipErrors.push(`Relationship on ${tableRel.tableVariableName} has empty referencedColumns array`);
|
|
235
|
+
}
|
|
236
|
+
// Validate foreign key name format
|
|
237
|
+
if (!rel.foreignKeyName?.endsWith('_fk')) {
|
|
238
|
+
relationshipErrors.push(`Relationship on ${tableRel.tableVariableName} has invalid foreignKeyName: ${rel.foreignKeyName}`);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
if (relationshipErrors.length > 0) {
|
|
243
|
+
throw new Error(`Relationship validation failed:\n${relationshipErrors.map((e) => ` - ${e}`).join('\n')}`);
|
|
244
|
+
}
|
|
245
|
+
// Generate relationship arrays for all tables
|
|
246
|
+
const relationshipArrays = tables
|
|
247
|
+
.map((table) => {
|
|
248
|
+
const relationshipsVar = `${table.variableName}Relationships`;
|
|
249
|
+
const relationships = relationshipsMap.get(table.variableName) || [];
|
|
250
|
+
if (relationships.length === 0) {
|
|
251
|
+
return `// ${toPascalCase(table.variableName)} relationships
|
|
252
|
+
export const ${relationshipsVar}: readonly Relationship[] = []`;
|
|
253
|
+
}
|
|
254
|
+
// Format relationships as array
|
|
255
|
+
const relationshipsStr = relationships
|
|
256
|
+
.map((rel) => {
|
|
257
|
+
const columnsStr = rel.columns.map((c) => `'${c}'`).join(', ');
|
|
258
|
+
const refColumnsStr = rel.referencedColumns.map((c) => `'${c}'`).join(', ');
|
|
259
|
+
return ` { foreignKeyName: '${rel.foreignKeyName}', columns: [${columnsStr}], isOneToOne: ${rel.isOneToOne}, referencedRelation: '${rel.referencedRelation}', referencedColumns: [${refColumnsStr}] }`;
|
|
260
|
+
})
|
|
261
|
+
.join(',\n');
|
|
262
|
+
return `// ${toPascalCase(table.variableName)} relationships
|
|
263
|
+
export const ${relationshipsVar} = [
|
|
264
|
+
${relationshipsStr},
|
|
265
|
+
] as const satisfies readonly Relationship[]`;
|
|
266
|
+
})
|
|
267
|
+
.join('\n\n');
|
|
268
|
+
// Insert relationships after DatabaseRelationships type
|
|
269
|
+
const relationshipsMarker = '// Relationships will be inserted here';
|
|
270
|
+
const relationshipsIndex = header.indexOf(relationshipsMarker);
|
|
271
|
+
if (relationshipsIndex > -1) {
|
|
272
|
+
const before = header.substring(0, relationshipsIndex);
|
|
273
|
+
const after = header.substring(relationshipsIndex + relationshipsMarker.length);
|
|
274
|
+
return `${before + relationshipArrays}\n${after}`;
|
|
275
|
+
}
|
|
276
|
+
return header;
|
|
277
|
+
};
|
|
278
|
+
// Generate and write the file
|
|
279
|
+
try {
|
|
280
|
+
// Ensure directory exists
|
|
281
|
+
mkdirSync(dirname(outputPath), { recursive: true });
|
|
282
|
+
// Generate content
|
|
283
|
+
const content = generateDatabaseType();
|
|
284
|
+
// Write file
|
|
285
|
+
writeFileSync(outputPath, content, 'utf-8');
|
|
286
|
+
if (VERBOSE_LOGGING) {
|
|
287
|
+
logger.info(`✅ Generated Database type: ${outputPath.replace(rootDir, '.')}`);
|
|
288
|
+
logger.info(' - All tables included');
|
|
289
|
+
logger.info(' - Row, Insert, Update types generated');
|
|
290
|
+
logger.info(' - Relationships included');
|
|
291
|
+
logger.info(' - Supabase-compatible structure');
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
catch (error) {
|
|
295
|
+
logger.error('❌ Error generating Database type:', error instanceof Error ? error : undefined);
|
|
296
|
+
process.exit(1);
|
|
297
|
+
}
|
|
298
|
+
//# sourceMappingURL=generate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../../src/types/generate.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;GAaG;AAEH,8CAA8C;AAC9C,MAAM,eAAe,GACnB,OAAO,CAAC,GAAG,CAAC,UAAU,KAAK,OAAO;IAClC,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,IAAI,OAAO,CAAC,GAAG,CAAC,EAAE,KAAK,MAAM,CAAC,CAAA;AAEtE,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAClD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAC/C,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAC9D,OAAO,EAA8B,oBAAoB,EAAE,MAAM,4BAA4B,CAAA;AAE7F,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AACjD,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;AACrC,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,EAAE,UAAU,CAAC,CAAA;AAC3C,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,EAAE,aAAa,CAAC,CAAA;AAEjD,8BAA8B;AAC9B,MAAM,oBAAoB,GAAG,GAAG,EAAE;IAChC,oCAAoC;IACpC,MAAM,eAAe,GAAG,cAAc,EAAE,CAAA;IACxC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,GAAG,eAAe,CAAA;IAE3D,kCAAkC;IAClC,IAAI,eAAe,CAAC,MAAM,GA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ature parity with Supabase's Database type structure.
|
|
6
|
+
*
|
|
7
|
+
* ## Usage
|
|
8
|
+
*
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import type { Database } from '@revealui/db/types'
|
|
11
|
+
*
|
|
12
|
+
* // Extract table types
|
|
13
|
+
* type User = Database['public']['Tables']['users']['Row']
|
|
14
|
+
* type NewUser = Database['public']['Tables']['users']['Insert']
|
|
15
|
+
* type UserUpdate = Database['public']['Tables']['users']['Update']
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export type { AgentActionsInsert, AgentActionsRow, AgentActionsUpdate, AgentContextsInsert, AgentContextsRow, AgentContextsUpdate, AgentMemoriesInsert, AgentMemoriesRow, AgentMemoriesUpdate, ConversationsInsert, ConversationsRow, ConversationsUpdate, CrdtOperationsInsert, CrdtOperationsRow, CrdtOperationsUpdate, Database, DatabaseEnums, DatabaseRelationships, FailedAttemptsInsert, FailedAttemptsRow, FailedAttemptsUpdate, GlobalFooterInsert, GlobalFooterRow, GlobalFooterUpdate, GlobalHeaderInsert, GlobalHeaderRow, GlobalHeaderUpdate, GlobalSettingsInsert, GlobalSettingsRow, GlobalSettingsUpdate, MediaInsert, MediaRow, MediaUpdate, NodeIdMappingsInsert, NodeIdMappingsRow, NodeIdMappingsUpdate, PageRevisionsInsert, PageRevisionsRow, PageRevisionsUpdate, PagesInsert, PagesRow, PagesUpdate, PostsInsert, PostsRow, PostsUpdate, RateLimitsInsert, RateLimitsRow, RateLimitsUpdate, SessionsInsert, SessionsRow, SessionsUpdate, SiteCollaboratorsInsert, SiteCollaboratorsRow, SiteCollaboratorsUpdate, SitesInsert, SitesRow, SitesUpdate, TableInsert, TableRelationships, TableRow, TableUpdate, UsersInsert, UsersRow, UsersUpdate, } from './database.js';
|
|
19
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,YAAY,EACV,kBAAkB,EAClB,eAAe,EACf,kBAAkB,EAClB,mBAAmB,EACnB,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,EACnB,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,EACnB,gBAAgB,EAChB,mBAAmB,EACnB,oBAAoB,EACpB,iBAAiB,EACjB,oBAAoB,EACpB,QAAQ,EACR,aAAa,EACb,qBAAqB,EACrB,oBAAoB,EACpB,iBAAiB,EACjB,oBAAoB,EACpB,kBAAkB,EAClB,eAAe,EACf,kBAAkB,EAClB,kBAAkB,EAClB,eAAe,EACf,kBAAkB,EAClB,oBAAoB,EACpB,iBAAiB,EACjB,oBAAoB,EACpB,WAAW,EACX,QAAQ,EACR,WAAW,EACX,oBAAoB,EACpB,iBAAiB,EACjB,oBAAoB,EACpB,mBAAmB,EACnB,gBAAgB,EAChB,mBAAmB,EACnB,WAAW,EACX,QAAQ,EACR,WAAW,EACX,WAAW,EACX,QAAQ,EACR,WAAW,EACX,gBAAgB,EAChB,aAAa,EACb,gBAAgB,EAChB,cAAc,EACd,WAAW,EACX,cAAc,EACd,uBAAuB,EACvB,oBAAoB,EACpB,uBAAuB,EACvB,WAAW,EACX,QAAQ,EACR,WAAW,EACX,WAAW,EACX,kBAAkB,EAClB,QAAQ,EACR,WAAW,EACX,WAAW,EAEX,QAAQ,EACR,WAAW,GACZ,MAAM,eAAe,CAAA"}
|