pqb 0.48.6 → 0.49.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/dist/index.mjs CHANGED
@@ -3000,7 +3000,12 @@ const runAfterCommit = async (afterCommit, result) => {
3000
3000
  const applyBatchTransforms = (q, batches) => {
3001
3001
  if (q.transform) {
3002
3002
  for (const item of batches) {
3003
- item.parent[item.key] = item.data === null ? void 0 : applyTransforms(q, q.returnType, q.transform, item.data);
3003
+ item.parent[item.key] = applyTransforms(
3004
+ q,
3005
+ q.returnType,
3006
+ q.transform,
3007
+ item.data
3008
+ );
3004
3009
  }
3005
3010
  }
3006
3011
  };
@@ -3782,8 +3787,9 @@ const addParserForSelectItem = (q, as, key, arg, joinQuery) => {
3782
3787
  const { parsers } = query;
3783
3788
  if (parsers) {
3784
3789
  if (returnType === "one") {
3785
- for (const { data } of batches) {
3786
- if (data) parseRecord(parsers, data);
3790
+ for (const batch of batches) {
3791
+ if (batch.data) parseRecord(parsers, batch.data);
3792
+ else batch.data = void 0;
3787
3793
  }
3788
3794
  } else {
3789
3795
  for (const { data } of batches) {
@@ -3791,7 +3797,11 @@ const addParserForSelectItem = (q, as, key, arg, joinQuery) => {
3791
3797
  parseRecord(parsers, data);
3792
3798
  }
3793
3799
  }
3794
- } else if (returnType !== "one") {
3800
+ } else if (returnType === "one") {
3801
+ for (const batch of batches) {
3802
+ if (!batch.data) batch.data = void 0;
3803
+ }
3804
+ } else {
3795
3805
  for (const { data } of batches) {
3796
3806
  if (!data) throw new NotFoundError(arg);
3797
3807
  }
@@ -4064,7 +4074,16 @@ const handleComputed = (q, computeds, column) => {
4064
4074
  };
4065
4075
  const getShapeFromSelect = (q, isSubQuery) => {
4066
4076
  const query = q.q;
4067
- const { select, shape } = query;
4077
+ const { shape } = query;
4078
+ let select;
4079
+ if (query.selectedComputeds) {
4080
+ select = query.select ? [...query.select] : [];
4081
+ for (const key in query.selectedComputeds) {
4082
+ select.push(...query.selectedComputeds[key].deps);
4083
+ }
4084
+ } else {
4085
+ select = query.select;
4086
+ }
4068
4087
  let result;
4069
4088
  if (!select) {
4070
4089
  if (isSubQuery) {
@@ -4123,18 +4142,33 @@ const addColumnToShapeFromSelect = (q, arg, shape, query, result, isSubQuery, ke
4123
4142
  result[key || column] = shape[column];
4124
4143
  } else {
4125
4144
  const it = query.joinedShapes?.[table]?.[column];
4126
- if (it) result[key || column] = maybeUnNameColumn(it, isSubQuery);
4145
+ if (it)
4146
+ result[key || column] = mapSubSelectColumn(
4147
+ it,
4148
+ isSubQuery
4149
+ );
4127
4150
  }
4128
4151
  } else if (arg === "*") {
4129
4152
  for (const key2 in shape) {
4130
- result[key2] = maybeUnNameColumn(shape[key2], isSubQuery);
4153
+ result[key2] = mapSubSelectColumn(
4154
+ shape[key2],
4155
+ isSubQuery
4156
+ );
4131
4157
  }
4132
4158
  } else {
4133
- result[key || arg] = maybeUnNameColumn(shape[arg], isSubQuery);
4159
+ result[key || arg] = mapSubSelectColumn(
4160
+ shape[arg],
4161
+ isSubQuery
4162
+ );
4134
4163
  }
4135
4164
  };
4136
- const maybeUnNameColumn = (column, isSubQuery) => {
4137
- return isSubQuery && column?.data.name ? setColumnData(column, "name", void 0) : column;
4165
+ const mapSubSelectColumn = (column, isSubQuery) => {
4166
+ if (!isSubQuery || !column || !column.data.name && !column.data.explicitSelect) {
4167
+ return column;
4168
+ }
4169
+ const cloned = Object.create(column);
4170
+ cloned.data = { ...column.data, name: void 0, explicitSelect: void 0 };
4171
+ return cloned;
4138
4172
  };
4139
4173
  function _querySelect(q, args) {
4140
4174
  var _a;