pqb 0.41.1 → 0.41.3

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/dist/index.mjs CHANGED
@@ -4316,172 +4316,175 @@ const addParsersForSelectJoined = (q, arg, as = arg) => {
4316
4316
  );
4317
4317
  }
4318
4318
  };
4319
- const addParserForSelectItem = (q, as, key, arg) => {
4320
- var _a, _b, _c, _d;
4319
+ const addParserForSelectItem = (q, as, key, arg, joinQuery) => {
4320
+ var _a, _b, _c, _d, _e;
4321
4321
  if (typeof arg === "object" || typeof arg === "function") {
4322
- if (isExpression(arg)) {
4323
- addParserForRawExpression(q, key, arg);
4324
- } else {
4325
- const { q: query } = arg;
4326
- if (query.batchParsers) {
4327
- const batchParsers = (_b = (_a = q.q).batchParsers) != null ? _b : _a.batchParsers = [];
4328
- for (const bp of query.batchParsers) {
4329
- batchParsers.push({ path: [key, ...bp.path], fn: bp.fn });
4330
- }
4331
- }
4332
- if (query.hookSelect || query.parsers || query.transform) {
4333
- const batchParsers = (_d = (_c = q.q).batchParsers) != null ? _d : _c.batchParsers = [];
4334
- batchParsers.push({
4335
- path: [key],
4336
- fn: (path, queryResult) => {
4337
- var _a2, _b2, _c2;
4338
- const { rows } = queryResult;
4339
- const originalReturnType = query.returnType || "all";
4340
- let returnType = originalReturnType;
4341
- const { hookSelect } = query;
4342
- const batches = [];
4343
- const last = path.length;
4344
- if (returnType === "value" || returnType === "valueOrThrow") {
4345
- if (hookSelect) {
4346
- batches.push = (item) => {
4347
- if (!(key in item)) {
4348
- returnType = returnType === "value" ? "one" : "oneOrThrow";
4349
- }
4350
- batches.push = Array.prototype.push;
4351
- return batches.push(item);
4352
- };
4353
- }
4322
+ const { q: query } = arg;
4323
+ if (query.batchParsers) {
4324
+ const batchParsers = (_b = (_a = q.q).batchParsers) != null ? _b : _a.batchParsers = [];
4325
+ for (const bp of query.batchParsers) {
4326
+ batchParsers.push({ path: [key, ...bp.path], fn: bp.fn });
4327
+ }
4328
+ }
4329
+ if (query.hookSelect || query.parsers || query.transform) {
4330
+ const batchParsers = (_d = (_c = q.q).batchParsers) != null ? _d : _c.batchParsers = [];
4331
+ batchParsers.push({
4332
+ path: [key],
4333
+ fn: (path, queryResult) => {
4334
+ var _a2, _b2, _c2;
4335
+ const { rows } = queryResult;
4336
+ const originalReturnType = query.returnType || "all";
4337
+ let returnType = originalReturnType;
4338
+ const { hookSelect } = query;
4339
+ const batches = [];
4340
+ const last = path.length;
4341
+ if (returnType === "value" || returnType === "valueOrThrow") {
4342
+ if (hookSelect) {
4343
+ batches.push = (item) => {
4344
+ if (!(key in item)) {
4345
+ returnType = returnType === "value" ? "one" : "oneOrThrow";
4346
+ }
4347
+ batches.push = Array.prototype.push;
4348
+ return batches.push(item);
4349
+ };
4354
4350
  }
4355
- collectNestedSelectBatches(batches, rows, path, last);
4356
- switch (returnType) {
4357
- case "all": {
4358
- const { parsers } = query;
4359
- if (parsers) {
4360
- for (const { data } of batches) {
4361
- for (const one of data) {
4362
- parseRecord(parsers, one);
4363
- }
4351
+ }
4352
+ collectNestedSelectBatches(batches, rows, path, last);
4353
+ switch (returnType) {
4354
+ case "all": {
4355
+ const { parsers } = query;
4356
+ if (parsers) {
4357
+ for (const { data } of batches) {
4358
+ for (const one of data) {
4359
+ parseRecord(parsers, one);
4364
4360
  }
4365
4361
  }
4366
- break;
4367
4362
  }
4368
- case "one":
4369
- case "oneOrThrow": {
4370
- const { parsers } = query;
4371
- if (parsers) {
4372
- if (returnType === "one") {
4373
- for (const { data } of batches) {
4374
- if (data)
4375
- parseRecord(parsers, data);
4376
- }
4377
- } else {
4378
- for (const { data } of batches) {
4379
- if (!data)
4380
- throw new NotFoundError(arg);
4363
+ break;
4364
+ }
4365
+ case "one":
4366
+ case "oneOrThrow": {
4367
+ const { parsers } = query;
4368
+ if (parsers) {
4369
+ if (returnType === "one") {
4370
+ for (const { data } of batches) {
4371
+ if (data)
4381
4372
  parseRecord(parsers, data);
4382
- }
4383
4373
  }
4384
- } else if (returnType !== "one") {
4374
+ } else {
4385
4375
  for (const { data } of batches) {
4386
4376
  if (!data)
4387
4377
  throw new NotFoundError(arg);
4378
+ parseRecord(parsers, data);
4388
4379
  }
4389
4380
  }
4390
- if (hookSelect) {
4391
- for (const batch of batches) {
4392
- batch.data = [batch.data];
4393
- }
4381
+ } else if (returnType !== "one") {
4382
+ for (const { data } of batches) {
4383
+ if (!data)
4384
+ throw new NotFoundError(arg);
4394
4385
  }
4395
- break;
4396
4386
  }
4397
- case "pluck": {
4398
- const parse = (_a2 = query.parsers) == null ? void 0 : _a2.pluck;
4399
- if (parse) {
4400
- for (const { data } of batches) {
4401
- for (let i = 0; i < data.length; i++) {
4402
- data[i] = parse(data[i]);
4403
- }
4387
+ if (hookSelect) {
4388
+ for (const batch of batches) {
4389
+ batch.data = [batch.data];
4390
+ }
4391
+ }
4392
+ break;
4393
+ }
4394
+ case "pluck": {
4395
+ const parse = (_a2 = query.parsers) == null ? void 0 : _a2.pluck;
4396
+ if (parse) {
4397
+ for (const { data } of batches) {
4398
+ for (let i = 0; i < data.length; i++) {
4399
+ data[i] = parse(data[i]);
4404
4400
  }
4405
4401
  }
4406
- break;
4407
4402
  }
4408
- case "value":
4409
- case "valueOrThrow": {
4410
- const parse = (_b2 = query.parsers) == null ? void 0 : _b2[getValueKey];
4411
- if (parse) {
4412
- if (returnType === "value") {
4413
- for (const item of batches) {
4414
- item.parent[item.key] = item.data = item.data === void 0 ? arg.q.notFoundDefault : parse(item.data);
4415
- }
4416
- } else {
4417
- for (const item of batches) {
4418
- if (item.data === void 0)
4419
- throw new NotFoundError(arg);
4420
- item.parent[item.key] = item.data = parse(item.data);
4421
- }
4403
+ break;
4404
+ }
4405
+ case "value":
4406
+ case "valueOrThrow": {
4407
+ const parse = (_b2 = query.parsers) == null ? void 0 : _b2[getValueKey];
4408
+ if (parse) {
4409
+ if (returnType === "value") {
4410
+ for (const item of batches) {
4411
+ item.parent[item.key] = item.data = item.data === void 0 ? query.notFoundDefault : parse(item.data);
4422
4412
  }
4423
- } else if (returnType !== "value") {
4424
- for (const { data } of batches) {
4425
- if (data === void 0)
4413
+ } else {
4414
+ for (const item of batches) {
4415
+ if (item.data === void 0)
4426
4416
  throw new NotFoundError(arg);
4417
+ item.parent[item.key] = item.data = parse(item.data);
4427
4418
  }
4428
4419
  }
4429
- if (hookSelect) {
4430
- for (const batch of batches) {
4431
- batch.data = [batch.data];
4432
- }
4420
+ } else if (returnType !== "value") {
4421
+ for (const { data } of batches) {
4422
+ if (data === void 0)
4423
+ throw new NotFoundError(arg);
4433
4424
  }
4434
- break;
4435
4425
  }
4436
- }
4437
- if (hookSelect) {
4438
- let tempColumns;
4439
- let renames;
4440
- for (const column of hookSelect.keys()) {
4441
- const as2 = hookSelect.get(column).as;
4442
- if (as2)
4443
- (renames != null ? renames : renames = {})[column] = as2;
4444
- (_c2 = tempColumns != null ? tempColumns : tempColumns = /* @__PURE__ */ new Set()) == null ? void 0 : _c2.add(as2 || column);
4426
+ if (hookSelect) {
4427
+ for (const batch of batches) {
4428
+ batch.data = [batch.data];
4429
+ }
4445
4430
  }
4446
- if (renames) {
4447
- for (const { data } of batches) {
4448
- for (const record of data) {
4449
- if (record) {
4450
- for (const a in renames) {
4451
- const value = record[renames[a]];
4452
- record[renames[a]] = record[a];
4453
- record[a] = value;
4454
- }
4431
+ break;
4432
+ }
4433
+ }
4434
+ if (hookSelect) {
4435
+ let tempColumns;
4436
+ let renames;
4437
+ for (const column of hookSelect.keys()) {
4438
+ const as2 = hookSelect.get(column).as;
4439
+ if (as2)
4440
+ (renames != null ? renames : renames = {})[column] = as2;
4441
+ (_c2 = tempColumns != null ? tempColumns : tempColumns = /* @__PURE__ */ new Set()) == null ? void 0 : _c2.add(as2 || column);
4442
+ }
4443
+ if (renames) {
4444
+ for (const { data } of batches) {
4445
+ for (const record of data) {
4446
+ if (record) {
4447
+ for (const a in renames) {
4448
+ const value = record[renames[a]];
4449
+ record[renames[a]] = record[a];
4450
+ record[a] = value;
4455
4451
  }
4456
4452
  }
4457
4453
  }
4458
4454
  }
4459
- if (query.selectedComputeds) {
4460
- const maybePromise = processComputedBatches(
4461
- query,
4462
- batches,
4463
- originalReturnType,
4464
- returnType,
4465
- tempColumns,
4466
- renames,
4467
- key
4468
- );
4469
- if (maybePromise)
4470
- return maybePromise;
4471
- }
4472
- finalizeNestedHookSelect(
4455
+ }
4456
+ if (query.selectedComputeds) {
4457
+ const maybePromise = processComputedBatches(
4458
+ query,
4473
4459
  batches,
4474
4460
  originalReturnType,
4461
+ returnType,
4475
4462
  tempColumns,
4476
4463
  renames,
4477
4464
  key
4478
4465
  );
4466
+ if (maybePromise)
4467
+ return maybePromise;
4479
4468
  }
4480
- applyBatchTransforms(query, batches);
4481
- return;
4469
+ finalizeNestedHookSelect(
4470
+ batches,
4471
+ originalReturnType,
4472
+ tempColumns,
4473
+ renames,
4474
+ key
4475
+ );
4482
4476
  }
4483
- });
4484
- }
4477
+ applyBatchTransforms(query, batches);
4478
+ return;
4479
+ }
4480
+ });
4481
+ }
4482
+ if (!joinQuery && ((_e = arg.q) == null ? void 0 : _e.subQuery) && arg.q.expr) {
4483
+ arg = arg.q.expr;
4484
+ }
4485
+ if (isExpression(arg)) {
4486
+ addParserForRawExpression(q, key, arg);
4487
+ return arg;
4485
4488
  }
4486
4489
  return arg;
4487
4490
  }
@@ -4516,7 +4519,7 @@ const collectNestedSelectBatches = (batches, rows, path, last) => {
4516
4519
  };
4517
4520
  const emptyArrSQL = new RawSQL("'[]'");
4518
4521
  const processSelectArg = (q, as, arg, columnAs) => {
4519
- var _a, _b;
4522
+ var _a;
4520
4523
  if (typeof arg === "string") {
4521
4524
  return setParserForSelectedString(q, arg, as, columnAs);
4522
4525
  }
@@ -4524,13 +4527,16 @@ const processSelectArg = (q, as, arg, columnAs) => {
4524
4527
  let aliases;
4525
4528
  for (const key in arg) {
4526
4529
  let value = arg[key];
4530
+ let joinQuery;
4527
4531
  if (typeof value === "function") {
4528
4532
  value = resolveSubQueryCallback(q, value);
4529
4533
  if (isQueryNone(value)) {
4530
4534
  if (value.q.innerJoinLateral) {
4531
4535
  return false;
4532
4536
  }
4533
- } else if (!isExpression(value) && value.joinQuery) {
4537
+ }
4538
+ if (!isExpression(value) && value.joinQuery) {
4539
+ joinQuery = true;
4534
4540
  value = value.joinQuery(value, q);
4535
4541
  let query;
4536
4542
  const returnType = value.q.returnType;
@@ -4568,8 +4574,6 @@ const processSelectArg = (q, as, arg, columnAs) => {
4568
4574
  (q2) => q2,
4569
4575
  key
4570
4576
  );
4571
- } else if (((_b = value.q) == null ? void 0 : _b.subQuery) && value.q.expr) {
4572
- value = value.q.expr;
4573
4577
  }
4574
4578
  }
4575
4579
  if (aliases)
@@ -4578,7 +4582,8 @@ const processSelectArg = (q, as, arg, columnAs) => {
4578
4582
  q,
4579
4583
  as,
4580
4584
  key,
4581
- value
4585
+ value,
4586
+ joinQuery
4582
4587
  );
4583
4588
  }
4584
4589
  return { selectAs };