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