@dyrected/core 2.5.9 → 2.5.11

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.cjs CHANGED
@@ -1092,6 +1092,49 @@ var import_hono = require("hono");
1092
1092
  var import_cors = require("hono/cors");
1093
1093
  var import_request_id = require("hono/request-id");
1094
1094
 
1095
+ // src/services/defaults.service.ts
1096
+ var DefaultsService = class {
1097
+ /**
1098
+ * Recursively apply default values to a data object based on field definitions.
1099
+ */
1100
+ static apply(fields, data = {}) {
1101
+ const result = { ...data || {} };
1102
+ fields.forEach((field) => {
1103
+ if (field.type === "join") return;
1104
+ if (field.type === "row" && field.fields) {
1105
+ Object.assign(result, this.apply(field.fields, data));
1106
+ return;
1107
+ }
1108
+ if (!field.name) return;
1109
+ let value = result[field.name];
1110
+ if ((value === void 0 || value === null) && field.renameTo) {
1111
+ const legacyValue = result[field.renameTo];
1112
+ if (legacyValue !== void 0 && legacyValue !== null) {
1113
+ value = legacyValue;
1114
+ result[field.name] = legacyValue;
1115
+ }
1116
+ }
1117
+ if (value === void 0 || value === null) {
1118
+ if (field.defaultValue !== void 0) {
1119
+ result[field.name] = field.defaultValue;
1120
+ } else {
1121
+ if (field.type === "boolean") result[field.name] = false;
1122
+ else if (field.type === "array") result[field.name] = [];
1123
+ else if (field.type === "multiSelect") result[field.name] = [];
1124
+ else if (field.type === "object") {
1125
+ result[field.name] = this.apply(field.fields || [], {});
1126
+ }
1127
+ }
1128
+ } else if (field.type === "object" && field.fields) {
1129
+ result[field.name] = this.apply(field.fields, value);
1130
+ } else if (field.type === "array" && field.fields && Array.isArray(value)) {
1131
+ result[field.name] = value.map((item) => this.apply(field.fields, item));
1132
+ }
1133
+ });
1134
+ return result;
1135
+ }
1136
+ };
1137
+
1095
1138
  // src/services/population.service.ts
1096
1139
  var PopulationService = class {
1097
1140
  db;
@@ -1104,7 +1147,7 @@ var PopulationService = class {
1104
1147
  * Recursively populate relationship fields in a document or array of documents.
1105
1148
  */
1106
1149
  async populate(args) {
1107
- const { data, fields, currentDepth, maxDepth } = args;
1150
+ const { data, fields, currentDepth = 0, maxDepth = 10 } = args;
1108
1151
  if (currentDepth >= maxDepth || !data) {
1109
1152
  return data;
1110
1153
  }
@@ -1133,8 +1176,9 @@ var PopulationService = class {
1133
1176
  doc = await this.db.findOne({ collection: field.relationTo, id });
1134
1177
  }
1135
1178
  if (!doc || typeof doc !== "object") return id;
1179
+ const docWithDefaults = DefaultsService.apply(relatedCollection.fields, doc);
1136
1180
  return this.populate({
1137
- data: doc,
1181
+ data: docWithDefaults,
1138
1182
  fields: relatedCollection.fields,
1139
1183
  currentDepth: currentDepth + 1,
1140
1184
  maxDepth
@@ -1147,12 +1191,35 @@ var PopulationService = class {
1147
1191
  doc = await this.db.findOne({ collection: field.relationTo, id: value });
1148
1192
  }
1149
1193
  if (doc && typeof doc === "object") {
1194
+ const docWithDefaults = DefaultsService.apply(relatedCollection.fields, doc);
1150
1195
  populatedDoc[field.name] = await this.populate({
1151
- data: doc,
1196
+ data: docWithDefaults,
1197
+ fields: relatedCollection.fields,
1198
+ currentDepth: currentDepth + 1,
1199
+ maxDepth
1200
+ });
1201
+ }
1202
+ }
1203
+ }
1204
+ if (field.type === "url" && value && typeof value === "object" && value.type === "internal" && value.relationTo && value.value) {
1205
+ const relatedCollection = this.collections.find((c) => c.slug === value.relationTo);
1206
+ if (relatedCollection) {
1207
+ const doc = await this.db.findOne({ collection: value.relationTo, id: value.value });
1208
+ if (doc && typeof doc === "object") {
1209
+ const docWithDefaults = DefaultsService.apply(relatedCollection.fields, doc);
1210
+ const populatedDocValue = await this.populate({
1211
+ data: docWithDefaults,
1152
1212
  fields: relatedCollection.fields,
1153
1213
  currentDepth: currentDepth + 1,
1154
1214
  maxDepth
1155
1215
  });
1216
+ const identifier = docWithDefaults.slug || docWithDefaults.id;
1217
+ const resolvedUrl = `/collections/${value.relationTo}/${identifier}`;
1218
+ populatedDoc[field.name] = {
1219
+ ...value,
1220
+ url: resolvedUrl,
1221
+ doc: populatedDocValue
1222
+ };
1156
1223
  }
1157
1224
  }
1158
1225
  }
@@ -1200,49 +1267,6 @@ var PopulationService = class {
1200
1267
  }
1201
1268
  };
1202
1269
 
1203
- // src/services/defaults.service.ts
1204
- var DefaultsService = class {
1205
- /**
1206
- * Recursively apply default values to a data object based on field definitions.
1207
- */
1208
- static apply(fields, data = {}) {
1209
- const result = { ...data || {} };
1210
- fields.forEach((field) => {
1211
- if (field.type === "join") return;
1212
- if (field.type === "row" && field.fields) {
1213
- Object.assign(result, this.apply(field.fields, data));
1214
- return;
1215
- }
1216
- if (!field.name) return;
1217
- let value = result[field.name];
1218
- if ((value === void 0 || value === null) && field.renameTo) {
1219
- const legacyValue = result[field.renameTo];
1220
- if (legacyValue !== void 0 && legacyValue !== null) {
1221
- value = legacyValue;
1222
- result[field.name] = legacyValue;
1223
- }
1224
- }
1225
- if (value === void 0 || value === null) {
1226
- if (field.defaultValue !== void 0) {
1227
- result[field.name] = field.defaultValue;
1228
- } else {
1229
- if (field.type === "boolean") result[field.name] = false;
1230
- else if (field.type === "array") result[field.name] = [];
1231
- else if (field.type === "multiSelect") result[field.name] = [];
1232
- else if (field.type === "object") {
1233
- result[field.name] = this.apply(field.fields || [], {});
1234
- }
1235
- }
1236
- } else if (field.type === "object" && field.fields) {
1237
- result[field.name] = this.apply(field.fields, value);
1238
- } else if (field.type === "array" && field.fields && Array.isArray(value)) {
1239
- result[field.name] = value.map((item) => this.apply(field.fields, item));
1240
- }
1241
- });
1242
- return result;
1243
- }
1244
- };
1245
-
1246
1270
  // src/services/audit.service.ts
1247
1271
  var AuditService = class {
1248
1272
  /**
@@ -1283,7 +1307,7 @@ var CollectionController = class {
1283
1307
  if (!db) return c.json({ message: "Database not configured" }, 500);
1284
1308
  const limit = Number(c.req.query("limit")) || 10;
1285
1309
  const page = Number(c.req.query("page")) || 1;
1286
- const depth = c.req.query("depth") !== void 0 ? Number(c.req.query("depth")) : 1;
1310
+ const depth = c.req.query("depth") !== void 0 ? Number(c.req.query("depth")) : 2;
1287
1311
  const sort = c.req.query("sort") || void 0;
1288
1312
  let where = void 0;
1289
1313
  const whereRaw = c.req.query("where");
@@ -1325,7 +1349,7 @@ var CollectionController = class {
1325
1349
  const db = config.db;
1326
1350
  if (!db) return c.json({ message: "Database not configured" }, 500);
1327
1351
  const id = c.req.param("id");
1328
- const depth = c.req.query("depth") !== void 0 ? Number(c.req.query("depth")) : 1;
1352
+ const depth = c.req.query("depth") !== void 0 ? Number(c.req.query("depth")) : 10;
1329
1353
  if (!id) return c.json({ message: "Missing ID" }, 400);
1330
1354
  const doc = await db.findOne({ collection: this.collection.slug, id });
1331
1355
  if (!doc) return c.json({ message: "Not Found" }, 404);
@@ -1546,7 +1570,7 @@ var GlobalController = class {
1546
1570
  const config = c.get("config");
1547
1571
  const db = config.db;
1548
1572
  if (!db) return c.json({ message: "Database not configured" }, 500);
1549
- const depth = c.req.query("depth") !== void 0 ? Number(c.req.query("depth")) : 1;
1573
+ const depth = c.req.query("depth") !== void 0 ? Number(c.req.query("depth")) : 10;
1550
1574
  let data = await db.getGlobal({ slug: this.global.slug });
1551
1575
  const isEmpty = !data || Object.keys(data).length === 0;
1552
1576
  if (isEmpty && this.global.initialData) {
@@ -1560,7 +1584,7 @@ var GlobalController = class {
1560
1584
  const populatedData = await populationService.populate({
1561
1585
  data: dataWithDefaults,
1562
1586
  fields: this.global.fields,
1563
- currentDepth: 1,
1587
+ currentDepth: 0,
1564
1588
  maxDepth: depth
1565
1589
  });
1566
1590
  return c.json(populatedData);
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { D as DyrectedConfig, C as CollectionConfig, G as GlobalConfig } from './app-DZt5nslu.cjs';
2
- export { A as AccessFunction, a as AdminConfig, B as Block, b as DatabaseAdapter, c as DyrectedContext, F as Field, d as FieldHook, e as FieldType, f as FileData, H as HookFunction, I as ImageService, P as PaginatedResult, S as StorageAdapter, U as UploadConfig, g as createDyrectedApp } from './app-DZt5nslu.cjs';
1
+ import { D as DyrectedConfig, C as CollectionConfig, G as GlobalConfig } from './app-Dk3SzV1a.cjs';
2
+ export { A as AccessFunction, a as AdminConfig, B as Block, b as DatabaseAdapter, c as DyrectedContext, F as Field, d as FieldHook, e as FieldType, f as FileData, H as HookFunction, I as ImageService, P as PaginatedResult, S as StorageAdapter, U as UploadConfig, g as createDyrectedApp } from './app-Dk3SzV1a.cjs';
3
3
  import 'hono/types';
4
4
  import 'hono';
5
5
 
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { D as DyrectedConfig, C as CollectionConfig, G as GlobalConfig } from './app-DZt5nslu.js';
2
- export { A as AccessFunction, a as AdminConfig, B as Block, b as DatabaseAdapter, c as DyrectedContext, F as Field, d as FieldHook, e as FieldType, f as FileData, H as HookFunction, I as ImageService, P as PaginatedResult, S as StorageAdapter, U as UploadConfig, g as createDyrectedApp } from './app-DZt5nslu.js';
1
+ import { D as DyrectedConfig, C as CollectionConfig, G as GlobalConfig } from './app-Dk3SzV1a.js';
2
+ export { A as AccessFunction, a as AdminConfig, B as Block, b as DatabaseAdapter, c as DyrectedContext, F as Field, d as FieldHook, e as FieldType, f as FileData, H as HookFunction, I as ImageService, P as PaginatedResult, S as StorageAdapter, U as UploadConfig, g as createDyrectedApp } from './app-Dk3SzV1a.js';
3
3
  import 'hono/types';
4
4
  import 'hono';
5
5
 
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  createDyrectedApp,
3
3
  normalizeConfig
4
- } from "./chunk-TIJHR54M.js";
4
+ } from "./chunk-3VUH2MNW.js";
5
5
 
6
6
  // src/utils/setup-prompt.ts
7
7
  function buildEnvironmentSection(frameworkLabel, isSelfHosted, config) {
package/dist/server.cjs CHANGED
@@ -45,6 +45,49 @@ var import_hono = require("hono");
45
45
  var import_cors = require("hono/cors");
46
46
  var import_request_id = require("hono/request-id");
47
47
 
48
+ // src/services/defaults.service.ts
49
+ var DefaultsService = class {
50
+ /**
51
+ * Recursively apply default values to a data object based on field definitions.
52
+ */
53
+ static apply(fields, data = {}) {
54
+ const result = { ...data || {} };
55
+ fields.forEach((field) => {
56
+ if (field.type === "join") return;
57
+ if (field.type === "row" && field.fields) {
58
+ Object.assign(result, this.apply(field.fields, data));
59
+ return;
60
+ }
61
+ if (!field.name) return;
62
+ let value = result[field.name];
63
+ if ((value === void 0 || value === null) && field.renameTo) {
64
+ const legacyValue = result[field.renameTo];
65
+ if (legacyValue !== void 0 && legacyValue !== null) {
66
+ value = legacyValue;
67
+ result[field.name] = legacyValue;
68
+ }
69
+ }
70
+ if (value === void 0 || value === null) {
71
+ if (field.defaultValue !== void 0) {
72
+ result[field.name] = field.defaultValue;
73
+ } else {
74
+ if (field.type === "boolean") result[field.name] = false;
75
+ else if (field.type === "array") result[field.name] = [];
76
+ else if (field.type === "multiSelect") result[field.name] = [];
77
+ else if (field.type === "object") {
78
+ result[field.name] = this.apply(field.fields || [], {});
79
+ }
80
+ }
81
+ } else if (field.type === "object" && field.fields) {
82
+ result[field.name] = this.apply(field.fields, value);
83
+ } else if (field.type === "array" && field.fields && Array.isArray(value)) {
84
+ result[field.name] = value.map((item) => this.apply(field.fields, item));
85
+ }
86
+ });
87
+ return result;
88
+ }
89
+ };
90
+
48
91
  // src/services/population.service.ts
49
92
  var PopulationService = class {
50
93
  db;
@@ -57,7 +100,7 @@ var PopulationService = class {
57
100
  * Recursively populate relationship fields in a document or array of documents.
58
101
  */
59
102
  async populate(args) {
60
- const { data, fields, currentDepth, maxDepth } = args;
103
+ const { data, fields, currentDepth = 0, maxDepth = 10 } = args;
61
104
  if (currentDepth >= maxDepth || !data) {
62
105
  return data;
63
106
  }
@@ -86,8 +129,9 @@ var PopulationService = class {
86
129
  doc = await this.db.findOne({ collection: field.relationTo, id });
87
130
  }
88
131
  if (!doc || typeof doc !== "object") return id;
132
+ const docWithDefaults = DefaultsService.apply(relatedCollection.fields, doc);
89
133
  return this.populate({
90
- data: doc,
134
+ data: docWithDefaults,
91
135
  fields: relatedCollection.fields,
92
136
  currentDepth: currentDepth + 1,
93
137
  maxDepth
@@ -100,12 +144,35 @@ var PopulationService = class {
100
144
  doc = await this.db.findOne({ collection: field.relationTo, id: value });
101
145
  }
102
146
  if (doc && typeof doc === "object") {
147
+ const docWithDefaults = DefaultsService.apply(relatedCollection.fields, doc);
103
148
  populatedDoc[field.name] = await this.populate({
104
- data: doc,
149
+ data: docWithDefaults,
150
+ fields: relatedCollection.fields,
151
+ currentDepth: currentDepth + 1,
152
+ maxDepth
153
+ });
154
+ }
155
+ }
156
+ }
157
+ if (field.type === "url" && value && typeof value === "object" && value.type === "internal" && value.relationTo && value.value) {
158
+ const relatedCollection = this.collections.find((c) => c.slug === value.relationTo);
159
+ if (relatedCollection) {
160
+ const doc = await this.db.findOne({ collection: value.relationTo, id: value.value });
161
+ if (doc && typeof doc === "object") {
162
+ const docWithDefaults = DefaultsService.apply(relatedCollection.fields, doc);
163
+ const populatedDocValue = await this.populate({
164
+ data: docWithDefaults,
105
165
  fields: relatedCollection.fields,
106
166
  currentDepth: currentDepth + 1,
107
167
  maxDepth
108
168
  });
169
+ const identifier = docWithDefaults.slug || docWithDefaults.id;
170
+ const resolvedUrl = `/collections/${value.relationTo}/${identifier}`;
171
+ populatedDoc[field.name] = {
172
+ ...value,
173
+ url: resolvedUrl,
174
+ doc: populatedDocValue
175
+ };
109
176
  }
110
177
  }
111
178
  }
@@ -153,49 +220,6 @@ var PopulationService = class {
153
220
  }
154
221
  };
155
222
 
156
- // src/services/defaults.service.ts
157
- var DefaultsService = class {
158
- /**
159
- * Recursively apply default values to a data object based on field definitions.
160
- */
161
- static apply(fields, data = {}) {
162
- const result = { ...data || {} };
163
- fields.forEach((field) => {
164
- if (field.type === "join") return;
165
- if (field.type === "row" && field.fields) {
166
- Object.assign(result, this.apply(field.fields, data));
167
- return;
168
- }
169
- if (!field.name) return;
170
- let value = result[field.name];
171
- if ((value === void 0 || value === null) && field.renameTo) {
172
- const legacyValue = result[field.renameTo];
173
- if (legacyValue !== void 0 && legacyValue !== null) {
174
- value = legacyValue;
175
- result[field.name] = legacyValue;
176
- }
177
- }
178
- if (value === void 0 || value === null) {
179
- if (field.defaultValue !== void 0) {
180
- result[field.name] = field.defaultValue;
181
- } else {
182
- if (field.type === "boolean") result[field.name] = false;
183
- else if (field.type === "array") result[field.name] = [];
184
- else if (field.type === "multiSelect") result[field.name] = [];
185
- else if (field.type === "object") {
186
- result[field.name] = this.apply(field.fields || [], {});
187
- }
188
- }
189
- } else if (field.type === "object" && field.fields) {
190
- result[field.name] = this.apply(field.fields, value);
191
- } else if (field.type === "array" && field.fields && Array.isArray(value)) {
192
- result[field.name] = value.map((item) => this.apply(field.fields, item));
193
- }
194
- });
195
- return result;
196
- }
197
- };
198
-
199
223
  // src/services/audit.service.ts
200
224
  var AuditService = class {
201
225
  /**
@@ -236,7 +260,7 @@ var CollectionController = class {
236
260
  if (!db) return c.json({ message: "Database not configured" }, 500);
237
261
  const limit = Number(c.req.query("limit")) || 10;
238
262
  const page = Number(c.req.query("page")) || 1;
239
- const depth = c.req.query("depth") !== void 0 ? Number(c.req.query("depth")) : 1;
263
+ const depth = c.req.query("depth") !== void 0 ? Number(c.req.query("depth")) : 2;
240
264
  const sort = c.req.query("sort") || void 0;
241
265
  let where = void 0;
242
266
  const whereRaw = c.req.query("where");
@@ -278,7 +302,7 @@ var CollectionController = class {
278
302
  const db = config.db;
279
303
  if (!db) return c.json({ message: "Database not configured" }, 500);
280
304
  const id = c.req.param("id");
281
- const depth = c.req.query("depth") !== void 0 ? Number(c.req.query("depth")) : 1;
305
+ const depth = c.req.query("depth") !== void 0 ? Number(c.req.query("depth")) : 10;
282
306
  if (!id) return c.json({ message: "Missing ID" }, 400);
283
307
  const doc = await db.findOne({ collection: this.collection.slug, id });
284
308
  if (!doc) return c.json({ message: "Not Found" }, 404);
@@ -499,7 +523,7 @@ var GlobalController = class {
499
523
  const config = c.get("config");
500
524
  const db = config.db;
501
525
  if (!db) return c.json({ message: "Database not configured" }, 500);
502
- const depth = c.req.query("depth") !== void 0 ? Number(c.req.query("depth")) : 1;
526
+ const depth = c.req.query("depth") !== void 0 ? Number(c.req.query("depth")) : 10;
503
527
  let data = await db.getGlobal({ slug: this.global.slug });
504
528
  const isEmpty = !data || Object.keys(data).length === 0;
505
529
  if (isEmpty && this.global.initialData) {
@@ -513,7 +537,7 @@ var GlobalController = class {
513
537
  const populatedData = await populationService.populate({
514
538
  data: dataWithDefaults,
515
539
  fields: this.global.fields,
516
- currentDepth: 1,
540
+ currentDepth: 0,
517
541
  maxDepth: depth
518
542
  });
519
543
  return c.json(populatedData);
package/dist/server.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { c as DyrectedContext, D as DyrectedConfig, C as CollectionConfig, G as GlobalConfig } from './app-DZt5nslu.cjs';
2
- export { g as createDyrectedApp } from './app-DZt5nslu.cjs';
1
+ import { c as DyrectedContext, D as DyrectedConfig, C as CollectionConfig, G as GlobalConfig } from './app-Dk3SzV1a.cjs';
2
+ export { g as createDyrectedApp } from './app-Dk3SzV1a.cjs';
3
3
  import * as hono from 'hono';
4
4
  import { Hono, Context } from 'hono';
5
5
  import * as hono_utils_http_status from 'hono/utils/http-status';
package/dist/server.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { c as DyrectedContext, D as DyrectedConfig, C as CollectionConfig, G as GlobalConfig } from './app-DZt5nslu.js';
2
- export { g as createDyrectedApp } from './app-DZt5nslu.js';
1
+ import { c as DyrectedContext, D as DyrectedConfig, C as CollectionConfig, G as GlobalConfig } from './app-Dk3SzV1a.js';
2
+ export { g as createDyrectedApp } from './app-Dk3SzV1a.js';
3
3
  import * as hono from 'hono';
4
4
  import { Hono, Context } from 'hono';
5
5
  import * as hono_utils_http_status from 'hono/utils/http-status';
package/dist/server.js CHANGED
@@ -6,7 +6,7 @@ import {
6
6
  PreviewController,
7
7
  createDyrectedApp,
8
8
  registerRoutes
9
- } from "./chunk-TIJHR54M.js";
9
+ } from "./chunk-3VUH2MNW.js";
10
10
  export {
11
11
  AuthController,
12
12
  CollectionController,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dyrected/core",
3
- "version": "2.5.9",
3
+ "version": "2.5.11",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",