@dyrected/sdk 2.5.39 → 2.5.40

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
@@ -196,19 +196,12 @@ var DyrectedClient = class {
196
196
  normalizedArgs.where = JSON.stringify(normalizedArgs.where);
197
197
  }
198
198
  const query = stringifyQuery(normalizedArgs, { addQueryPrefix: true });
199
- const res = await this.request(
200
- `/api/collections/${collection}${query}`
201
- );
199
+ const res = await this.request(`/api/collections/${collection}${query}`);
202
200
  if (res.docs.length === 0 && initialData && initialData.length > 0) {
203
201
  this.request(`/api/collections/${collection}/seed`, {
204
202
  method: "POST",
205
203
  body: JSON.stringify({ data: initialData })
206
- }).catch(
207
- (err) => console.error(
208
- `[dyrected/sdk] Failed to auto-seed collection "${collection}":`,
209
- err
210
- )
211
- );
204
+ }).catch((err) => console.error(`[dyrected/sdk] Failed to auto-seed collection "${collection}":`, err));
212
205
  return {
213
206
  docs: initialData,
214
207
  total: initialData.length,
@@ -227,10 +220,7 @@ var DyrectedClient = class {
227
220
  collection(slug) {
228
221
  return {
229
222
  find: (args) => {
230
- const qb = new QueryBuilder(
231
- slug,
232
- (c, a) => this.find(c, a)
233
- );
223
+ const qb = new QueryBuilder(slug, (c, a) => this.find(c, a));
234
224
  if (args) {
235
225
  if (args.where) qb.where(args.where);
236
226
  if (args.sort) qb.sort(args.sort);
@@ -328,12 +318,7 @@ var DyrectedClient = class {
328
318
  * comment: 'Please add more detail to section 2.',
329
319
  * })
330
320
  */
331
- transition: (id, transitionName, opts) => this.transition(
332
- slug,
333
- id,
334
- transitionName,
335
- opts
336
- ),
321
+ transition: (id, transitionName, opts) => this.transition(slug, id, transitionName, opts),
337
322
  /**
338
323
  * Fetch the workflow history for a single document — every transition that
339
324
  * has ever been performed, newest first.
@@ -366,10 +351,7 @@ var DyrectedClient = class {
366
351
  method: "POST",
367
352
  body: JSON.stringify({ data: [{ id, ...initialData }] })
368
353
  }).catch(
369
- (err2) => console.error(
370
- `[dyrected/sdk] Failed to auto-seed document "${id}" in collection "${collection}":`,
371
- err2
372
- )
354
+ (err2) => console.error(`[dyrected/sdk] Failed to auto-seed document "${id}" in collection "${collection}":`, err2)
373
355
  );
374
356
  return initialData;
375
357
  }
@@ -408,13 +390,10 @@ var DyrectedClient = class {
408
390
  * const updated = await client.transition('posts', postId, 'publish')
409
391
  */
410
392
  async transition(collection, id, transitionName, opts = {}) {
411
- return this.request(
412
- `/api/collections/${collection}/${id}/transitions/${encodeURIComponent(transitionName)}`,
413
- {
414
- method: "POST",
415
- body: JSON.stringify(opts)
416
- }
417
- );
393
+ return this.request(`/api/collections/${collection}/${id}/transitions/${encodeURIComponent(transitionName)}`, {
394
+ method: "POST",
395
+ body: JSON.stringify(opts)
396
+ });
418
397
  }
419
398
  /**
420
399
  * Fetch the workflow history for a document.
@@ -427,9 +406,7 @@ var DyrectedClient = class {
427
406
  */
428
407
  async workflowHistory(collection, id, args = {}) {
429
408
  const query = args.limit ? `?limit=${args.limit}` : "";
430
- return this.request(
431
- `/api/collections/${collection}/${id}/workflow-history${query}`
432
- );
409
+ return this.request(`/api/collections/${collection}/${id}/workflow-history${query}`);
433
410
  }
434
411
  async deleteMany(collection, ids) {
435
412
  return this.request(`/api/collections/${collection}/delete-many`, {
@@ -442,16 +419,12 @@ var DyrectedClient = class {
442
419
  const query = stringifyQuery(queryArgs, { addQueryPrefix: true });
443
420
  try {
444
421
  const res = await this.request(`/api/globals/${slug}${query}`);
445
- if ((!res || Object.keys(res).length === 0) && initialData) {
422
+ if ((!res || isFunctionallyEmpty(res)) && !isFunctionallyEmpty(initialData)) {
423
+ console.log("[getGlobal] We are seeding", res);
446
424
  this.request(`/api/globals/${slug}/seed`, {
447
425
  method: "POST",
448
426
  body: JSON.stringify({ data: initialData })
449
- }).catch(
450
- (err) => console.error(
451
- `[dyrected/sdk] Failed to auto-seed global "${slug}":`,
452
- err
453
- )
454
- );
427
+ }).catch((err) => console.error(`[dyrected/sdk] Failed to auto-seed global "${slug}":`, err));
455
428
  return initialData;
456
429
  }
457
430
  return res;
@@ -460,12 +433,7 @@ var DyrectedClient = class {
460
433
  this.request(`/api/globals/${slug}/seed`, {
461
434
  method: "POST",
462
435
  body: JSON.stringify({ data: initialData })
463
- }).catch(
464
- (err2) => console.error(
465
- `[dyrected/sdk] Failed to auto-seed global "${slug}":`,
466
- err2
467
- )
468
- );
436
+ }).catch((err2) => console.error(`[dyrected/sdk] Failed to auto-seed global "${slug}":`, err2));
469
437
  return initialData;
470
438
  }
471
439
  throw err;
@@ -533,11 +501,8 @@ var DyrectedClient = class {
533
501
  })
534
502
  );
535
503
  }
536
- throw new DyrectedError(
537
- body.message || `Request failed with status ${res.status}`,
538
- res.status,
539
- body.code
540
- );
504
+ console.log("[DyrectedError]", body, res.status);
505
+ throw new DyrectedError(body.message || `Request failed with status ${res.status}`, res.status, body.code);
541
506
  }
542
507
  return res.json();
543
508
  }
@@ -547,6 +512,19 @@ var DyrectedClient = class {
547
512
  function createClient(config) {
548
513
  return new DyrectedClient(config);
549
514
  }
515
+ function isFunctionallyEmpty(obj) {
516
+ if (obj === null || obj === void 0 || obj === "") return true;
517
+ if (Array.isArray(obj)) {
518
+ if (obj.length === 0) return true;
519
+ return obj.every(isFunctionallyEmpty);
520
+ }
521
+ if (typeof obj === "object") {
522
+ const keys = Object.keys(obj);
523
+ if (keys.length === 0) return true;
524
+ return keys.every((key) => isFunctionallyEmpty(obj[key]));
525
+ }
526
+ return false;
527
+ }
550
528
  // Annotate the CommonJS export names for ESM import in node:
551
529
  0 && (module.exports = {
552
530
  DyrectedClient,
package/dist/index.d.cts CHANGED
@@ -145,19 +145,19 @@ declare class DyrectedClient<TSchema extends BaseSchema = any> {
145
145
  globals: any[];
146
146
  }>;
147
147
  getPreference<T = unknown>(key: string, options?: {
148
- scope?: 'personal' | 'global';
148
+ scope?: "personal" | "global";
149
149
  }): Promise<{
150
150
  key: string;
151
151
  value: T | null;
152
152
  }>;
153
153
  setPreference<T = unknown>(key: string, value: T, options?: {
154
- scope?: 'personal' | 'global';
154
+ scope?: "personal" | "global";
155
155
  }): Promise<{
156
156
  key: string;
157
157
  value: T;
158
158
  }>;
159
159
  deletePreference(key: string, options?: {
160
- scope?: 'personal' | 'global';
160
+ scope?: "personal" | "global";
161
161
  }): Promise<{
162
162
  success: boolean;
163
163
  }>;
package/dist/index.d.ts CHANGED
@@ -145,19 +145,19 @@ declare class DyrectedClient<TSchema extends BaseSchema = any> {
145
145
  globals: any[];
146
146
  }>;
147
147
  getPreference<T = unknown>(key: string, options?: {
148
- scope?: 'personal' | 'global';
148
+ scope?: "personal" | "global";
149
149
  }): Promise<{
150
150
  key: string;
151
151
  value: T | null;
152
152
  }>;
153
153
  setPreference<T = unknown>(key: string, value: T, options?: {
154
- scope?: 'personal' | 'global';
154
+ scope?: "personal" | "global";
155
155
  }): Promise<{
156
156
  key: string;
157
157
  value: T;
158
158
  }>;
159
159
  deletePreference(key: string, options?: {
160
- scope?: 'personal' | 'global';
160
+ scope?: "personal" | "global";
161
161
  }): Promise<{
162
162
  success: boolean;
163
163
  }>;
package/dist/index.js CHANGED
@@ -168,19 +168,12 @@ var DyrectedClient = class {
168
168
  normalizedArgs.where = JSON.stringify(normalizedArgs.where);
169
169
  }
170
170
  const query = stringifyQuery(normalizedArgs, { addQueryPrefix: true });
171
- const res = await this.request(
172
- `/api/collections/${collection}${query}`
173
- );
171
+ const res = await this.request(`/api/collections/${collection}${query}`);
174
172
  if (res.docs.length === 0 && initialData && initialData.length > 0) {
175
173
  this.request(`/api/collections/${collection}/seed`, {
176
174
  method: "POST",
177
175
  body: JSON.stringify({ data: initialData })
178
- }).catch(
179
- (err) => console.error(
180
- `[dyrected/sdk] Failed to auto-seed collection "${collection}":`,
181
- err
182
- )
183
- );
176
+ }).catch((err) => console.error(`[dyrected/sdk] Failed to auto-seed collection "${collection}":`, err));
184
177
  return {
185
178
  docs: initialData,
186
179
  total: initialData.length,
@@ -199,10 +192,7 @@ var DyrectedClient = class {
199
192
  collection(slug) {
200
193
  return {
201
194
  find: (args) => {
202
- const qb = new QueryBuilder(
203
- slug,
204
- (c, a) => this.find(c, a)
205
- );
195
+ const qb = new QueryBuilder(slug, (c, a) => this.find(c, a));
206
196
  if (args) {
207
197
  if (args.where) qb.where(args.where);
208
198
  if (args.sort) qb.sort(args.sort);
@@ -300,12 +290,7 @@ var DyrectedClient = class {
300
290
  * comment: 'Please add more detail to section 2.',
301
291
  * })
302
292
  */
303
- transition: (id, transitionName, opts) => this.transition(
304
- slug,
305
- id,
306
- transitionName,
307
- opts
308
- ),
293
+ transition: (id, transitionName, opts) => this.transition(slug, id, transitionName, opts),
309
294
  /**
310
295
  * Fetch the workflow history for a single document — every transition that
311
296
  * has ever been performed, newest first.
@@ -338,10 +323,7 @@ var DyrectedClient = class {
338
323
  method: "POST",
339
324
  body: JSON.stringify({ data: [{ id, ...initialData }] })
340
325
  }).catch(
341
- (err2) => console.error(
342
- `[dyrected/sdk] Failed to auto-seed document "${id}" in collection "${collection}":`,
343
- err2
344
- )
326
+ (err2) => console.error(`[dyrected/sdk] Failed to auto-seed document "${id}" in collection "${collection}":`, err2)
345
327
  );
346
328
  return initialData;
347
329
  }
@@ -380,13 +362,10 @@ var DyrectedClient = class {
380
362
  * const updated = await client.transition('posts', postId, 'publish')
381
363
  */
382
364
  async transition(collection, id, transitionName, opts = {}) {
383
- return this.request(
384
- `/api/collections/${collection}/${id}/transitions/${encodeURIComponent(transitionName)}`,
385
- {
386
- method: "POST",
387
- body: JSON.stringify(opts)
388
- }
389
- );
365
+ return this.request(`/api/collections/${collection}/${id}/transitions/${encodeURIComponent(transitionName)}`, {
366
+ method: "POST",
367
+ body: JSON.stringify(opts)
368
+ });
390
369
  }
391
370
  /**
392
371
  * Fetch the workflow history for a document.
@@ -399,9 +378,7 @@ var DyrectedClient = class {
399
378
  */
400
379
  async workflowHistory(collection, id, args = {}) {
401
380
  const query = args.limit ? `?limit=${args.limit}` : "";
402
- return this.request(
403
- `/api/collections/${collection}/${id}/workflow-history${query}`
404
- );
381
+ return this.request(`/api/collections/${collection}/${id}/workflow-history${query}`);
405
382
  }
406
383
  async deleteMany(collection, ids) {
407
384
  return this.request(`/api/collections/${collection}/delete-many`, {
@@ -414,16 +391,12 @@ var DyrectedClient = class {
414
391
  const query = stringifyQuery(queryArgs, { addQueryPrefix: true });
415
392
  try {
416
393
  const res = await this.request(`/api/globals/${slug}${query}`);
417
- if ((!res || Object.keys(res).length === 0) && initialData) {
394
+ if ((!res || isFunctionallyEmpty(res)) && !isFunctionallyEmpty(initialData)) {
395
+ console.log("[getGlobal] We are seeding", res);
418
396
  this.request(`/api/globals/${slug}/seed`, {
419
397
  method: "POST",
420
398
  body: JSON.stringify({ data: initialData })
421
- }).catch(
422
- (err) => console.error(
423
- `[dyrected/sdk] Failed to auto-seed global "${slug}":`,
424
- err
425
- )
426
- );
399
+ }).catch((err) => console.error(`[dyrected/sdk] Failed to auto-seed global "${slug}":`, err));
427
400
  return initialData;
428
401
  }
429
402
  return res;
@@ -432,12 +405,7 @@ var DyrectedClient = class {
432
405
  this.request(`/api/globals/${slug}/seed`, {
433
406
  method: "POST",
434
407
  body: JSON.stringify({ data: initialData })
435
- }).catch(
436
- (err2) => console.error(
437
- `[dyrected/sdk] Failed to auto-seed global "${slug}":`,
438
- err2
439
- )
440
- );
408
+ }).catch((err2) => console.error(`[dyrected/sdk] Failed to auto-seed global "${slug}":`, err2));
441
409
  return initialData;
442
410
  }
443
411
  throw err;
@@ -505,11 +473,8 @@ var DyrectedClient = class {
505
473
  })
506
474
  );
507
475
  }
508
- throw new DyrectedError(
509
- body.message || `Request failed with status ${res.status}`,
510
- res.status,
511
- body.code
512
- );
476
+ console.log("[DyrectedError]", body, res.status);
477
+ throw new DyrectedError(body.message || `Request failed with status ${res.status}`, res.status, body.code);
513
478
  }
514
479
  return res.json();
515
480
  }
@@ -519,6 +484,19 @@ var DyrectedClient = class {
519
484
  function createClient(config) {
520
485
  return new DyrectedClient(config);
521
486
  }
487
+ function isFunctionallyEmpty(obj) {
488
+ if (obj === null || obj === void 0 || obj === "") return true;
489
+ if (Array.isArray(obj)) {
490
+ if (obj.length === 0) return true;
491
+ return obj.every(isFunctionallyEmpty);
492
+ }
493
+ if (typeof obj === "object") {
494
+ const keys = Object.keys(obj);
495
+ if (keys.length === 0) return true;
496
+ return keys.every((key) => isFunctionallyEmpty(obj[key]));
497
+ }
498
+ return false;
499
+ }
522
500
  export {
523
501
  DyrectedClient,
524
502
  DyrectedError,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dyrected/sdk",
3
- "version": "2.5.39",
3
+ "version": "2.5.40",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -30,7 +30,7 @@
30
30
  "tsup": "^8.5.1",
31
31
  "typescript": "^5.4.5",
32
32
  "vitest": "^1.0.0",
33
- "@dyrected/core": "2.5.39"
33
+ "@dyrected/core": "2.5.40"
34
34
  },
35
35
  "license": "BSL-1.1",
36
36
  "author": "Busola Okeowo <busolaokemoney@gmail.com>",