@lunora/do 1.0.0-alpha.4 → 1.0.0-alpha.5

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.
@@ -1,3 +1,6 @@
1
+ import { applySelect } from './applySelect-BvZdFUBT.mjs';
2
+
3
+ const projectChildren = (documents, nested) => nested.select ? applySelect(documents, nested.select, nested.with) : documents;
1
4
  const distinctValues = (rows, field) => {
2
5
  const seen = /* @__PURE__ */ new Set();
3
6
  for (const row of rows) {
@@ -44,7 +47,8 @@ const resolveWith = async (options) => {
44
47
  byReference.set(child[relation.references], child);
45
48
  }
46
49
  for (const parent of parents) {
47
- parent[name] = byReference.get(parent[relation.field]) ?? null;
50
+ const child = byReference.get(parent[relation.field]);
51
+ parent[name] = child ? projectChildren([child], nested)[0] ?? null : null;
48
52
  }
49
53
  };
50
54
  const loadMany = async (name, relation, nested) => {
@@ -77,7 +81,7 @@ const resolveWith = async (options) => {
77
81
  const cap = typeof nested.limit === "number" ? Math.max(0, Math.floor(nested.limit)) : void 0;
78
82
  for (const parent of parents) {
79
83
  const group = groups.get(parent[relation.references]) ?? [];
80
- parent[name] = cap === void 0 ? group : group.slice(0, cap);
84
+ parent[name] = projectChildren(cap === void 0 ? group : group.slice(0, cap), nested);
81
85
  }
82
86
  };
83
87
  const resolveCounts = async (countInput) => {
@@ -80,5 +80,22 @@ const buildSeekBeforeWhere = (keys, cursorValues) => {
80
80
  }
81
81
  return { OR: branches };
82
82
  };
83
+ const SELECT_SYSTEM_FIELDS = ["_id", "_creationTime"];
84
+ const applySelect = (page, select, withInput) => {
85
+ if (!select) {
86
+ return page;
87
+ }
88
+ const keep = /* @__PURE__ */ new Set([...select, ...SELECT_SYSTEM_FIELDS, ...withInput ? Object.keys(withInput) : []]);
89
+ return page.map((document) => {
90
+ const projected = {};
91
+ for (const key of keep) {
92
+ if (key in document) {
93
+ projected[key] = document[key];
94
+ }
95
+ }
96
+ return projected;
97
+ });
98
+ };
99
+ const softDeleteScope = (softDeleteMode, includeDeleted) => softDeleteMode && includeDeleted !== true ? { [softDeleteMode.field]: { isNull: true } } : void 0;
83
100
 
84
- export { buildSeekBeforeWhere, buildSeekWhere, decodeCursor, encodeCursor, normalizeOrderKeys };
101
+ export { applySelect, buildSeekBeforeWhere, buildSeekWhere, decodeCursor, encodeCursor, normalizeOrderKeys, softDeleteScope };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/do",
3
- "version": "1.0.0-alpha.4",
3
+ "version": "1.0.0-alpha.5",
4
4
  "description": "Lunora Durable Objects: ShardDO (SQLite, OCC, hibernated WebSocket subscriptions) and SessionDO",
5
5
  "keywords": [
6
6
  "cloudflare",