@volter/world-runtime 3.0.47 → 3.0.49

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.
@@ -2,6 +2,11 @@ export interface InfraService {
2
2
  kind: string;
3
3
  hostPort: number;
4
4
  replicaSet?: string;
5
+ postgres?: {
6
+ user: string;
7
+ database: string;
8
+ password?: string;
9
+ };
5
10
  }
6
11
  /** Read the generated definition's loopback port mappings. MongoDB may explicitly request
7
12
  * one replica-set member through its Compose-compatible command; other mongod options are refused. */
@@ -44,7 +44,20 @@ export function parseInfraDefinition(text) {
44
44
  });
45
45
  if (ports.length !== 1)
46
46
  throw new Error(`managed infrastructure ${kind} needs exactly one declared loopback port`);
47
- services.push({ kind, hostPort: ports[0], ...(replicaSet ? { replicaSet } : {}) });
47
+ let postgres;
48
+ if (kind === 'postgres') {
49
+ const environment = declared.environment ?? {};
50
+ const user = environment.POSTGRES_USER ?? 'postgres';
51
+ const database = environment.POSTGRES_DB ?? user;
52
+ const password = environment.POSTGRES_PASSWORD;
53
+ if ([user, database, password].some(value => value !== undefined && (typeof value !== 'string' || !value || /[\r\n\0]|\$\{/.test(value)))) {
54
+ throw new Error('World-managed PGlite requires literal POSTGRES_USER, POSTGRES_DB and POSTGRES_PASSWORD');
55
+ }
56
+ if ([user, database].some(value => Buffer.byteLength(value, 'utf8') > 63))
57
+ throw new Error('World-managed PGlite identifiers must fit PostgreSQL\'s 63-byte name limit');
58
+ postgres = { user: user, database: database, ...(password !== undefined ? { password: password } : {}) };
59
+ }
60
+ services.push({ kind, hostPort: ports[0], ...(replicaSet ? { replicaSet } : {}), ...(postgres ? { postgres } : {}) });
48
61
  }
49
62
  return services;
50
63
  }
@@ -160,6 +173,8 @@ export async function pgliteUp(services, dataDir, launch = {}) {
160
173
  }
161
174
  const name = CONTAINERLESS[service.kind] ?? `pglite-${service.kind}`;
162
175
  const serviceData = join(dataDir, containerlessDataDirectory(service.kind) ?? `${name}-data`);
176
+ if (service.kind === 'postgres' && !service.postgres?.password)
177
+ throw new Error('World-managed PGlite requires a literal POSTGRES_PASSWORD; declare a throwaway World credential');
163
178
  const log = join(dataDir, `${name}.log`);
164
179
  if (await listening(service.hostPort)) {
165
180
  throw new Error(`${name} cannot serve port ${service.hostPort}: another process is already listening on it`);
@@ -177,7 +192,8 @@ export async function pgliteUp(services, dataDir, launch = {}) {
177
192
  const logFd = openSync(log, 'a');
178
193
  const child = spawn(command, args, {
179
194
  windowsHide: true,
180
- env,
195
+ env: service.postgres ? { ...env, VOLTER_WORLD_PGLITE_USER: service.postgres.user,
196
+ VOLTER_WORLD_PGLITE_DATABASE: service.postgres.database, VOLTER_WORLD_PGLITE_PASSWORD: service.postgres.password } : env,
181
197
  detached: true,
182
198
  stdio: ['ignore', logFd, logFd],
183
199
  });