@relyio/sdk 0.5.0 → 0.7.0

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.
Files changed (37) hide show
  1. package/CHANGELOG.md +540 -0
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/{chunk-HAQELDZN.cjs → chunk-72UK5U7T.cjs} +70 -60
  4. package/dist/{chunk-5AZUUV5B.js → chunk-GYHAVYND.js} +1086 -494
  5. package/dist/{chunk-I3ESNANB.js → chunk-H6IBQSMM.js} +2 -2
  6. package/dist/{chunk-HT6NFRM2.cjs → chunk-TZL374LS.cjs} +2 -2
  7. package/dist/{chunk-CIRT6TVT.cjs → chunk-VH2DE7HZ.cjs} +1088 -497
  8. package/dist/{chunk-XY5KFEFY.js → chunk-YEJUMW4X.js} +70 -60
  9. package/dist/client/index.cjs +4 -3
  10. package/dist/client/index.d.cts +4 -4
  11. package/dist/client/index.d.ts +4 -4
  12. package/dist/client/index.js +2 -1
  13. package/dist/{index-C5mRBb6t.d.cts → define-content-type-DiVpbwNs.d.cts} +1629 -665
  14. package/dist/{index-mXUx2H99.d.ts → define-content-type-DiVpbwNs.d.ts} +1629 -665
  15. package/dist/{define-schema-DzYXk4HL.d.ts → define-schema-C-5an28C.d.ts} +211 -429
  16. package/dist/{define-schema-2xbHgtK-.d.cts → define-schema-D7MButVt.d.cts} +211 -429
  17. package/dist/{index-Dzo-upNS.d.ts → index-1G97sNA8.d.ts} +677 -296
  18. package/dist/index-BOQIHnsh.d.ts +818 -0
  19. package/dist/index-DbsTUw3Q.d.cts +818 -0
  20. package/dist/{index-BozPz4n1.d.cts → index-M0X45k7J.d.cts} +677 -296
  21. package/dist/index.cjs +180 -103
  22. package/dist/index.d.cts +307 -32
  23. package/dist/index.d.ts +307 -32
  24. package/dist/index.js +95 -8
  25. package/dist/schema/index.cjs +35 -35
  26. package/dist/schema/index.d.cts +21 -15
  27. package/dist/schema/index.d.ts +21 -15
  28. package/dist/schema/index.js +1 -1
  29. package/dist/types/index.d.cts +2 -2
  30. package/dist/types/index.d.ts +2 -2
  31. package/dist/utils/index.cjs +19 -19
  32. package/dist/utils/index.d.cts +10 -1
  33. package/dist/utils/index.d.ts +10 -1
  34. package/dist/utils/index.js +1 -1
  35. package/package.json +4 -3
  36. package/dist/define-content-type-CBfnTWSS.d.cts +0 -716
  37. package/dist/define-content-type-CBfnTWSS.d.ts +0 -716
@@ -6,8 +6,8 @@ var chunkMWMSFIWN_cjs = require('./chunk-MWMSFIWN.cjs');
6
6
 
7
7
  // src/schema/define-schema.ts
8
8
  function defineSchema(config) {
9
- if (config.contentTypes == null || Object.keys(config.contentTypes).length === 0) {
10
- throw new Error("Schema must have at least one content type");
9
+ if (config.contentTypes == null) {
10
+ throw new Error("Schema must declare contentTypes (an empty object declares none)");
11
11
  }
12
12
  if (config.locales && config.locales.length > 0) {
13
13
  const defaultLocales = config.locales.filter((l) => l.default === true);
@@ -49,7 +49,7 @@ function defineSchema(config) {
49
49
  const builtInRoles = /* @__PURE__ */ new Set(["admin", "editor", "viewer"]);
50
50
  const customRoleIds = new Set(config.roles?.map((r) => r.id) ?? []);
51
51
  const allRoleIds = /* @__PURE__ */ new Set([...builtInRoles, ...customRoleIds]);
52
- for (const stage of config.workflow.stages) {
52
+ for (const stage of config.workflow.stages ?? []) {
53
53
  if (stage.allowedRoles) {
54
54
  for (const roleId of stage.allowedRoles) {
55
55
  if (!allRoleIds.has(roleId)) {
@@ -95,16 +95,16 @@ function defineSchema(config) {
95
95
  }
96
96
  return {
97
97
  _tag: "schema",
98
- ...config.locales && config.locales.length > 0 && { locales: config.locales },
98
+ ...config.locales !== void 0 && { locales: config.locales },
99
99
  contentTypes: config.contentTypes,
100
100
  components: config.components ?? {},
101
101
  singletonContentTypes: config.singletonContentTypes ?? {},
102
102
  queries: config.queries ?? {},
103
103
  settingsGroups: config.settingsGroups,
104
104
  ...config.assetTypes && { assetTypes: config.assetTypes },
105
- ...config.roles && config.roles.length > 0 && { roles: config.roles },
105
+ ...config.roles !== void 0 && { roles: config.roles },
106
106
  ...config.workflow && { workflow: config.workflow },
107
- ...config.views && config.views.length > 0 && { views: config.views }
107
+ ...config.views !== void 0 && { views: config.views }
108
108
  };
109
109
  }
110
110
  chunkMWMSFIWN_cjs.__name(defineSchema, "defineSchema");
@@ -137,9 +137,9 @@ function defineLocale(code, options) {
137
137
  code,
138
138
  displayName: options.displayName,
139
139
  ...options.default !== void 0 && { default: options.default },
140
- ...options.fallback && options.fallback.length > 0 && { fallback: options.fallback },
141
- ...options.direction && options.direction !== "ltr" && { direction: options.direction },
142
- ...options.active !== void 0 && options.active !== true && { active: options.active }
140
+ ...options.fallback !== void 0 && { fallback: options.fallback },
141
+ ...options.direction !== void 0 && { direction: options.direction },
142
+ ...options.active !== void 0 && { active: options.active }
143
143
  };
144
144
  }
145
145
  chunkMWMSFIWN_cjs.__name(defineLocale, "defineLocale");
@@ -187,6 +187,9 @@ function fieldset(id, config) {
187
187
  id,
188
188
  displayName: config.displayName,
189
189
  description: config.description,
190
+ ...config.collapsedByDefault !== void 0 && {
191
+ collapsedByDefault: config.collapsedByDefault
192
+ },
190
193
  ai: config.ai,
191
194
  fields: config.fields
192
195
  };
@@ -201,8 +204,10 @@ function defineContentType(name, config) {
201
204
  description: config.description,
202
205
  ai: config.ai,
203
206
  displayField: config.displayField,
204
- hierarchical: config.hierarchical ?? false,
205
- ...config.accessTags !== void 0 && config.accessTags.length > 0 && { accessTags: config.accessTags },
207
+ // Written only when given: it was `false` whenever not, so the same content type was one
208
+ // definition from YAML and another from TypeScript, with a different schemaHash (REL-1458)
209
+ ...config.hierarchical !== void 0 && { hierarchical: config.hierarchical },
210
+ ...config.accessTags !== void 0 && { accessTags: config.accessTags },
206
211
  ...config.workflow !== void 0 && { workflow: config.workflow }
207
212
  };
208
213
  if ("fields" in config && config.fields) {
@@ -225,8 +230,11 @@ function defineSingletonContentType(name, config) {
225
230
  description: config.description,
226
231
  ai: config.ai,
227
232
  displayField: config.displayField,
228
- hierarchical: false,
229
- ...config.accessTags !== void 0 && config.accessTags.length > 0 && { accessTags: config.accessTags }
233
+ // Written only when given, as a content type's is (REL-1458)
234
+ ...config.hierarchical !== void 0 && { hierarchical: config.hierarchical },
235
+ ...config.accessTags !== void 0 && { accessTags: config.accessTags },
236
+ // Its config type took `workflow` and this dropped it, so a singleton's workflow never deployed
237
+ ...config.workflow !== void 0 && { workflow: config.workflow }
230
238
  };
231
239
  if ("fields" in config && config.fields) {
232
240
  return { ...base, fields: config.fields };
@@ -247,7 +255,9 @@ function defineComponent(name, config) {
247
255
  displayName: config.displayName,
248
256
  description: config.description,
249
257
  ai: config.ai,
250
- deprecated: config.deprecated ?? false,
258
+ // Written only when given: `false` whenever not made a YAML and a TypeScript component two
259
+ // definitions (REL-1458)
260
+ ...config.deprecated !== void 0 && { deprecated: config.deprecated },
251
261
  fields: config.fields,
252
262
  metadata: config.metadata
253
263
  };
@@ -262,7 +272,7 @@ function defineSettingsGroup(name, config) {
262
272
  displayName: config.displayName,
263
273
  description: config.description,
264
274
  ai: config.ai,
265
- ...config.accessTags !== void 0 && config.accessTags.length > 0 && { accessTags: config.accessTags },
275
+ ...config.accessTags !== void 0 && { accessTags: config.accessTags },
266
276
  fields: config.fields
267
277
  };
268
278
  }
@@ -287,7 +297,8 @@ function defineAssetType(name, config) {
287
297
  description: config.description,
288
298
  ai: config.ai,
289
299
  displayField: config.displayField,
290
- ...config.accessTags !== void 0 && config.accessTags.length > 0 && { accessTags: config.accessTags },
300
+ // An empty list too, as a content type's and a settings group's are kept (REL-1457, REL-1458)
301
+ ...config.accessTags !== void 0 && { accessTags: config.accessTags },
291
302
  ...config.workflow !== void 0 && { workflow: config.workflow },
292
303
  ...config.image !== void 0 && { image: config.image },
293
304
  ...config.video !== void 0 && { video: config.video },
@@ -299,7 +310,7 @@ function defineAssetType(name, config) {
299
310
  if ("fieldsets" in config && config.fieldsets) {
300
311
  return { ...base, fieldsets: config.fieldsets };
301
312
  }
302
- throw new Error(`Asset type '${name}' must have either fields or fieldsets`);
313
+ return base;
303
314
  }
304
315
  chunkMWMSFIWN_cjs.__name(defineAssetType, "defineAssetType");
305
316
 
@@ -369,10 +380,10 @@ function defineRole(id, config) {
369
380
  _tag: "role",
370
381
  id,
371
382
  displayName: config.displayName,
372
- ...config.description !== void 0 && config.description !== "" && { description: config.description },
383
+ ...config.description !== void 0 && { description: config.description },
373
384
  ...config.baseRole !== void 0 && { baseRole: config.baseRole },
374
- ...hasIncludes && { includes: config.includes },
375
- ...hasPermissions && { permissions: config.permissions },
385
+ ...config.includes !== void 0 && { includes: config.includes },
386
+ ...config.permissions !== void 0 && { permissions: config.permissions },
376
387
  ...config.fields !== void 0 && { fields: config.fields }
377
388
  };
378
389
  }
@@ -413,8 +424,7 @@ function defineWorkflowStage(id, config) {
413
424
  if (config.description != null && config.description.length > 512) {
414
425
  throw new Error(`Workflow stage description must be 512 characters or less`);
415
426
  }
416
- const requiredApprovals = config.requiredApprovals ?? 1;
417
- if (requiredApprovals < 1 || requiredApprovals > 10) {
427
+ if (config.requiredApprovals !== void 0 && (config.requiredApprovals < 1 || config.requiredApprovals > 10)) {
418
428
  throw new Error(`requiredApprovals must be between 1 and 10`);
419
429
  }
420
430
  if (config.timeoutDays !== void 0) {
@@ -431,9 +441,9 @@ function defineWorkflowStage(id, config) {
431
441
  _tag: "workflowStage",
432
442
  id,
433
443
  displayName: config.displayName,
434
- ...config.description !== void 0 && config.description !== "" && { description: config.description },
435
- requiredApprovals,
436
- ...config.allowedRoles !== void 0 && config.allowedRoles.length > 0 && { allowedRoles: config.allowedRoles },
444
+ ...config.description !== void 0 && { description: config.description },
445
+ ...config.requiredApprovals !== void 0 && { requiredApprovals: config.requiredApprovals },
446
+ ...config.allowedRoles !== void 0 && { allowedRoles: config.allowedRoles },
437
447
  ...config.autoAssign !== void 0 && { autoAssign: config.autoAssign },
438
448
  ...config.timeoutDays !== void 0 && { timeoutDays: config.timeoutDays },
439
449
  ...config.escalation !== void 0 && { escalation: config.escalation }
@@ -441,28 +451,25 @@ function defineWorkflowStage(id, config) {
441
451
  }
442
452
  chunkMWMSFIWN_cjs.__name(defineWorkflowStage, "defineWorkflowStage");
443
453
  function defineWorkflow(config) {
444
- const enabled = config.enabled ?? false;
445
- const stages = config.stages ?? [];
446
- if (stages.length > 0) {
447
- const stageIds = /* @__PURE__ */ new Set();
448
- for (const stage of stages) {
449
- if (stageIds.has(stage.id)) {
450
- throw new Error(`Duplicate workflow stage ID '${stage.id}'`);
451
- }
452
- stageIds.add(stage.id);
454
+ const stageIds = /* @__PURE__ */ new Set();
455
+ for (const stage of config.stages ?? []) {
456
+ if (stageIds.has(stage.id)) {
457
+ throw new Error(`Duplicate workflow stage ID '${stage.id}'`);
453
458
  }
459
+ stageIds.add(stage.id);
454
460
  }
455
461
  return {
456
462
  _tag: "workflow",
457
- enabled,
458
- stages
463
+ ...config.enabled !== void 0 && { enabled: config.enabled },
464
+ ...config.stages !== void 0 && { stages: config.stages }
459
465
  };
460
466
  }
461
467
  chunkMWMSFIWN_cjs.__name(defineWorkflow, "defineWorkflow");
462
468
  function defineContentTypeWorkflow(config) {
463
469
  return {
464
470
  ...config.enabled !== void 0 && { enabled: config.enabled },
465
- ...config.stages !== void 0 && config.stages.length > 0 && { stages: config.stages },
471
+ // An empty list too, as YAML keeps it (REL-1458)
472
+ ...config.stages !== void 0 && { stages: config.stages },
466
473
  ...config.autoPublish !== void 0 && { autoPublish: config.autoPublish },
467
474
  ...config.requireAllLocales !== void 0 && { requireAllLocales: config.requireAllLocales }
468
475
  };
@@ -476,41 +483,44 @@ function isWorkflowDefinition(value) {
476
483
  return typeof value === "object" && value !== null && "_tag" in value && value._tag === "workflow";
477
484
  }
478
485
  chunkMWMSFIWN_cjs.__name(isWorkflowDefinition, "isWorkflowDefinition");
486
+ function stagesOf(workflow) {
487
+ return workflow.stages ?? [];
488
+ }
489
+ chunkMWMSFIWN_cjs.__name(stagesOf, "stagesOf");
479
490
  function getWorkflowStageIds(workflow) {
480
- return workflow.stages.map((s) => s.id);
491
+ return stagesOf(workflow).map((s) => s.id);
481
492
  }
482
493
  chunkMWMSFIWN_cjs.__name(getWorkflowStageIds, "getWorkflowStageIds");
483
494
  function findWorkflowStage(workflow, stageId) {
484
- return workflow.stages.find((s) => s.id === stageId);
495
+ return stagesOf(workflow).find((s) => s.id === stageId);
485
496
  }
486
497
  chunkMWMSFIWN_cjs.__name(findWorkflowStage, "findWorkflowStage");
487
498
  function getNextWorkflowStage(workflow, currentStageId) {
488
- const currentIndex = workflow.stages.findIndex((s) => s.id === currentStageId);
489
- if (currentIndex === -1 || currentIndex === workflow.stages.length - 1) {
499
+ const stages = stagesOf(workflow);
500
+ const currentIndex = stages.findIndex((s) => s.id === currentStageId);
501
+ if (currentIndex === -1 || currentIndex === stages.length - 1) {
490
502
  return null;
491
503
  }
492
- const nextStage = workflow.stages[currentIndex + 1];
504
+ const nextStage = stages[currentIndex + 1];
493
505
  return nextStage ?? null;
494
506
  }
495
507
  chunkMWMSFIWN_cjs.__name(getNextWorkflowStage, "getNextWorkflowStage");
496
508
  function getFirstWorkflowStage(workflow) {
497
- if (workflow.stages.length === 0) return null;
498
- const firstStage = workflow.stages[0];
509
+ const stages = stagesOf(workflow);
510
+ if (stages.length === 0) return null;
511
+ const firstStage = stages[0];
499
512
  return firstStage ?? null;
500
513
  }
501
514
  chunkMWMSFIWN_cjs.__name(getFirstWorkflowStage, "getFirstWorkflowStage");
502
515
  function isFinalWorkflowStage(workflow, stageId) {
503
- if (workflow.stages.length === 0) return false;
504
- const lastStage = workflow.stages[workflow.stages.length - 1];
516
+ const stages = stagesOf(workflow);
517
+ if (stages.length === 0) return false;
518
+ const lastStage = stages[stages.length - 1];
505
519
  return lastStage?.id === stageId;
506
520
  }
507
521
  chunkMWMSFIWN_cjs.__name(isFinalWorkflowStage, "isFinalWorkflowStage");
508
522
 
509
523
  // src/schema/define-view.ts
510
- function generateSlugFromId(id) {
511
- return id.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/[_\s]+/g, "-").toLowerCase();
512
- }
513
- chunkMWMSFIWN_cjs.__name(generateSlugFromId, "generateSlugFromId");
514
524
  function defineView(id, config) {
515
525
  if (!id.match(/^[a-zA-Z][a-zA-Z0-9_-]*$/)) {
516
526
  throw new Error(
@@ -526,16 +536,14 @@ function defineView(id, config) {
526
536
  if (!config.scope?.type) {
527
537
  throw new Error(`View '${id}' must have a valid scope`);
528
538
  }
529
- const slug2 = config.slug ?? generateSlugFromId(id);
530
- if (!slug2.match(/^[a-z][a-z0-9-]*$/)) {
539
+ if (config.slug !== void 0 && !/^[a-z][a-z0-9-]*$/.test(config.slug)) {
531
540
  throw new Error(
532
- `View '${id}' slug '${slug2}' must be lowercase, start with a letter, and contain only letters, numbers, and hyphens`
541
+ `View '${id}' slug '${config.slug}' must be lowercase, start with a letter, and contain only letters, numbers, and hyphens`
533
542
  );
534
543
  }
535
544
  return {
536
545
  _tag: "view",
537
546
  id,
538
- slug: slug2,
539
547
  ...config
540
548
  };
541
549
  }
@@ -543,8 +551,8 @@ chunkMWMSFIWN_cjs.__name(defineView, "defineView");
543
551
 
544
552
  // src/schema/define-query.ts
545
553
  function defineQuery(name, config) {
546
- if (!config.fetch && !config.aggregate && !config.search && !config.similar) {
547
- throw new Error("Query must have at least one of: fetch, aggregate, search, or similar");
554
+ if (!config.fetch && !config.aggregate && !config.search) {
555
+ throw new Error("Query must have at least one of: fetch, aggregate or search");
548
556
  }
549
557
  if (!config.endpoint.startsWith("/api/")) {
550
558
  throw new Error("Query endpoint must start with /api/");
@@ -552,14 +560,15 @@ function defineQuery(name, config) {
552
560
  return {
553
561
  _tag: "query",
554
562
  name,
563
+ type: config.type,
555
564
  endpoint: config.endpoint,
556
565
  description: config.description,
557
566
  fetch: config.fetch,
558
567
  aggregate: config.aggregate,
559
568
  search: config.search,
560
- similar: config.similar,
561
569
  include: config.include,
562
570
  filters: config.filters,
571
+ fullText: config.fullText,
563
572
  select: config.select,
564
573
  cache: config.cache,
565
574
  parameters: config.parameters,
@@ -597,7 +606,8 @@ function createField(id, type, options = {}) {
597
606
  ...options.config !== void 0 && { config: options.config },
598
607
  ...options.ui !== void 0 && { ui: options.ui },
599
608
  ...options.ai !== void 0 && { ai: options.ai },
600
- ...options.rules !== void 0 && options.rules.length > 0 && { rules: options.rules },
609
+ // An empty list too: dropping it made a YAML field and a TypeScript one two definitions (REL-1458)
610
+ ...options.rules !== void 0 && { rules: options.rules },
601
611
  ...options.localization !== void 0 && { localization: options.localization },
602
612
  ...options.fallback !== void 0 && { fallback: options.fallback },
603
613
  ...options.deprecated !== void 0 && { deprecated: options.deprecated }
@@ -707,5 +717,5 @@ exports.isLocaleDefinition = isLocaleDefinition;
707
717
  exports.isRoleDefinition = isRoleDefinition;
708
718
  exports.isWorkflowDefinition = isWorkflowDefinition;
709
719
  exports.isWorkflowStageDefinition = isWorkflowStageDefinition;
710
- //# sourceMappingURL=chunk-HAQELDZN.cjs.map
711
- //# sourceMappingURL=chunk-HAQELDZN.cjs.map
720
+ //# sourceMappingURL=chunk-72UK5U7T.cjs.map
721
+ //# sourceMappingURL=chunk-72UK5U7T.cjs.map