zeti-framework-backend 0.2.4 → 0.2.5
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 +0 -0
- package/dist/chunk-VW7PIVLA.js +64 -0
- package/dist/chunk-VW7PIVLA.js.map +1 -0
- package/dist/index.d.ts +2 -54
- package/dist/index.js +4 -59
- package/dist/index.js.map +1 -1
- package/dist/prisma/index.d.ts +59 -0
- package/dist/prisma/index.js +10 -0
- package/dist/prisma/index.js.map +1 -0
- package/package.json +5 -1
package/README.md
ADDED
|
Binary file
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// src/prisma/config.ts
|
|
2
|
+
import "dotenv/config";
|
|
3
|
+
function findDatabaseUrl() {
|
|
4
|
+
if (process.env.DATABASE_URL) {
|
|
5
|
+
return process.env.DATABASE_URL;
|
|
6
|
+
}
|
|
7
|
+
for (const [key, value] of Object.entries(process.env)) {
|
|
8
|
+
if (!value) continue;
|
|
9
|
+
if (key.endsWith("_DATABASE_URL") || key.startsWith("DATABASE_") && key.endsWith("_URL")) {
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
throw new Error(
|
|
14
|
+
"Nenhuma URL de banco de dados encontrada no .env. Configure DATABASE_URL ou uma vari\xE1vel que termine com _DATABASE_URL."
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
function definePrismaConfig(zetiConfigOrOptions, options) {
|
|
18
|
+
let finalOptions;
|
|
19
|
+
let zetiConfig;
|
|
20
|
+
if (zetiConfigOrOptions && "databases" in zetiConfigOrOptions) {
|
|
21
|
+
zetiConfig = zetiConfigOrOptions;
|
|
22
|
+
finalOptions = options;
|
|
23
|
+
} else if (zetiConfigOrOptions) {
|
|
24
|
+
finalOptions = zetiConfigOrOptions;
|
|
25
|
+
}
|
|
26
|
+
const schema = finalOptions?.schema || "prisma/schema.prisma";
|
|
27
|
+
const migrationsPath = finalOptions?.migrationsPath || "prisma/migrations";
|
|
28
|
+
let databaseUrl;
|
|
29
|
+
if (zetiConfig) {
|
|
30
|
+
if (zetiConfig.databases?.connections?.default) {
|
|
31
|
+
databaseUrl = zetiConfig.databases.connections.default;
|
|
32
|
+
} else if (zetiConfig.databases?.connections) {
|
|
33
|
+
const firstConnection = Object.values(zetiConfig.databases.connections)[0];
|
|
34
|
+
if (firstConnection) {
|
|
35
|
+
databaseUrl = firstConnection;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (!databaseUrl) {
|
|
40
|
+
databaseUrl = findDatabaseUrl();
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
schema,
|
|
44
|
+
migrations: {
|
|
45
|
+
path: migrationsPath
|
|
46
|
+
},
|
|
47
|
+
datasource: {
|
|
48
|
+
url: databaseUrl
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function getAllDatabaseUrls(zetiConfig) {
|
|
53
|
+
const urls = {};
|
|
54
|
+
if (zetiConfig.databases.connections) {
|
|
55
|
+
Object.assign(urls, zetiConfig.databases.connections);
|
|
56
|
+
}
|
|
57
|
+
return urls;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export {
|
|
61
|
+
definePrismaConfig,
|
|
62
|
+
getAllDatabaseUrls
|
|
63
|
+
};
|
|
64
|
+
//# sourceMappingURL=chunk-VW7PIVLA.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/prisma/config.ts"],"sourcesContent":["import \"dotenv/config\";\r\nimport type { ZetiConfigInternal } from '../types/config';\r\n\r\nexport interface PrismaConfigOptions {\r\n /** Caminho do schema. Default: \"prisma/schema.prisma\" */\r\n schema?: string;\r\n /** Caminho das migrations. Default: \"prisma/migrations\" */\r\n migrationsPath?: string;\r\n}\r\n\r\ninterface PrismaDefineConfig {\r\n schema: string;\r\n migrations: {\r\n path: string;\r\n };\r\n datasource: {\r\n url: string;\r\n };\r\n}\r\n\r\n/**\r\n * Busca a URL do banco de dados no .env.\r\n * Procura por DATABASE_URL ou qualquer variável que termine com _DATABASE_URL.\r\n */\r\nfunction findDatabaseUrl(): string {\r\n // 1. Tenta DATABASE_URL (padrão para single-tenant e migrations)\r\n if (process.env.DATABASE_URL) {\r\n return process.env.DATABASE_URL;\r\n }\r\n\r\n // 2. Tenta encontrar qualquer URL de banco (para migrations de multi-tenant)\r\n for (const [key, value] of Object.entries(process.env)) {\r\n if (!value) continue;\r\n\r\n // Qualquer variável que termine com _DATABASE_URL\r\n if (key.endsWith('_DATABASE_URL') || (key.startsWith('DATABASE_') && key.endsWith('_URL'))) {\r\n return value;\r\n }\r\n }\r\n\r\n throw new Error(\r\n 'Nenhuma URL de banco de dados encontrada no .env. ' +\r\n 'Configure DATABASE_URL ou uma variável que termine com _DATABASE_URL.'\r\n );\r\n}\r\n\r\n/**\r\n * Gera a configuração do Prisma.\r\n * \r\n * Aceita opcionalmente um ZetiConfig, mas NÃO É NECESSÁRIO passá-lo.\r\n * A função busca automaticamente a URL do banco no .env.\r\n * \r\n * @example Uso simples (recomendado para evitar importar zeti.config.ts)\r\n * ```typescript\r\n * // prisma.config.ts\r\n * import { definePrismaConfig } from \"zeti-framework\";\r\n * \r\n * export default definePrismaConfig();\r\n * ```\r\n * \r\n * @example Uso com config (opcional)\r\n * ```typescript\r\n * // prisma.config.ts\r\n * import { zetiConfig } from \"./zeti.config\";\r\n * import { definePrismaConfig } from \"zeti-framework\";\r\n * \r\n * export default definePrismaConfig(zetiConfig);\r\n * ```\r\n */\r\nexport function definePrismaConfig(\r\n zetiConfigOrOptions?: ZetiConfigInternal | PrismaConfigOptions,\r\n options?: PrismaConfigOptions\r\n): PrismaDefineConfig {\r\n // Detecta se o primeiro argumento é um ZetiConfig ou PrismaConfigOptions\r\n let finalOptions: PrismaConfigOptions | undefined;\r\n let zetiConfig: ZetiConfigInternal | undefined;\r\n\r\n if (zetiConfigOrOptions && 'databases' in zetiConfigOrOptions) {\r\n // É um ZetiConfig\r\n zetiConfig = zetiConfigOrOptions;\r\n finalOptions = options;\r\n } else if (zetiConfigOrOptions) {\r\n // É PrismaConfigOptions\r\n finalOptions = zetiConfigOrOptions as PrismaConfigOptions;\r\n }\r\n\r\n const schema = finalOptions?.schema || \"prisma/schema.prisma\";\r\n const migrationsPath = finalOptions?.migrationsPath || \"prisma/migrations\";\r\n\r\n // Pega a URL do banco de dados\r\n let databaseUrl: string | undefined;\r\n\r\n if (zetiConfig) {\r\n // Se passou zetiConfig, tenta pegar do config primeiro\r\n if (zetiConfig.databases?.connections?.default) {\r\n databaseUrl = zetiConfig.databases.connections.default;\r\n } else if (zetiConfig.databases?.connections) {\r\n const firstConnection = Object.values(zetiConfig.databases.connections)[0];\r\n if (firstConnection) {\r\n databaseUrl = firstConnection;\r\n }\r\n }\r\n }\r\n\r\n // Se não encontrou no config (ou não passou config), busca no .env\r\n if (!databaseUrl) {\r\n databaseUrl = findDatabaseUrl();\r\n }\r\n\r\n return {\r\n schema,\r\n migrations: {\r\n path: migrationsPath,\r\n },\r\n datasource: {\r\n url: databaseUrl,\r\n },\r\n };\r\n}\r\n\r\n/**\r\n * Retorna todas as URLs de banco de dados configuradas (para multi-tenant migrations).\r\n * \r\n * @example\r\n * ```typescript\r\n * const urls = getAllDatabaseUrls(zetiConfig);\r\n * for (const [name, url] of Object.entries(urls)) {\r\n * console.log(`Migrating ${name}...`);\r\n * // executar migration para cada tenant\r\n * }\r\n * ```\r\n */\r\nexport function getAllDatabaseUrls(zetiConfig: ZetiConfigInternal): Record<string, string> {\r\n const urls: Record<string, string> = {};\r\n\r\n // Carrega conexões do config\r\n if (zetiConfig.databases.connections) {\r\n Object.assign(urls, zetiConfig.databases.connections);\r\n }\r\n\r\n return urls;\r\n}\r\n"],"mappings":";AAAA,OAAO;AAwBP,SAAS,kBAA0B;AAEjC,MAAI,QAAQ,IAAI,cAAc;AAC5B,WAAO,QAAQ,IAAI;AAAA,EACrB;AAGA,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,QAAQ,GAAG,GAAG;AACtD,QAAI,CAAC,MAAO;AAGZ,QAAI,IAAI,SAAS,eAAe,KAAM,IAAI,WAAW,WAAW,KAAK,IAAI,SAAS,MAAM,GAAI;AAC1F,aAAO;AAAA,IACT;AAAA,EACF;AAEA,QAAM,IAAI;AAAA,IACR;AAAA,EAEF;AACF;AAyBO,SAAS,mBACd,qBACA,SACoB;AAEpB,MAAI;AACJ,MAAI;AAEJ,MAAI,uBAAuB,eAAe,qBAAqB;AAE7D,iBAAa;AACb,mBAAe;AAAA,EACjB,WAAW,qBAAqB;AAE9B,mBAAe;AAAA,EACjB;AAEA,QAAM,SAAS,cAAc,UAAU;AACvC,QAAM,iBAAiB,cAAc,kBAAkB;AAGvD,MAAI;AAEJ,MAAI,YAAY;AAEd,QAAI,WAAW,WAAW,aAAa,SAAS;AAC9C,oBAAc,WAAW,UAAU,YAAY;AAAA,IACjD,WAAW,WAAW,WAAW,aAAa;AAC5C,YAAM,kBAAkB,OAAO,OAAO,WAAW,UAAU,WAAW,EAAE,CAAC;AACzE,UAAI,iBAAiB;AACnB,sBAAc;AAAA,MAChB;AAAA,IACF;AAAA,EACF;AAGA,MAAI,CAAC,aAAa;AAChB,kBAAc,gBAAgB;AAAA,EAChC;AAEA,SAAO;AAAA,IACL;AAAA,IACA,YAAY;AAAA,MACV,MAAM;AAAA,IACR;AAAA,IACA,YAAY;AAAA,MACV,KAAK;AAAA,IACP;AAAA,EACF;AACF;AAcO,SAAS,mBAAmB,YAAwD;AACzF,QAAM,OAA+B,CAAC;AAGtC,MAAI,WAAW,UAAU,aAAa;AACpC,WAAO,OAAO,MAAM,WAAW,UAAU,WAAW;AAAA,EACtD;AAEA,SAAO;AACT;","names":[]}
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { TenantManager } from './tenants/index.js';
|
|
|
8
8
|
export { MetricsCollector, TenantMetrics } from './tenants/index.js';
|
|
9
9
|
import Redis from 'ioredis';
|
|
10
10
|
export { default as Redis } from 'ioredis';
|
|
11
|
+
export { PrismaConfigOptions, definePrismaConfig, getAllDatabaseUrls } from './prisma/index.js';
|
|
11
12
|
import { z } from 'zod';
|
|
12
13
|
export { GenerateRegistryOptions, GenerateSwaggerTypesOptions, generateRegistry, generateSwaggerTypes, runPrebuild } from './scripts/index.js';
|
|
13
14
|
import 'hono/http-exception';
|
|
@@ -162,59 +163,6 @@ declare function hasRedis(): boolean;
|
|
|
162
163
|
declare function getRedisConfiguration(): RedisConfig | null;
|
|
163
164
|
declare function shutdownZeti(): Promise<void>;
|
|
164
165
|
|
|
165
|
-
interface PrismaConfigOptions {
|
|
166
|
-
/** Caminho do schema. Default: "prisma/schema.prisma" */
|
|
167
|
-
schema?: string;
|
|
168
|
-
/** Caminho das migrations. Default: "prisma/migrations" */
|
|
169
|
-
migrationsPath?: string;
|
|
170
|
-
}
|
|
171
|
-
interface PrismaDefineConfig {
|
|
172
|
-
schema: string;
|
|
173
|
-
migrations: {
|
|
174
|
-
path: string;
|
|
175
|
-
};
|
|
176
|
-
datasource: {
|
|
177
|
-
url: string;
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* Gera a configuração do Prisma.
|
|
182
|
-
*
|
|
183
|
-
* Aceita opcionalmente um ZetiConfig, mas NÃO É NECESSÁRIO passá-lo.
|
|
184
|
-
* A função busca automaticamente a URL do banco no .env.
|
|
185
|
-
*
|
|
186
|
-
* @example Uso simples (recomendado para evitar importar zeti.config.ts)
|
|
187
|
-
* ```typescript
|
|
188
|
-
* // prisma.config.ts
|
|
189
|
-
* import { definePrismaConfig } from "zeti-framework";
|
|
190
|
-
*
|
|
191
|
-
* export default definePrismaConfig();
|
|
192
|
-
* ```
|
|
193
|
-
*
|
|
194
|
-
* @example Uso com config (opcional)
|
|
195
|
-
* ```typescript
|
|
196
|
-
* // prisma.config.ts
|
|
197
|
-
* import { zetiConfig } from "./zeti.config";
|
|
198
|
-
* import { definePrismaConfig } from "zeti-framework";
|
|
199
|
-
*
|
|
200
|
-
* export default definePrismaConfig(zetiConfig);
|
|
201
|
-
* ```
|
|
202
|
-
*/
|
|
203
|
-
declare function definePrismaConfig(zetiConfigOrOptions?: ZetiConfigInternal | PrismaConfigOptions, options?: PrismaConfigOptions): PrismaDefineConfig;
|
|
204
|
-
/**
|
|
205
|
-
* Retorna todas as URLs de banco de dados configuradas (para multi-tenant migrations).
|
|
206
|
-
*
|
|
207
|
-
* @example
|
|
208
|
-
* ```typescript
|
|
209
|
-
* const urls = getAllDatabaseUrls(zetiConfig);
|
|
210
|
-
* for (const [name, url] of Object.entries(urls)) {
|
|
211
|
-
* console.log(`Migrating ${name}...`);
|
|
212
|
-
* // executar migration para cada tenant
|
|
213
|
-
* }
|
|
214
|
-
* ```
|
|
215
|
-
*/
|
|
216
|
-
declare function getAllDatabaseUrls(zetiConfig: ZetiConfigInternal): Record<string, string>;
|
|
217
|
-
|
|
218
166
|
declare function badRequestError(message: string, cause?: any): never;
|
|
219
167
|
declare function unauthorizedError(message: string, cause?: any): never;
|
|
220
168
|
declare function forbiddenError(message: string, cause?: any): never;
|
|
@@ -330,4 +278,4 @@ interface DatabaseContext {
|
|
|
330
278
|
*/
|
|
331
279
|
declare function getDbFromContext<TPrisma = any>(c: Context): TPrisma;
|
|
332
280
|
|
|
333
|
-
export { type DatabaseContext, FILE_SCHEMA_SYMBOL,
|
|
281
|
+
export { type DatabaseContext, FILE_SCHEMA_SYMBOL, RedisConfig, SchemaDefinition, type StartZetiOptions, SwaggerRegistry, TenantManager, WorkerConfig, WorkerInstance, WorkerManager, type ZetiApp, ZetiConfigInternal, ZetiMethodOptions, type ZetiMiddlewareHandler, ZetiPrismaConnectionConfig, autoInitializeZetiApp, badRequestError, conflictError, createAppProxy, createDatabaseMiddleware, createZetiApp, env, forbiddenError, getDbFromContext, getPrismaClient, getPrismaConnectionConfig, getRedis, getRedisConfiguration, getWorkerManager, getZetiApp, getZetiAppTyped, goneError, hasRedis, honoRoutesZeti, initializeZetiApp, internalServerError, isFileSchema, isMultipleFileSchema, loadEnv, notFoundError, shutdownZeti, startZeti, stopAllWorkers, unauthorizedError, unprocessableEntityError, zFile, zFiles };
|
package/dist/index.js
CHANGED
|
@@ -10,6 +10,10 @@ import {
|
|
|
10
10
|
generateSwaggerTypes,
|
|
11
11
|
runPrebuild
|
|
12
12
|
} from "./chunk-KIOZSPU2.js";
|
|
13
|
+
import {
|
|
14
|
+
definePrismaConfig,
|
|
15
|
+
getAllDatabaseUrls
|
|
16
|
+
} from "./chunk-VW7PIVLA.js";
|
|
13
17
|
import {
|
|
14
18
|
FILE_SCHEMA_SYMBOL,
|
|
15
19
|
generateSwagger,
|
|
@@ -11289,65 +11293,6 @@ function defineZetiConfig(config, options) {
|
|
|
11289
11293
|
};
|
|
11290
11294
|
}
|
|
11291
11295
|
|
|
11292
|
-
// src/prisma/config.ts
|
|
11293
|
-
import "dotenv/config";
|
|
11294
|
-
function findDatabaseUrl() {
|
|
11295
|
-
if (process.env.DATABASE_URL) {
|
|
11296
|
-
return process.env.DATABASE_URL;
|
|
11297
|
-
}
|
|
11298
|
-
for (const [key, value] of Object.entries(process.env)) {
|
|
11299
|
-
if (!value) continue;
|
|
11300
|
-
if (key.endsWith("_DATABASE_URL") || key.startsWith("DATABASE_") && key.endsWith("_URL")) {
|
|
11301
|
-
return value;
|
|
11302
|
-
}
|
|
11303
|
-
}
|
|
11304
|
-
throw new Error(
|
|
11305
|
-
"Nenhuma URL de banco de dados encontrada no .env. Configure DATABASE_URL ou uma vari\xE1vel que termine com _DATABASE_URL."
|
|
11306
|
-
);
|
|
11307
|
-
}
|
|
11308
|
-
function definePrismaConfig(zetiConfigOrOptions, options) {
|
|
11309
|
-
let finalOptions;
|
|
11310
|
-
let zetiConfig;
|
|
11311
|
-
if (zetiConfigOrOptions && "databases" in zetiConfigOrOptions) {
|
|
11312
|
-
zetiConfig = zetiConfigOrOptions;
|
|
11313
|
-
finalOptions = options;
|
|
11314
|
-
} else if (zetiConfigOrOptions) {
|
|
11315
|
-
finalOptions = zetiConfigOrOptions;
|
|
11316
|
-
}
|
|
11317
|
-
const schema = finalOptions?.schema || "prisma/schema.prisma";
|
|
11318
|
-
const migrationsPath = finalOptions?.migrationsPath || "prisma/migrations";
|
|
11319
|
-
let databaseUrl;
|
|
11320
|
-
if (zetiConfig) {
|
|
11321
|
-
if (zetiConfig.databases?.connections?.default) {
|
|
11322
|
-
databaseUrl = zetiConfig.databases.connections.default;
|
|
11323
|
-
} else if (zetiConfig.databases?.connections) {
|
|
11324
|
-
const firstConnection = Object.values(zetiConfig.databases.connections)[0];
|
|
11325
|
-
if (firstConnection) {
|
|
11326
|
-
databaseUrl = firstConnection;
|
|
11327
|
-
}
|
|
11328
|
-
}
|
|
11329
|
-
}
|
|
11330
|
-
if (!databaseUrl) {
|
|
11331
|
-
databaseUrl = findDatabaseUrl();
|
|
11332
|
-
}
|
|
11333
|
-
return {
|
|
11334
|
-
schema,
|
|
11335
|
-
migrations: {
|
|
11336
|
-
path: migrationsPath
|
|
11337
|
-
},
|
|
11338
|
-
datasource: {
|
|
11339
|
-
url: databaseUrl
|
|
11340
|
-
}
|
|
11341
|
-
};
|
|
11342
|
-
}
|
|
11343
|
-
function getAllDatabaseUrls(zetiConfig) {
|
|
11344
|
-
const urls = {};
|
|
11345
|
-
if (zetiConfig.databases.connections) {
|
|
11346
|
-
Object.assign(urls, zetiConfig.databases.connections);
|
|
11347
|
-
}
|
|
11348
|
-
return urls;
|
|
11349
|
-
}
|
|
11350
|
-
|
|
11351
11296
|
// src/utils/error-handler.ts
|
|
11352
11297
|
import { HTTPException } from "hono/http-exception";
|
|
11353
11298
|
function isJsonParseError(err) {
|