@flowdular/sdk 0.2.0 → 0.2.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/package.json
CHANGED
|
@@ -81,22 +81,40 @@ export function createPgliteCluster(
|
|
|
81
81
|
const close = (): Promise<void> => {
|
|
82
82
|
closePromise ??= (async () => {
|
|
83
83
|
if (!databasePromise) return;
|
|
84
|
-
|
|
84
|
+
// A failed initialization has no database to close; its caller already
|
|
85
|
+
// received the original error. Do not replace it during disposal.
|
|
86
|
+
const instance = await databasePromise.catch(() => undefined);
|
|
85
87
|
databasePromise = undefined;
|
|
86
|
-
await instance
|
|
88
|
+
await instance?.close();
|
|
87
89
|
})();
|
|
88
90
|
return closePromise;
|
|
89
91
|
};
|
|
90
92
|
|
|
91
93
|
const database = async (): Promise<PGlite> => {
|
|
92
94
|
databasePromise ??= (async () => {
|
|
95
|
+
if (options.dataDirectory) {
|
|
96
|
+
const { mkdir } = await import('node:fs/promises');
|
|
97
|
+
await mkdir(options.dataDirectory, { recursive: true, mode: 0o700 });
|
|
98
|
+
}
|
|
93
99
|
const created = options.dataDirectory
|
|
94
100
|
? await PGlite.create({
|
|
95
101
|
dataDir: options.dataDirectory,
|
|
96
102
|
parsers: SERVER_PARSERS,
|
|
97
103
|
})
|
|
98
104
|
: await PGlite.create({ parsers: SERVER_PARSERS });
|
|
99
|
-
|
|
105
|
+
try {
|
|
106
|
+
if (options.bootstrap) await created.exec(options.bootstrap);
|
|
107
|
+
} catch (error) {
|
|
108
|
+
try {
|
|
109
|
+
await created.close();
|
|
110
|
+
} catch (closeError) {
|
|
111
|
+
throw new AggregateError(
|
|
112
|
+
[error, closeError],
|
|
113
|
+
'PGlite bootstrap failed and cleanup also failed.',
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
throw error;
|
|
117
|
+
}
|
|
100
118
|
return created;
|
|
101
119
|
})();
|
|
102
120
|
return databasePromise;
|