postgresdk 0.1.1 → 0.1.2-alpha.1
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 +419 -8
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +547 -0
- package/dist/emit-server-index.d.ts +5 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +547 -0
- package/package.json +4 -3
package/dist/index.js
CHANGED
@@ -1,4 +1,466 @@
|
|
1
|
+
import { createRequire } from "node:module";
|
2
|
+
var __create = Object.create;
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
4
|
+
var __defProp = Object.defineProperty;
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
7
|
+
var __toESM = (mod, isNodeMode, target) => {
|
8
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
9
|
+
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
10
|
+
for (let key of __getOwnPropNames(mod))
|
11
|
+
if (!__hasOwnProp.call(to, key))
|
12
|
+
__defProp(to, key, {
|
13
|
+
get: () => mod[key],
|
14
|
+
enumerable: true
|
15
|
+
});
|
16
|
+
return to;
|
17
|
+
};
|
18
|
+
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
19
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
20
|
+
|
21
|
+
// node_modules/dotenv/package.json
|
22
|
+
var require_package = __commonJS((exports, module) => {
|
23
|
+
module.exports = {
|
24
|
+
name: "dotenv",
|
25
|
+
version: "17.2.1",
|
26
|
+
description: "Loads environment variables from .env file",
|
27
|
+
main: "lib/main.js",
|
28
|
+
types: "lib/main.d.ts",
|
29
|
+
exports: {
|
30
|
+
".": {
|
31
|
+
types: "./lib/main.d.ts",
|
32
|
+
require: "./lib/main.js",
|
33
|
+
default: "./lib/main.js"
|
34
|
+
},
|
35
|
+
"./config": "./config.js",
|
36
|
+
"./config.js": "./config.js",
|
37
|
+
"./lib/env-options": "./lib/env-options.js",
|
38
|
+
"./lib/env-options.js": "./lib/env-options.js",
|
39
|
+
"./lib/cli-options": "./lib/cli-options.js",
|
40
|
+
"./lib/cli-options.js": "./lib/cli-options.js",
|
41
|
+
"./package.json": "./package.json"
|
42
|
+
},
|
43
|
+
scripts: {
|
44
|
+
"dts-check": "tsc --project tests/types/tsconfig.json",
|
45
|
+
lint: "standard",
|
46
|
+
pretest: "npm run lint && npm run dts-check",
|
47
|
+
test: "tap run --allow-empty-coverage --disable-coverage --timeout=60000",
|
48
|
+
"test:coverage": "tap run --show-full-coverage --timeout=60000 --coverage-report=text --coverage-report=lcov",
|
49
|
+
prerelease: "npm test",
|
50
|
+
release: "standard-version"
|
51
|
+
},
|
52
|
+
repository: {
|
53
|
+
type: "git",
|
54
|
+
url: "git://github.com/motdotla/dotenv.git"
|
55
|
+
},
|
56
|
+
homepage: "https://github.com/motdotla/dotenv#readme",
|
57
|
+
funding: "https://dotenvx.com",
|
58
|
+
keywords: [
|
59
|
+
"dotenv",
|
60
|
+
"env",
|
61
|
+
".env",
|
62
|
+
"environment",
|
63
|
+
"variables",
|
64
|
+
"config",
|
65
|
+
"settings"
|
66
|
+
],
|
67
|
+
readmeFilename: "README.md",
|
68
|
+
license: "BSD-2-Clause",
|
69
|
+
devDependencies: {
|
70
|
+
"@types/node": "^18.11.3",
|
71
|
+
decache: "^4.6.2",
|
72
|
+
sinon: "^14.0.1",
|
73
|
+
standard: "^17.0.0",
|
74
|
+
"standard-version": "^9.5.0",
|
75
|
+
tap: "^19.2.0",
|
76
|
+
typescript: "^4.8.4"
|
77
|
+
},
|
78
|
+
engines: {
|
79
|
+
node: ">=12"
|
80
|
+
},
|
81
|
+
browser: {
|
82
|
+
fs: false
|
83
|
+
}
|
84
|
+
};
|
85
|
+
});
|
86
|
+
|
87
|
+
// node_modules/dotenv/lib/main.js
|
88
|
+
var require_main = __commonJS((exports, module) => {
|
89
|
+
var fs = __require("fs");
|
90
|
+
var path = __require("path");
|
91
|
+
var os = __require("os");
|
92
|
+
var crypto = __require("crypto");
|
93
|
+
var packageJson = require_package();
|
94
|
+
var version = packageJson.version;
|
95
|
+
var TIPS = [
|
96
|
+
"\uD83D\uDD10 encrypt with Dotenvx: https://dotenvx.com",
|
97
|
+
"\uD83D\uDD10 prevent committing .env to code: https://dotenvx.com/precommit",
|
98
|
+
"\uD83D\uDD10 prevent building .env in docker: https://dotenvx.com/prebuild",
|
99
|
+
"\uD83D\uDCE1 observe env with Radar: https://dotenvx.com/radar",
|
100
|
+
"\uD83D\uDCE1 auto-backup env with Radar: https://dotenvx.com/radar",
|
101
|
+
"\uD83D\uDCE1 version env with Radar: https://dotenvx.com/radar",
|
102
|
+
"\uD83D\uDEE0️ run anywhere with `dotenvx run -- yourcommand`",
|
103
|
+
"⚙️ specify custom .env file path with { path: '/custom/path/.env' }",
|
104
|
+
"⚙️ enable debug logging with { debug: true }",
|
105
|
+
"⚙️ override existing env vars with { override: true }",
|
106
|
+
"⚙️ suppress all logs with { quiet: true }",
|
107
|
+
"⚙️ write to custom object with { processEnv: myObject }",
|
108
|
+
"⚙️ load multiple .env files with { path: ['.env.local', '.env'] }"
|
109
|
+
];
|
110
|
+
function _getRandomTip() {
|
111
|
+
return TIPS[Math.floor(Math.random() * TIPS.length)];
|
112
|
+
}
|
113
|
+
function parseBoolean(value) {
|
114
|
+
if (typeof value === "string") {
|
115
|
+
return !["false", "0", "no", "off", ""].includes(value.toLowerCase());
|
116
|
+
}
|
117
|
+
return Boolean(value);
|
118
|
+
}
|
119
|
+
function supportsAnsi() {
|
120
|
+
return process.stdout.isTTY;
|
121
|
+
}
|
122
|
+
function dim(text) {
|
123
|
+
return supportsAnsi() ? `\x1B[2m${text}\x1B[0m` : text;
|
124
|
+
}
|
125
|
+
var LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;
|
126
|
+
function parse(src) {
|
127
|
+
const obj = {};
|
128
|
+
let lines = src.toString();
|
129
|
+
lines = lines.replace(/\r\n?/mg, `
|
130
|
+
`);
|
131
|
+
let match;
|
132
|
+
while ((match = LINE.exec(lines)) != null) {
|
133
|
+
const key = match[1];
|
134
|
+
let value = match[2] || "";
|
135
|
+
value = value.trim();
|
136
|
+
const maybeQuote = value[0];
|
137
|
+
value = value.replace(/^(['"`])([\s\S]*)\1$/mg, "$2");
|
138
|
+
if (maybeQuote === '"') {
|
139
|
+
value = value.replace(/\\n/g, `
|
140
|
+
`);
|
141
|
+
value = value.replace(/\\r/g, "\r");
|
142
|
+
}
|
143
|
+
obj[key] = value;
|
144
|
+
}
|
145
|
+
return obj;
|
146
|
+
}
|
147
|
+
function _parseVault(options) {
|
148
|
+
options = options || {};
|
149
|
+
const vaultPath = _vaultPath(options);
|
150
|
+
options.path = vaultPath;
|
151
|
+
const result = DotenvModule.configDotenv(options);
|
152
|
+
if (!result.parsed) {
|
153
|
+
const err = new Error(`MISSING_DATA: Cannot parse ${vaultPath} for an unknown reason`);
|
154
|
+
err.code = "MISSING_DATA";
|
155
|
+
throw err;
|
156
|
+
}
|
157
|
+
const keys = _dotenvKey(options).split(",");
|
158
|
+
const length = keys.length;
|
159
|
+
let decrypted;
|
160
|
+
for (let i = 0;i < length; i++) {
|
161
|
+
try {
|
162
|
+
const key = keys[i].trim();
|
163
|
+
const attrs = _instructions(result, key);
|
164
|
+
decrypted = DotenvModule.decrypt(attrs.ciphertext, attrs.key);
|
165
|
+
break;
|
166
|
+
} catch (error) {
|
167
|
+
if (i + 1 >= length) {
|
168
|
+
throw error;
|
169
|
+
}
|
170
|
+
}
|
171
|
+
}
|
172
|
+
return DotenvModule.parse(decrypted);
|
173
|
+
}
|
174
|
+
function _warn(message) {
|
175
|
+
console.error(`[dotenv@${version}][WARN] ${message}`);
|
176
|
+
}
|
177
|
+
function _debug(message) {
|
178
|
+
console.log(`[dotenv@${version}][DEBUG] ${message}`);
|
179
|
+
}
|
180
|
+
function _log(message) {
|
181
|
+
console.log(`[dotenv@${version}] ${message}`);
|
182
|
+
}
|
183
|
+
function _dotenvKey(options) {
|
184
|
+
if (options && options.DOTENV_KEY && options.DOTENV_KEY.length > 0) {
|
185
|
+
return options.DOTENV_KEY;
|
186
|
+
}
|
187
|
+
if (process.env.DOTENV_KEY && process.env.DOTENV_KEY.length > 0) {
|
188
|
+
return process.env.DOTENV_KEY;
|
189
|
+
}
|
190
|
+
return "";
|
191
|
+
}
|
192
|
+
function _instructions(result, dotenvKey) {
|
193
|
+
let uri;
|
194
|
+
try {
|
195
|
+
uri = new URL(dotenvKey);
|
196
|
+
} catch (error) {
|
197
|
+
if (error.code === "ERR_INVALID_URL") {
|
198
|
+
const err = new Error("INVALID_DOTENV_KEY: Wrong format. Must be in valid uri format like dotenv://:key_1234@dotenvx.com/vault/.env.vault?environment=development");
|
199
|
+
err.code = "INVALID_DOTENV_KEY";
|
200
|
+
throw err;
|
201
|
+
}
|
202
|
+
throw error;
|
203
|
+
}
|
204
|
+
const key = uri.password;
|
205
|
+
if (!key) {
|
206
|
+
const err = new Error("INVALID_DOTENV_KEY: Missing key part");
|
207
|
+
err.code = "INVALID_DOTENV_KEY";
|
208
|
+
throw err;
|
209
|
+
}
|
210
|
+
const environment = uri.searchParams.get("environment");
|
211
|
+
if (!environment) {
|
212
|
+
const err = new Error("INVALID_DOTENV_KEY: Missing environment part");
|
213
|
+
err.code = "INVALID_DOTENV_KEY";
|
214
|
+
throw err;
|
215
|
+
}
|
216
|
+
const environmentKey = `DOTENV_VAULT_${environment.toUpperCase()}`;
|
217
|
+
const ciphertext = result.parsed[environmentKey];
|
218
|
+
if (!ciphertext) {
|
219
|
+
const err = new Error(`NOT_FOUND_DOTENV_ENVIRONMENT: Cannot locate environment ${environmentKey} in your .env.vault file.`);
|
220
|
+
err.code = "NOT_FOUND_DOTENV_ENVIRONMENT";
|
221
|
+
throw err;
|
222
|
+
}
|
223
|
+
return { ciphertext, key };
|
224
|
+
}
|
225
|
+
function _vaultPath(options) {
|
226
|
+
let possibleVaultPath = null;
|
227
|
+
if (options && options.path && options.path.length > 0) {
|
228
|
+
if (Array.isArray(options.path)) {
|
229
|
+
for (const filepath of options.path) {
|
230
|
+
if (fs.existsSync(filepath)) {
|
231
|
+
possibleVaultPath = filepath.endsWith(".vault") ? filepath : `${filepath}.vault`;
|
232
|
+
}
|
233
|
+
}
|
234
|
+
} else {
|
235
|
+
possibleVaultPath = options.path.endsWith(".vault") ? options.path : `${options.path}.vault`;
|
236
|
+
}
|
237
|
+
} else {
|
238
|
+
possibleVaultPath = path.resolve(process.cwd(), ".env.vault");
|
239
|
+
}
|
240
|
+
if (fs.existsSync(possibleVaultPath)) {
|
241
|
+
return possibleVaultPath;
|
242
|
+
}
|
243
|
+
return null;
|
244
|
+
}
|
245
|
+
function _resolveHome(envPath) {
|
246
|
+
return envPath[0] === "~" ? path.join(os.homedir(), envPath.slice(1)) : envPath;
|
247
|
+
}
|
248
|
+
function _configVault(options) {
|
249
|
+
const debug = parseBoolean(process.env.DOTENV_CONFIG_DEBUG || options && options.debug);
|
250
|
+
const quiet = parseBoolean(process.env.DOTENV_CONFIG_QUIET || options && options.quiet);
|
251
|
+
if (debug || !quiet) {
|
252
|
+
_log("Loading env from encrypted .env.vault");
|
253
|
+
}
|
254
|
+
const parsed = DotenvModule._parseVault(options);
|
255
|
+
let processEnv = process.env;
|
256
|
+
if (options && options.processEnv != null) {
|
257
|
+
processEnv = options.processEnv;
|
258
|
+
}
|
259
|
+
DotenvModule.populate(processEnv, parsed, options);
|
260
|
+
return { parsed };
|
261
|
+
}
|
262
|
+
function configDotenv(options) {
|
263
|
+
const dotenvPath = path.resolve(process.cwd(), ".env");
|
264
|
+
let encoding = "utf8";
|
265
|
+
let processEnv = process.env;
|
266
|
+
if (options && options.processEnv != null) {
|
267
|
+
processEnv = options.processEnv;
|
268
|
+
}
|
269
|
+
let debug = parseBoolean(processEnv.DOTENV_CONFIG_DEBUG || options && options.debug);
|
270
|
+
let quiet = parseBoolean(processEnv.DOTENV_CONFIG_QUIET || options && options.quiet);
|
271
|
+
if (options && options.encoding) {
|
272
|
+
encoding = options.encoding;
|
273
|
+
} else {
|
274
|
+
if (debug) {
|
275
|
+
_debug("No encoding is specified. UTF-8 is used by default");
|
276
|
+
}
|
277
|
+
}
|
278
|
+
let optionPaths = [dotenvPath];
|
279
|
+
if (options && options.path) {
|
280
|
+
if (!Array.isArray(options.path)) {
|
281
|
+
optionPaths = [_resolveHome(options.path)];
|
282
|
+
} else {
|
283
|
+
optionPaths = [];
|
284
|
+
for (const filepath of options.path) {
|
285
|
+
optionPaths.push(_resolveHome(filepath));
|
286
|
+
}
|
287
|
+
}
|
288
|
+
}
|
289
|
+
let lastError;
|
290
|
+
const parsedAll = {};
|
291
|
+
for (const path2 of optionPaths) {
|
292
|
+
try {
|
293
|
+
const parsed = DotenvModule.parse(fs.readFileSync(path2, { encoding }));
|
294
|
+
DotenvModule.populate(parsedAll, parsed, options);
|
295
|
+
} catch (e) {
|
296
|
+
if (debug) {
|
297
|
+
_debug(`Failed to load ${path2} ${e.message}`);
|
298
|
+
}
|
299
|
+
lastError = e;
|
300
|
+
}
|
301
|
+
}
|
302
|
+
const populated = DotenvModule.populate(processEnv, parsedAll, options);
|
303
|
+
debug = parseBoolean(processEnv.DOTENV_CONFIG_DEBUG || debug);
|
304
|
+
quiet = parseBoolean(processEnv.DOTENV_CONFIG_QUIET || quiet);
|
305
|
+
if (debug || !quiet) {
|
306
|
+
const keysCount = Object.keys(populated).length;
|
307
|
+
const shortPaths = [];
|
308
|
+
for (const filePath of optionPaths) {
|
309
|
+
try {
|
310
|
+
const relative = path.relative(process.cwd(), filePath);
|
311
|
+
shortPaths.push(relative);
|
312
|
+
} catch (e) {
|
313
|
+
if (debug) {
|
314
|
+
_debug(`Failed to load ${filePath} ${e.message}`);
|
315
|
+
}
|
316
|
+
lastError = e;
|
317
|
+
}
|
318
|
+
}
|
319
|
+
_log(`injecting env (${keysCount}) from ${shortPaths.join(",")} ${dim(`-- tip: ${_getRandomTip()}`)}`);
|
320
|
+
}
|
321
|
+
if (lastError) {
|
322
|
+
return { parsed: parsedAll, error: lastError };
|
323
|
+
} else {
|
324
|
+
return { parsed: parsedAll };
|
325
|
+
}
|
326
|
+
}
|
327
|
+
function config(options) {
|
328
|
+
if (_dotenvKey(options).length === 0) {
|
329
|
+
return DotenvModule.configDotenv(options);
|
330
|
+
}
|
331
|
+
const vaultPath = _vaultPath(options);
|
332
|
+
if (!vaultPath) {
|
333
|
+
_warn(`You set DOTENV_KEY but you are missing a .env.vault file at ${vaultPath}. Did you forget to build it?`);
|
334
|
+
return DotenvModule.configDotenv(options);
|
335
|
+
}
|
336
|
+
return DotenvModule._configVault(options);
|
337
|
+
}
|
338
|
+
function decrypt(encrypted, keyStr) {
|
339
|
+
const key = Buffer.from(keyStr.slice(-64), "hex");
|
340
|
+
let ciphertext = Buffer.from(encrypted, "base64");
|
341
|
+
const nonce = ciphertext.subarray(0, 12);
|
342
|
+
const authTag = ciphertext.subarray(-16);
|
343
|
+
ciphertext = ciphertext.subarray(12, -16);
|
344
|
+
try {
|
345
|
+
const aesgcm = crypto.createDecipheriv("aes-256-gcm", key, nonce);
|
346
|
+
aesgcm.setAuthTag(authTag);
|
347
|
+
return `${aesgcm.update(ciphertext)}${aesgcm.final()}`;
|
348
|
+
} catch (error) {
|
349
|
+
const isRange = error instanceof RangeError;
|
350
|
+
const invalidKeyLength = error.message === "Invalid key length";
|
351
|
+
const decryptionFailed = error.message === "Unsupported state or unable to authenticate data";
|
352
|
+
if (isRange || invalidKeyLength) {
|
353
|
+
const err = new Error("INVALID_DOTENV_KEY: It must be 64 characters long (or more)");
|
354
|
+
err.code = "INVALID_DOTENV_KEY";
|
355
|
+
throw err;
|
356
|
+
} else if (decryptionFailed) {
|
357
|
+
const err = new Error("DECRYPTION_FAILED: Please check your DOTENV_KEY");
|
358
|
+
err.code = "DECRYPTION_FAILED";
|
359
|
+
throw err;
|
360
|
+
} else {
|
361
|
+
throw error;
|
362
|
+
}
|
363
|
+
}
|
364
|
+
}
|
365
|
+
function populate(processEnv, parsed, options = {}) {
|
366
|
+
const debug = Boolean(options && options.debug);
|
367
|
+
const override = Boolean(options && options.override);
|
368
|
+
const populated = {};
|
369
|
+
if (typeof parsed !== "object") {
|
370
|
+
const err = new Error("OBJECT_REQUIRED: Please check the processEnv argument being passed to populate");
|
371
|
+
err.code = "OBJECT_REQUIRED";
|
372
|
+
throw err;
|
373
|
+
}
|
374
|
+
for (const key of Object.keys(parsed)) {
|
375
|
+
if (Object.prototype.hasOwnProperty.call(processEnv, key)) {
|
376
|
+
if (override === true) {
|
377
|
+
processEnv[key] = parsed[key];
|
378
|
+
populated[key] = parsed[key];
|
379
|
+
}
|
380
|
+
if (debug) {
|
381
|
+
if (override === true) {
|
382
|
+
_debug(`"${key}" is already defined and WAS overwritten`);
|
383
|
+
} else {
|
384
|
+
_debug(`"${key}" is already defined and was NOT overwritten`);
|
385
|
+
}
|
386
|
+
}
|
387
|
+
} else {
|
388
|
+
processEnv[key] = parsed[key];
|
389
|
+
populated[key] = parsed[key];
|
390
|
+
}
|
391
|
+
}
|
392
|
+
return populated;
|
393
|
+
}
|
394
|
+
var DotenvModule = {
|
395
|
+
configDotenv,
|
396
|
+
_configVault,
|
397
|
+
_parseVault,
|
398
|
+
config,
|
399
|
+
decrypt,
|
400
|
+
parse,
|
401
|
+
populate
|
402
|
+
};
|
403
|
+
exports.configDotenv = DotenvModule.configDotenv;
|
404
|
+
exports._configVault = DotenvModule._configVault;
|
405
|
+
exports._parseVault = DotenvModule._parseVault;
|
406
|
+
exports.config = DotenvModule.config;
|
407
|
+
exports.decrypt = DotenvModule.decrypt;
|
408
|
+
exports.parse = DotenvModule.parse;
|
409
|
+
exports.populate = DotenvModule.populate;
|
410
|
+
module.exports = DotenvModule;
|
411
|
+
});
|
412
|
+
|
413
|
+
// node_modules/dotenv/lib/env-options.js
|
414
|
+
var require_env_options = __commonJS((exports, module) => {
|
415
|
+
var options = {};
|
416
|
+
if (process.env.DOTENV_CONFIG_ENCODING != null) {
|
417
|
+
options.encoding = process.env.DOTENV_CONFIG_ENCODING;
|
418
|
+
}
|
419
|
+
if (process.env.DOTENV_CONFIG_PATH != null) {
|
420
|
+
options.path = process.env.DOTENV_CONFIG_PATH;
|
421
|
+
}
|
422
|
+
if (process.env.DOTENV_CONFIG_QUIET != null) {
|
423
|
+
options.quiet = process.env.DOTENV_CONFIG_QUIET;
|
424
|
+
}
|
425
|
+
if (process.env.DOTENV_CONFIG_DEBUG != null) {
|
426
|
+
options.debug = process.env.DOTENV_CONFIG_DEBUG;
|
427
|
+
}
|
428
|
+
if (process.env.DOTENV_CONFIG_OVERRIDE != null) {
|
429
|
+
options.override = process.env.DOTENV_CONFIG_OVERRIDE;
|
430
|
+
}
|
431
|
+
if (process.env.DOTENV_CONFIG_DOTENV_KEY != null) {
|
432
|
+
options.DOTENV_KEY = process.env.DOTENV_CONFIG_DOTENV_KEY;
|
433
|
+
}
|
434
|
+
module.exports = options;
|
435
|
+
});
|
436
|
+
|
437
|
+
// node_modules/dotenv/lib/cli-options.js
|
438
|
+
var require_cli_options = __commonJS((exports, module) => {
|
439
|
+
var re = /^dotenv_config_(encoding|path|quiet|debug|override|DOTENV_KEY)=(.+)$/;
|
440
|
+
module.exports = function optionMatcher(args) {
|
441
|
+
const options = args.reduce(function(acc, cur) {
|
442
|
+
const matches = cur.match(re);
|
443
|
+
if (matches) {
|
444
|
+
acc[matches[1]] = matches[2];
|
445
|
+
}
|
446
|
+
return acc;
|
447
|
+
}, {});
|
448
|
+
if (!("quiet" in options)) {
|
449
|
+
options.quiet = "true";
|
450
|
+
}
|
451
|
+
return options;
|
452
|
+
};
|
453
|
+
});
|
454
|
+
|
455
|
+
// node_modules/dotenv/config.js
|
456
|
+
var require_config = __commonJS(() => {
|
457
|
+
(function() {
|
458
|
+
require_main().config(Object.assign({}, require_env_options(), require_cli_options()(process.argv)));
|
459
|
+
})();
|
460
|
+
});
|
461
|
+
|
1
462
|
// src/index.ts
|
463
|
+
var import_config = __toESM(require_config(), 1);
|
2
464
|
import { join } from "node:path";
|
3
465
|
import { pathToFileURL } from "node:url";
|
4
466
|
|
@@ -1196,6 +1658,87 @@ export async function authMiddleware(c: Context, next: Next) {
|
|
1196
1658
|
`;
|
1197
1659
|
}
|
1198
1660
|
|
1661
|
+
// src/emit-server-index.ts
|
1662
|
+
function emitServerIndex(tables, hasAuth) {
|
1663
|
+
const tableNames = tables.map((t) => t.name).sort();
|
1664
|
+
const imports = tableNames.map((name) => {
|
1665
|
+
const Type = pascal(name);
|
1666
|
+
return `import { register${Type}Routes } from "./routes/${name}";`;
|
1667
|
+
}).join(`
|
1668
|
+
`);
|
1669
|
+
const registrations = tableNames.map((name) => {
|
1670
|
+
const Type = pascal(name);
|
1671
|
+
return ` register${Type}Routes(router, deps);`;
|
1672
|
+
}).join(`
|
1673
|
+
`);
|
1674
|
+
const reExports = tableNames.map((name) => {
|
1675
|
+
const Type = pascal(name);
|
1676
|
+
return `export { register${Type}Routes } from "./routes/${name}";`;
|
1677
|
+
}).join(`
|
1678
|
+
`);
|
1679
|
+
return `/* Generated. Do not edit. */
|
1680
|
+
import { Hono } from "hono";
|
1681
|
+
${imports}
|
1682
|
+
${hasAuth ? `export { authMiddleware } from "./auth";` : ""}
|
1683
|
+
|
1684
|
+
/**
|
1685
|
+
* Creates a Hono router with all generated routes that can be mounted into your existing app.
|
1686
|
+
*
|
1687
|
+
* @example
|
1688
|
+
* import { Hono } from "hono";
|
1689
|
+
* import { Client } from "pg";
|
1690
|
+
* import { createRouter } from "./generated/server";
|
1691
|
+
*
|
1692
|
+
* const app = new Hono();
|
1693
|
+
* const pg = new Client({ connectionString: process.env.DATABASE_URL });
|
1694
|
+
* await pg.connect();
|
1695
|
+
*
|
1696
|
+
* // Mount all generated routes under /api
|
1697
|
+
* const apiRouter = createRouter({ pg });
|
1698
|
+
* app.route("/api", apiRouter);
|
1699
|
+
*
|
1700
|
+
* // Or mount directly at root
|
1701
|
+
* const router = createRouter({ pg });
|
1702
|
+
* app.route("/", router);
|
1703
|
+
*/
|
1704
|
+
export function createRouter(
|
1705
|
+
deps: { pg: { query: (text: string, params?: any[]) => Promise<{ rows: any[] }> } }
|
1706
|
+
): Hono {
|
1707
|
+
const router = new Hono();
|
1708
|
+
${registrations}
|
1709
|
+
return router;
|
1710
|
+
}
|
1711
|
+
|
1712
|
+
/**
|
1713
|
+
* Register all generated routes directly on an existing Hono app.
|
1714
|
+
*
|
1715
|
+
* @example
|
1716
|
+
* import { Hono } from "hono";
|
1717
|
+
* import { Client } from "pg";
|
1718
|
+
* import { registerAllRoutes } from "./generated/server";
|
1719
|
+
*
|
1720
|
+
* const app = new Hono();
|
1721
|
+
* const pg = new Client({ connectionString: process.env.DATABASE_URL });
|
1722
|
+
* await pg.connect();
|
1723
|
+
*
|
1724
|
+
* // Register all routes at once
|
1725
|
+
* registerAllRoutes(app, { pg });
|
1726
|
+
*/
|
1727
|
+
export function registerAllRoutes(
|
1728
|
+
app: Hono,
|
1729
|
+
deps: { pg: { query: (text: string, params?: any[]) => Promise<{ rows: any[] }> } }
|
1730
|
+
) {
|
1731
|
+
${registrations.replace(/router/g, "app")}
|
1732
|
+
}
|
1733
|
+
|
1734
|
+
// Individual route registrations (for selective use)
|
1735
|
+
${reExports}
|
1736
|
+
|
1737
|
+
// Re-export types and schemas for convenience
|
1738
|
+
export * from "./include-spec";
|
1739
|
+
`;
|
1740
|
+
}
|
1741
|
+
|
1199
1742
|
// src/index.ts
|
1200
1743
|
async function generate(configPath) {
|
1201
1744
|
const configUrl = pathToFileURL(configPath).href;
|
@@ -1258,6 +1801,10 @@ async function generate(configPath) {
|
|
1258
1801
|
path: join(clientDir, "index.ts"),
|
1259
1802
|
content: emitClientIndex(Object.values(model.tables))
|
1260
1803
|
});
|
1804
|
+
files.push({
|
1805
|
+
path: join(serverDir, "index.ts"),
|
1806
|
+
content: emitServerIndex(Object.values(model.tables), !!cfg.auth?.strategy && cfg.auth.strategy !== "none")
|
1807
|
+
});
|
1261
1808
|
console.log("✍️ Writing files...");
|
1262
1809
|
await writeFiles(files);
|
1263
1810
|
console.log(`✅ Generated ${files.length} files`);
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "postgresdk",
|
3
|
-
"version": "0.1.1",
|
3
|
+
"version": "0.1.2-alpha.1",
|
4
4
|
"description": "Generate a typed server/client SDK from a Postgres schema (includes, Zod, Hono).",
|
5
5
|
"type": "module",
|
6
6
|
"bin": {
|
@@ -29,9 +29,10 @@
|
|
29
29
|
"publish:major": "./publish.sh"
|
30
30
|
},
|
31
31
|
"dependencies": {
|
32
|
+
"dotenv": "^17.2.1",
|
33
|
+
"hono": "^4.9.0",
|
32
34
|
"pg": "^8.16.3",
|
33
|
-
"zod": "^4.0.15"
|
34
|
-
"hono": "^4.9.0"
|
35
|
+
"zod": "^4.0.15"
|
35
36
|
},
|
36
37
|
"devDependencies": {
|
37
38
|
"@types/node": "^20.0.0",
|