sf-plugin-data 0.1.0 → 0.2.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 (269) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +572 -240
  3. package/docs/artifact-format.md +527 -633
  4. package/docs/capabilities.md +1159 -168
  5. package/docs/git-workflow.md +135 -12
  6. package/docs/handover.md +7826 -12
  7. package/lib/api.d.ts +7 -0
  8. package/lib/api.js +7 -0
  9. package/lib/artifacts/code-fields.d.ts +49 -0
  10. package/lib/artifacts/code-fields.js +142 -0
  11. package/lib/artifacts/data-graph-document.d.ts +29 -0
  12. package/lib/artifacts/data-graph-document.js +52 -0
  13. package/lib/artifacts/data-space-field.d.ts +65 -0
  14. package/lib/artifacts/data-space-field.js +98 -0
  15. package/lib/artifacts/data-stream-document.d.ts +264 -0
  16. package/lib/artifacts/data-stream-document.js +680 -0
  17. package/lib/artifacts/data-transform-document.d.ts +152 -0
  18. package/lib/artifacts/data-transform-document.js +560 -0
  19. package/lib/artifacts/dependency-selection.d.ts +51 -0
  20. package/lib/artifacts/dependency-selection.js +154 -0
  21. package/lib/artifacts/dlo-document.d.ts +93 -0
  22. package/lib/artifacts/dlo-document.js +253 -0
  23. package/lib/artifacts/enum-case.d.ts +39 -0
  24. package/lib/artifacts/enum-case.js +67 -0
  25. package/lib/artifacts/git-deploy-selection.d.ts +68 -0
  26. package/lib/artifacts/git-deploy-selection.js +474 -0
  27. package/lib/artifacts/identity-resolution-document.d.ts +133 -0
  28. package/lib/artifacts/identity-resolution-document.js +625 -0
  29. package/lib/artifacts/mapping-document.d.ts +1 -0
  30. package/lib/artifacts/mapping-document.js +1 -0
  31. package/lib/artifacts/native-calculated-insight-document.d.ts +142 -0
  32. package/lib/artifacts/native-calculated-insight-document.js +321 -0
  33. package/lib/artifacts/native-data-graph-document.d.ts +124 -0
  34. package/lib/artifacts/native-data-graph-document.js +780 -0
  35. package/lib/artifacts/native-dmo-document.d.ts +151 -0
  36. package/lib/artifacts/native-dmo-document.js +313 -0
  37. package/lib/artifacts/native-mapping-document.d.ts +67 -0
  38. package/lib/artifacts/native-mapping-document.js +187 -0
  39. package/lib/artifacts/native-relationship-document.d.ts +76 -0
  40. package/lib/artifacts/native-relationship-document.js +232 -0
  41. package/lib/artifacts/path-selector.d.ts +55 -0
  42. package/lib/artifacts/path-selector.js +167 -0
  43. package/lib/artifacts/read-deploy-input.d.ts +222 -6
  44. package/lib/artifacts/read-deploy-input.js +1213 -53
  45. package/lib/artifacts/segment-document.d.ts +183 -0
  46. package/lib/artifacts/segment-document.js +570 -0
  47. package/lib/artifacts/verbatim-document.d.ts +203 -0
  48. package/lib/artifacts/verbatim-document.js +339 -0
  49. package/lib/artifacts/write-data-graph.d.ts +17 -0
  50. package/lib/artifacts/write-data-graph.js +162 -0
  51. package/lib/artifacts/write-data-stream.d.ts +11 -0
  52. package/lib/artifacts/write-data-stream.js +175 -0
  53. package/lib/artifacts/write-data-transform.d.ts +11 -0
  54. package/lib/artifacts/write-data-transform.js +180 -0
  55. package/lib/artifacts/write-dlo.d.ts +11 -0
  56. package/lib/artifacts/write-dlo.js +158 -0
  57. package/lib/artifacts/write-identity-resolution.d.ts +18 -0
  58. package/lib/artifacts/write-identity-resolution.js +165 -0
  59. package/lib/artifacts/write-mapping-definition.d.ts +17 -0
  60. package/lib/artifacts/write-mapping-definition.js +127 -0
  61. package/lib/artifacts/write-member-export.d.ts +88 -0
  62. package/lib/artifacts/write-member-export.js +199 -0
  63. package/lib/artifacts/write-native-calculated-insight.d.ts +21 -0
  64. package/lib/artifacts/write-native-calculated-insight.js +176 -0
  65. package/lib/artifacts/write-native-dmo.d.ts +11 -0
  66. package/lib/artifacts/write-native-dmo.js +158 -0
  67. package/lib/artifacts/write-native-mapping.d.ts +11 -0
  68. package/lib/artifacts/write-native-mapping.js +157 -0
  69. package/lib/artifacts/write-native-relationship.d.ts +11 -0
  70. package/lib/artifacts/write-native-relationship.js +157 -0
  71. package/lib/artifacts/write-segment.d.ts +26 -0
  72. package/lib/artifacts/write-segment.js +212 -0
  73. package/lib/commands/data360/delete.d.ts +280 -0
  74. package/lib/commands/data360/delete.js +2297 -0
  75. package/lib/commands/data360/deploy.d.ts +234 -15
  76. package/lib/commands/data360/deploy.js +2292 -100
  77. package/lib/commands/data360/publish.d.ts +93 -0
  78. package/lib/commands/data360/publish.js +292 -0
  79. package/lib/commands/data360/retrieve.d.ts +260 -13
  80. package/lib/commands/data360/retrieve.js +1880 -85
  81. package/lib/commands/data360/segment/members/export.d.ts +101 -0
  82. package/lib/commands/data360/segment/members/export.js +318 -0
  83. package/lib/errors/codes/calculated-insight.d.ts +2 -0
  84. package/lib/errors/codes/calculated-insight.js +25 -0
  85. package/lib/errors/codes/data-graph.d.ts +2 -0
  86. package/lib/errors/codes/data-graph.js +22 -0
  87. package/lib/errors/codes/data-stream.d.ts +2 -0
  88. package/lib/errors/codes/data-stream.js +70 -0
  89. package/lib/errors/codes/data-transform.d.ts +2 -0
  90. package/lib/errors/codes/data-transform.js +35 -0
  91. package/lib/errors/codes/dependency.d.ts +2 -0
  92. package/lib/errors/codes/dependency.js +11 -0
  93. package/lib/errors/codes/dlo.d.ts +2 -0
  94. package/lib/errors/codes/dlo.js +31 -0
  95. package/lib/errors/codes/dmo.d.ts +2 -0
  96. package/lib/errors/codes/dmo.js +28 -0
  97. package/lib/errors/codes/general.d.ts +2 -0
  98. package/lib/errors/codes/general.js +57 -0
  99. package/lib/errors/codes/identity-resolution.d.ts +2 -0
  100. package/lib/errors/codes/identity-resolution.js +24 -0
  101. package/lib/errors/codes/mapping.d.ts +2 -0
  102. package/lib/errors/codes/mapping.js +42 -0
  103. package/lib/errors/codes/relationship.d.ts +2 -0
  104. package/lib/errors/codes/relationship.js +21 -0
  105. package/lib/errors/codes/segment.d.ts +2 -0
  106. package/lib/errors/codes/segment.js +49 -0
  107. package/lib/errors/registry.d.ts +60 -0
  108. package/lib/errors/registry.js +123 -0
  109. package/lib/plugin.d.ts +1 -0
  110. package/lib/plugin.js +3 -1
  111. package/lib/services/acquire-retrieve-selection.d.ts +43 -0
  112. package/lib/services/acquire-retrieve-selection.js +145 -0
  113. package/lib/services/bind-identity-resolution-dependencies.d.ts +53 -0
  114. package/lib/services/bind-identity-resolution-dependencies.js +238 -0
  115. package/lib/services/bind-segment-dependencies.d.ts +49 -0
  116. package/lib/services/bind-segment-dependencies.js +115 -0
  117. package/lib/services/bounded-reads.d.ts +17 -0
  118. package/lib/services/bounded-reads.js +42 -0
  119. package/lib/services/calculated-insight-sql-checks.d.ts +33 -0
  120. package/lib/services/calculated-insight-sql-checks.js +193 -0
  121. package/lib/services/command-dlo.d.ts +48 -0
  122. package/lib/services/command-dlo.js +103 -0
  123. package/lib/services/command-native-data-graph.d.ts +54 -0
  124. package/lib/services/command-native-data-graph.js +485 -0
  125. package/lib/services/command-native-data-stream.d.ts +104 -0
  126. package/lib/services/command-native-data-stream.js +257 -0
  127. package/lib/services/command-native-dmo.d.ts +124 -0
  128. package/lib/services/command-native-dmo.js +338 -0
  129. package/lib/services/command-native-mapping.d.ts +65 -0
  130. package/lib/services/command-native-mapping.js +129 -0
  131. package/lib/services/command-native-relationship.d.ts +46 -0
  132. package/lib/services/command-native-relationship.js +103 -0
  133. package/lib/services/cross-dataspace-deploy.d.ts +111 -0
  134. package/lib/services/cross-dataspace-deploy.js +493 -0
  135. package/lib/services/cross-dataspace-rename.d.ts +74 -0
  136. package/lib/services/cross-dataspace-rename.js +1314 -0
  137. package/lib/services/cross-dataspace-sql.d.ts +109 -0
  138. package/lib/services/cross-dataspace-sql.js +1301 -0
  139. package/lib/services/cross-space-context.d.ts +23 -0
  140. package/lib/services/cross-space-context.js +36 -0
  141. package/lib/services/crud-plan.d.ts +137 -0
  142. package/lib/services/crud-plan.js +408 -0
  143. package/lib/services/data-space-check.d.ts +89 -0
  144. package/lib/services/data-space-check.js +162 -0
  145. package/lib/services/data-space-prefix.d.ts +77 -0
  146. package/lib/services/data-space-prefix.js +127 -0
  147. package/lib/services/data-transform-space.d.ts +31 -0
  148. package/lib/services/data-transform-space.js +79 -0
  149. package/lib/services/delete-calculated-insight.d.ts +44 -0
  150. package/lib/services/delete-calculated-insight.js +101 -0
  151. package/lib/services/delete-data-transform.d.ts +52 -0
  152. package/lib/services/delete-data-transform.js +222 -0
  153. package/lib/services/delete-dmo-field.d.ts +211 -0
  154. package/lib/services/delete-dmo-field.js +472 -0
  155. package/lib/services/delete-identity-resolution.d.ts +43 -0
  156. package/lib/services/delete-identity-resolution.js +295 -0
  157. package/lib/services/delete-segment.d.ts +42 -0
  158. package/lib/services/delete-segment.js +248 -0
  159. package/lib/services/deploy-result.d.ts +54 -0
  160. package/lib/services/deploy-result.js +60 -0
  161. package/lib/services/escaped-copy.d.ts +23 -0
  162. package/lib/services/escaped-copy.js +88 -0
  163. package/lib/services/execute-calculated-insight-deploy.d.ts +42 -0
  164. package/lib/services/execute-calculated-insight-deploy.js +96 -0
  165. package/lib/services/execute-data-transform-deploy.d.ts +56 -0
  166. package/lib/services/execute-data-transform-deploy.js +168 -0
  167. package/lib/services/execute-native-identity-resolution-deploy.d.ts +48 -0
  168. package/lib/services/execute-native-identity-resolution-deploy.js +360 -0
  169. package/lib/services/execute-segment-deploy.d.ts +45 -0
  170. package/lib/services/execute-segment-deploy.js +393 -0
  171. package/lib/services/local-file-removal.d.ts +36 -0
  172. package/lib/services/local-file-removal.js +103 -0
  173. package/lib/services/native-calculated-insight.d.ts +87 -0
  174. package/lib/services/native-calculated-insight.js +164 -0
  175. package/lib/services/native-crm-data-stream.d.ts +91 -0
  176. package/lib/services/native-crm-data-stream.js +272 -0
  177. package/lib/services/native-data-graph-context.d.ts +12 -0
  178. package/lib/services/native-data-graph-context.js +139 -0
  179. package/lib/services/native-data-graph-crd.d.ts +261 -0
  180. package/lib/services/native-data-graph-crd.js +866 -0
  181. package/lib/services/native-data-stream.d.ts +329 -0
  182. package/lib/services/native-data-stream.js +1830 -0
  183. package/lib/services/native-dlo.d.ts +163 -0
  184. package/lib/services/native-dlo.js +402 -0
  185. package/lib/services/native-dmo.d.ts +191 -0
  186. package/lib/services/native-dmo.js +614 -0
  187. package/lib/services/native-mapping.d.ts +255 -0
  188. package/lib/services/native-mapping.js +1226 -0
  189. package/lib/services/native-relationship.d.ts +132 -0
  190. package/lib/services/native-relationship.js +512 -0
  191. package/lib/services/operation-diagnostic.d.ts +83 -0
  192. package/lib/services/operation-diagnostic.js +272 -0
  193. package/lib/services/preflight-calculated-insight-deploy.d.ts +58 -0
  194. package/lib/services/preflight-calculated-insight-deploy.js +95 -0
  195. package/lib/services/preflight-data-transform-deploy.d.ts +33 -0
  196. package/lib/services/preflight-data-transform-deploy.js +104 -0
  197. package/lib/services/preflight-identity-resolution-deploy.d.ts +107 -0
  198. package/lib/services/preflight-identity-resolution-deploy.js +281 -0
  199. package/lib/services/preflight-segment-deploy.d.ts +31 -0
  200. package/lib/services/preflight-segment-deploy.js +109 -0
  201. package/lib/services/publish-calculated-insight.d.ts +40 -0
  202. package/lib/services/publish-calculated-insight.js +95 -0
  203. package/lib/services/publish-segment.d.ts +65 -0
  204. package/lib/services/publish-segment.js +194 -0
  205. package/lib/services/readback-pace.d.ts +16 -0
  206. package/lib/services/readback-pace.js +23 -0
  207. package/lib/services/retrieve-data-transform.d.ts +26 -0
  208. package/lib/services/retrieve-data-transform.js +65 -0
  209. package/lib/services/retrieve-identity-resolution.d.ts +40 -0
  210. package/lib/services/retrieve-identity-resolution.js +87 -0
  211. package/lib/services/retrieve-inventory.d.ts +32 -0
  212. package/lib/services/retrieve-inventory.js +151 -0
  213. package/lib/services/retrieve-segment.d.ts +120 -0
  214. package/lib/services/retrieve-segment.js +502 -0
  215. package/lib/services/segment-lookup.d.ts +46 -0
  216. package/lib/services/segment-lookup.js +108 -0
  217. package/lib/services/segment-members.d.ts +144 -0
  218. package/lib/services/segment-members.js +402 -0
  219. package/lib/services/select-native-retrieve.d.ts +60 -0
  220. package/lib/services/select-native-retrieve.js +226 -0
  221. package/lib/services/settle-calculated-insight.d.ts +22 -0
  222. package/lib/services/settle-calculated-insight.js +53 -0
  223. package/lib/services/sql-tokens.d.ts +58 -0
  224. package/lib/services/sql-tokens.js +147 -0
  225. package/lib/transport/api-version.d.ts +36 -0
  226. package/lib/transport/api-version.js +89 -0
  227. package/lib/transport/bound-ssot.d.ts +27 -0
  228. package/lib/transport/bound-ssot.js +116 -0
  229. package/lib/transport/calculated-insight-rest.d.ts +28 -0
  230. package/lib/transport/calculated-insight-rest.js +62 -0
  231. package/lib/transport/connect-client.d.ts +94 -32
  232. package/lib/transport/connect-client.js +318 -178
  233. package/lib/transport/connect-diagnostic.d.ts +89 -0
  234. package/lib/transport/connect-diagnostic.js +331 -0
  235. package/lib/transport/data-graph-rest.d.ts +27 -0
  236. package/lib/transport/data-graph-rest.js +76 -0
  237. package/lib/transport/data-stream-rest.d.ts +62 -0
  238. package/lib/transport/data-stream-rest.js +348 -0
  239. package/lib/transport/data-transform-rest.d.ts +25 -0
  240. package/lib/transport/data-transform-rest.js +100 -0
  241. package/lib/transport/dlo-native-rest.d.ts +22 -0
  242. package/lib/transport/dlo-native-rest.js +89 -0
  243. package/lib/transport/dlo-rest.d.ts +23 -0
  244. package/lib/transport/dlo-rest.js +135 -0
  245. package/lib/transport/dmo-native-rest.d.ts +18 -0
  246. package/lib/transport/dmo-native-rest.js +55 -0
  247. package/lib/transport/dmo-rest.d.ts +30 -0
  248. package/lib/transport/dmo-rest.js +163 -0
  249. package/lib/transport/mapping-rest.d.ts +63 -0
  250. package/lib/transport/mapping-rest.js +341 -0
  251. package/lib/transport/project-metadata.d.ts +36 -0
  252. package/lib/transport/project-metadata.js +118 -0
  253. package/lib/transport/relationship-rest.d.ts +43 -0
  254. package/lib/transport/relationship-rest.js +201 -0
  255. package/package.json +29 -6
  256. package/lib/artifacts/dmo-document.d.ts +0 -181
  257. package/lib/artifacts/dmo-document.js +0 -848
  258. package/lib/artifacts/dmo-update-delta.d.ts +0 -28
  259. package/lib/artifacts/dmo-update-delta.js +0 -86
  260. package/lib/artifacts/write-other-dmo.d.ts +0 -17
  261. package/lib/artifacts/write-other-dmo.js +0 -140
  262. package/lib/services/execute-dmo-create.d.ts +0 -24
  263. package/lib/services/execute-dmo-create.js +0 -118
  264. package/lib/services/execute-dmo-deploy.d.ts +0 -33
  265. package/lib/services/execute-dmo-deploy.js +0 -197
  266. package/lib/services/preflight-dmo-deploy.d.ts +0 -69
  267. package/lib/services/preflight-dmo-deploy.js +0 -161
  268. package/lib/services/retrieve-other-dmo.d.ts +0 -46
  269. package/lib/services/retrieve-other-dmo.js +0 -140
@@ -0,0 +1,570 @@
1
+ import { segmentName } from './path-selector.js';
2
+ import { isDeepStrictEqual } from 'node:util';
3
+ import { joinCodeFields, splitCodeFields } from './code-fields.js';
4
+ import { explainInput, printableKey } from '../services/operation-diagnostic.js';
5
+ import { dataSpaceKey, readSingleDataSpace, refuseLegacyDataSpace } from './data-space-field.js';
6
+ /** Payload-free refusal of incomplete or unsupported Segment content. */
7
+ export class SegmentError extends Error {
8
+ code;
9
+ constructor(code) {
10
+ super('Segment configuration could not be admitted.');
11
+ this.code = code;
12
+ this.name = 'SegmentError';
13
+ }
14
+ }
15
+ const dmoName = /^[A-Za-z][A-Za-z0-9_]*__dlm$/u;
16
+ // A model name is part of its SQL file name (`<Segment>.segment.<model>.sql`), as in code-fields.
17
+ const modelFileName = /^[A-Za-z0-9][A-Za-z0-9_]*$/u;
18
+ // Keys every file of a type holds; `schedule` (and the lookback of other types) may be absent.
19
+ const specKeys = [
20
+ 'displayName',
21
+ 'description',
22
+ 'segmentType',
23
+ 'segmentOn',
24
+ 'models',
25
+ 'lookbackPeriod',
26
+ ];
27
+ const uiSpecKeys = [
28
+ 'displayName',
29
+ 'description',
30
+ 'segmentType',
31
+ 'segmentOn',
32
+ 'includeCriteria',
33
+ 'lookbackPeriod',
34
+ ];
35
+ const otherSpecKeys = ['displayName', 'description', 'segmentType', 'segmentOn'];
36
+ const scheduleKeys = [
37
+ 'frequency',
38
+ 'interval',
39
+ 'daysOfWeek',
40
+ 'startDateTime',
41
+ 'time',
42
+ 'endDate',
43
+ 'endDateTime',
44
+ 'publishInterval',
45
+ ];
46
+ /**
47
+ * The schedule of a segment that does not refresh. Retrieve leaves the key out for it; a file
48
+ * states it explicitly to turn a schedule off.
49
+ */
50
+ export const unscheduledSegment = Object.freeze({ frequency: 'None' });
51
+ /** The segment type whose child segments the file holds by name (`spec.childSegments`). */
52
+ export const waterfallSegmentType = 'Waterfall';
53
+ /**
54
+ * Stand-in for a child segment of a Waterfall read from an org that the plugin could not name
55
+ * (deploy-mode reads only): it never equals a name in a file, and deploy refuses it in a file.
56
+ */
57
+ export const unnamedChildSegment = '(a child segment the plugin could not name)';
58
+ /**
59
+ * Stand-in for an org schedule the file cannot hold (deploy-mode reads only): it never equals a
60
+ * file schedule, and a file without `schedule` leaves it alone.
61
+ */
62
+ export const opaqueSegmentSchedule = Object.freeze({
63
+ frequency: '(a schedule the segment file cannot hold)',
64
+ });
65
+ /**
66
+ * Refuse a segment file, naming the key path that cannot be deployed.
67
+ * @param {string} code Stable refusal code.
68
+ * @param {string} keyPath Printable key path.
69
+ * @param {string} problem What is wrong with it.
70
+ * @returns {SegmentError} Refusal with an explanation.
71
+ */
72
+ function refuse(code, keyPath, problem) {
73
+ return explainInput(new SegmentError(code), `The segment file cannot be deployed: ${keyPath} ${problem}. Correct the file, or retrieve the segment again once the plugin supports it.`);
74
+ }
75
+ /**
76
+ * Admit a plain record with all of its required keys. A closed record also rejects every other
77
+ * key outside `optional`, naming it; an open one keeps them.
78
+ * @param {unknown} value Untrusted record.
79
+ * @param {string[]} keys Required key set.
80
+ * @param {string} keyPath Printable path of the record.
81
+ * @param {boolean} open Whether keys outside `keys` and `optional` are kept.
82
+ * @param {string[]} optional Keys a closed record may also hold.
83
+ * @returns {Record<string, unknown>} Checked record.
84
+ */
85
+ function record(value, keys, keyPath, open = false, optional = []) {
86
+ if (!value || typeof value !== 'object' || Array.isArray(value))
87
+ throw refuse('INVALID_SEGMENT_DOCUMENT', keyPath, 'is not an object');
88
+ const result = value;
89
+ const missing = keys.find((key) => !Object.hasOwn(result, key));
90
+ if (missing !== undefined)
91
+ throw refuse('UNKNOWN_SEGMENT_CONFIGURATION', `${keyPath}.${missing}`, 'is missing');
92
+ const unknown = open
93
+ ? undefined
94
+ : Object.keys(result).find((key) => !keys.includes(key) && !optional.includes(key));
95
+ if (unknown !== undefined)
96
+ throw refuse('UNKNOWN_SEGMENT_CONFIGURATION', `${keyPath}.${printableKey(unknown)}`, 'is not a key a segment file can hold');
97
+ return result;
98
+ }
99
+ /**
100
+ * Bound text without changing SQL bytes or inventing defaults. Retrieve keeps any string.
101
+ * @param {unknown} value Untrusted string.
102
+ * @param {string} keyPath Printable key path.
103
+ * @param {DocumentMode} mode Check mode.
104
+ * @param {boolean} empty Whether an empty string is meaningful.
105
+ * @returns {string} Original text.
106
+ */
107
+ function text(value, keyPath, mode, empty = false) {
108
+ if (typeof value !== 'string')
109
+ throw refuse('INVALID_SEGMENT_DOCUMENT', keyPath, 'is not text');
110
+ if (mode === 'retrieve')
111
+ return value;
112
+ if (!empty && value.length === 0)
113
+ throw refuse('INVALID_SEGMENT_DOCUMENT', keyPath, 'is empty');
114
+ if (value.length > 262_144 ||
115
+ [...value].some((character) => character.codePointAt(0) < 32 && !['\t', '\n', '\r'].includes(character)))
116
+ throw refuse('INVALID_SEGMENT_DOCUMENT', keyPath, 'is longer than 262144 characters or has control characters');
117
+ return value;
118
+ }
119
+ /**
120
+ * Admit the optional schedule: an object with at least one write key, whose values are sent as
121
+ * written (Salesforce decides about them). `frequency` and `publishInterval` are text.
122
+ * `{frequency: None}` stands alone.
123
+ * @param {unknown} value Untrusted schedule.
124
+ * @param {DocumentMode} mode Check mode.
125
+ * @returns {SegmentSchedule} Detached schedule.
126
+ */
127
+ function scheduleOf(value, mode) {
128
+ const schedule = record(value, [], 'spec.schedule', mode === 'retrieve', scheduleKeys);
129
+ if (Object.keys(schedule).length === 0)
130
+ throw refuse('INVALID_SEGMENT_DOCUMENT', 'spec.schedule', 'holds no schedule key');
131
+ const empty = Object.keys(schedule).find((key) => schedule[key] === null);
132
+ if (empty !== undefined)
133
+ throw refuse('INVALID_SEGMENT_DOCUMENT', `spec.schedule.${printableKey(empty)}`, 'is null; leave the key out to keep the org value, or turn the schedule off with {"frequency": "None"}');
134
+ for (const key of ['frequency', 'publishInterval'])
135
+ if (Object.hasOwn(schedule, key))
136
+ text(schedule[key], `spec.schedule.${key}`, mode);
137
+ if (isOff(schedule) && Object.keys(schedule).length > 1)
138
+ throw refuse('INVALID_SEGMENT_DOCUMENT', 'spec.schedule', 'turns the schedule off (frequency None) and cannot hold other keys');
139
+ return structuredClone(schedule);
140
+ }
141
+ /**
142
+ * Admit the child segments of a Waterfall: a non-empty list of segment API names in priority
143
+ * order, each named once (ignoring case). A deploy-mode read of the org may hold
144
+ * `unnamedChildSegment` for a child it could not name.
145
+ * @param {unknown} value Untrusted list.
146
+ * @param {DocumentMode} mode Check mode.
147
+ * @returns {string[]} Detached names.
148
+ */
149
+ function childSegmentsOf(value, mode) {
150
+ if (!Array.isArray(value) || value.length === 0)
151
+ throw refuse('INVALID_SEGMENT_DOCUMENT', 'spec.childSegments', 'is not a list of child segment API names; leave the key out to keep the children of the org segment');
152
+ const seen = new Set();
153
+ return value.map((entry, index) => {
154
+ const name = text(entry, `spec.childSegments[${index}]`, mode);
155
+ if (name === unnamedChildSegment)
156
+ return name;
157
+ if (!segmentName.test(name) || seen.has(name.toLowerCase()))
158
+ throw refuse('INVALID_SEGMENT_DOCUMENT', `spec.childSegments[${index}]`, 'is not a segment API name or names a child segment twice');
159
+ seen.add(name.toLowerCase());
160
+ return name;
161
+ });
162
+ }
163
+ /**
164
+ * Validate and detach an authored Segment definition (structure only). Its data space is the
165
+ * top-level `c__dataSpace`; the old `identity.dataSpace` and `spec.segmentOn.dataSpace` keys are
166
+ * refused (LEGACY_DATASPACE_KEY), since the segmentOn DMO is always in the segment's space. A DBT segment
167
+ * holds SQL models, a UI segment (`segmentType: UI`) its `includeCriteria` as a JSON object, and
168
+ * any other type neither; a Waterfall may list its child segments by API name
169
+ * (`childSegments`). The lookback (any text; optional for other types) and the optional
170
+ * schedule are sent as written and Salesforce decides about them. Retrieve mode keeps unknown
171
+ * `spec`, schedule and model keys and lifts the text limits, but still refuses what the file
172
+ * cannot represent: another source kind, and a model name that cannot be a file
173
+ * name or repeats one (ignoring case). Deploy refuses unknown keys and names the key path.
174
+ * @param {unknown} value Untrusted authored document.
175
+ * @param {DocumentMode} [mode] `deploy` (strict) or `retrieve` (keeps unknown keys).
176
+ * @returns {SegmentDocument} Independently admitted detached document.
177
+ */
178
+ export function validateSegmentDocument(value, mode = 'deploy') {
179
+ const lenient = mode === 'retrieve';
180
+ const root = record(value, ['schemaVersion', 'kind', 'identity', 'spec'], '[document]', false, [
181
+ dataSpaceKey,
182
+ ]);
183
+ const identity = record(root.identity, ['apiName'], 'identity', false, ['dataSpace']);
184
+ refuseLegacyDataSpace(identity, refuse);
185
+ const dataSpace = readSingleDataSpace(root, refuse);
186
+ const type = root.spec?.segmentType;
187
+ const keys = type === 'UI' ? uiSpecKeys : type === 'DBT' ? specKeys : otherSpecKeys;
188
+ const waterfall = type === waterfallSegmentType;
189
+ const spec = record(root.spec, keys, 'spec', lenient, keys === otherSpecKeys
190
+ ? ['lookbackPeriod', 'schedule', ...(waterfall ? ['childSegments'] : [])]
191
+ : ['schedule']);
192
+ const on = record(spec.segmentOn, ['kind', 'apiName'], 'spec.segmentOn', false, ['dataSpace']);
193
+ if (Object.hasOwn(on, 'dataSpace'))
194
+ throw refuse('LEGACY_DATASPACE_KEY', 'spec.segmentOn.dataSpace', `is the old place of a data space; the DMO a segment is built on is always in the segment's own data space (${dataSpaceKey})`);
195
+ if (root.schemaVersion !== 1 || root.kind !== 'segment')
196
+ throw refuse('UNSUPPORTED_SEGMENT_VARIANT', 'kind', 'is not a schemaVersion 1 segment');
197
+ if (!segmentName.test(text(identity.apiName, 'identity.apiName', mode)))
198
+ throw refuse('UNSUPPORTED_SEGMENT_VARIANT', 'identity', 'is not a segment API name');
199
+ if (on.kind !== 'dmo' || !dmoName.test(text(on.apiName, 'spec.segmentOn.apiName', mode)))
200
+ throw refuse('UNSUPPORTED_SEGMENT_VARIANT', 'spec.segmentOn', 'is not a DMO (__dlm)');
201
+ const segmentType = text(spec.segmentType, 'spec.segmentType', mode);
202
+ text(spec.displayName, 'spec.displayName', mode);
203
+ text(spec.description, 'spec.description', mode, true);
204
+ const lookbackPeriod = Object.hasOwn(spec, 'lookbackPeriod')
205
+ ? text(spec.lookbackPeriod, 'spec.lookbackPeriod', mode)
206
+ : undefined;
207
+ const schedule = Object.hasOwn(spec, 'schedule') ? scheduleOf(spec.schedule, mode) : undefined;
208
+ const childSegments = waterfall && Object.hasOwn(spec, 'childSegments')
209
+ ? childSegmentsOf(spec.childSegments, mode)
210
+ : undefined;
211
+ let content = {};
212
+ if (segmentType === 'UI') {
213
+ const criteria = spec.includeCriteria;
214
+ if (!criteria || typeof criteria !== 'object' || Array.isArray(criteria))
215
+ throw refuse('INVALID_SEGMENT_DOCUMENT', 'spec.includeCriteria', 'is not an object');
216
+ content = { includeCriteria: structuredClone(criteria) };
217
+ }
218
+ else if (segmentType === 'DBT') {
219
+ // The models are sent as written; Salesforce decides about the SQL and the model names.
220
+ if (!Array.isArray(spec.models))
221
+ throw refuse('INVALID_SEGMENT_DOCUMENT', 'spec.models', 'is not a list');
222
+ const names = new Set();
223
+ const models = spec.models.map((entry, index) => {
224
+ const keyPath = `spec.models[${index}]`;
225
+ const model = record(entry, ['name', 'sql'], keyPath, lenient);
226
+ const name = text(model.name, `${keyPath}.name`, mode);
227
+ const sql = text(model.sql, `${keyPath}.sql`, mode);
228
+ if (!lenient)
229
+ return { name, sql };
230
+ // Retrieve writes each model's SQL to a file named by the model.
231
+ if (!modelFileName.test(name) || names.has(name.toLowerCase()))
232
+ throw refuse('INVALID_SEGMENT_DOCUMENT', `${keyPath}.name`, 'cannot be a SQL file name or repeats another model name');
233
+ names.add(name.toLowerCase());
234
+ return { ...structuredClone(model), name, sql };
235
+ });
236
+ content = { models };
237
+ }
238
+ // Retrieve keeps the keys the plugin does not model after the known ones; deploy refused them.
239
+ const extra = Object.fromEntries(Object.entries(spec)
240
+ .filter(([key]) => !keys.includes(key) &&
241
+ !['lookbackPeriod', 'schedule'].includes(key) &&
242
+ !(waterfall && key === 'childSegments'))
243
+ .map(([key, entry]) => [key, structuredClone(entry)]));
244
+ return {
245
+ schemaVersion: 1,
246
+ kind: 'segment',
247
+ c__dataSpace: dataSpace,
248
+ identity: { apiName: identity.apiName },
249
+ spec: {
250
+ displayName: spec.displayName,
251
+ description: spec.description,
252
+ segmentType,
253
+ segmentOn: { kind: 'dmo', apiName: on.apiName },
254
+ ...content,
255
+ ...(lookbackPeriod === undefined ? {} : { lookbackPeriod }),
256
+ ...(schedule ? { schedule } : {}),
257
+ ...(childSegments ? { childSegments } : {}),
258
+ ...extra,
259
+ },
260
+ };
261
+ }
262
+ /**
263
+ * Whether a schedule turns refresh off (`frequency` None, in any letter case).
264
+ * @param {SegmentSchedule} schedule Schedule.
265
+ * @returns {boolean} Off.
266
+ */
267
+ function isOff(schedule) {
268
+ return (typeof schedule.frequency === 'string' &&
269
+ schedule.frequency.toLowerCase() === unscheduledSegment.frequency.toLowerCase());
270
+ }
271
+ /**
272
+ * One schedule value in comparable form: enum text folded to lower case, the interval as a
273
+ * number and ISO timestamps normalised (`…T03:00:00Z` equals `…T03:00:00.000Z`).
274
+ * @param {string} key Schedule key.
275
+ * @param {unknown} value Value.
276
+ * @returns {unknown} Comparable value.
277
+ */
278
+ function comparableScheduleValue(key, value) {
279
+ if (['frequency', 'publishInterval'].includes(key) && typeof value === 'string')
280
+ return value.toLowerCase();
281
+ if (key === 'interval' && (typeof value === 'number' || typeof value === 'string'))
282
+ return Number(value);
283
+ if (['startDateTime', 'endDate', 'endDateTime'].includes(key) && typeof value === 'string') {
284
+ const time = Date.parse(value);
285
+ return Number.isNaN(time) ? value : new Date(time).toISOString();
286
+ }
287
+ return value;
288
+ }
289
+ /**
290
+ * Whether the org schedule (as projected; none is unscheduled) already holds the schedule of the
291
+ * file. Only the keys the file states are compared: a key the file leaves out keeps its org
292
+ * value, because a write without it keeps the stored value. Salesforce does not read the time
293
+ * back, so a `time` the org does not show is not compared. A schedule the file cannot hold
294
+ * (`opaqueSegmentSchedule`) never equals a file schedule.
295
+ * @param {SegmentSchedule | undefined} current Projected org schedule.
296
+ * @param {SegmentSchedule} desired Schedule of the file.
297
+ * @returns {boolean} True when the schedule would not change.
298
+ */
299
+ export function sameSegmentSchedule(current, desired) {
300
+ const found = current ?? unscheduledSegment;
301
+ if (found.frequency === opaqueSegmentSchedule.frequency)
302
+ return false;
303
+ if (isOff(desired))
304
+ return isOff(found);
305
+ if (isOff(found))
306
+ return false;
307
+ return Object.entries(desired).every(([key, value]) => (key === 'time' && !Object.hasOwn(found, 'time')) ||
308
+ (Object.hasOwn(found, key) &&
309
+ isDeepStrictEqual(comparableScheduleValue(key, found[key]), comparableScheduleValue(key, value))));
310
+ }
311
+ /**
312
+ * The schedule keys of a segment write. Create sends `publishSchedule: NoRefresh` unless the file
313
+ * has a schedule; an update sends schedule keys only when `send` (the schedule changes). The
314
+ * file keys go out in the write shape, each only when the file has it: `frequency`, `interval`,
315
+ * `daysOfWeek` (wrapped) and `time` (as `timeInfo`) in `publishScheduleInfo`, `startDateTime`,
316
+ * `endDate` and `endDateTime` as `publishScheduleStartDateTime`, `publishScheduleEndDate` and
317
+ * `publishScheduleEndDateTime`, and an hourly `publishInterval` as `publishSchedule`. For
318
+ * `{frequency: None}` the clearing body goes out, which Salesforce takes for UI segments (it
319
+ * refuses every clearing body for DBT segments; that answer is reported).
320
+ * @param {SegmentSchedule | undefined} schedule Schedule of the file.
321
+ * @param {boolean} create Whether this is the create POST.
322
+ * @param {boolean} send Whether an update sends the schedule.
323
+ * @returns {Record<string, unknown>} Schedule keys of the body.
324
+ */
325
+ function scheduleBody(schedule, create, send) {
326
+ const off = !schedule || isOff(schedule);
327
+ if (create && off)
328
+ return { publishSchedule: 'NoRefresh' };
329
+ if (!create && (!send || !schedule))
330
+ return {};
331
+ if (off) {
332
+ // eslint-disable-next-line unicorn/no-null -- Salesforce clears a schedule only with explicit JSON nulls.
333
+ const cleared = null;
334
+ return {
335
+ publishSchedule: 'NoRefresh',
336
+ publishScheduleInfo: cleared,
337
+ publishScheduleStartDateTime: cleared,
338
+ publishScheduleEndDate: cleared,
339
+ publishScheduleEndDateTime: cleared,
340
+ };
341
+ }
342
+ const has = (key) => Object.hasOwn(schedule, key);
343
+ const info = {
344
+ ...(has('frequency') ? { frequency: schedule.frequency } : {}),
345
+ ...(has('interval') ? { interval: schedule.interval } : {}),
346
+ ...(has('daysOfWeek') ? { daysOfWeek: { daysOfWeek: schedule.daysOfWeek } } : {}),
347
+ ...(has('time') ? { timeInfo: schedule.time } : {}),
348
+ };
349
+ return {
350
+ ...(has('publishInterval') ? { publishSchedule: schedule.publishInterval } : {}),
351
+ ...(Object.keys(info).length > 0 ? { publishScheduleInfo: info } : {}),
352
+ ...(has('startDateTime') ? { publishScheduleStartDateTime: schedule.startDateTime } : {}),
353
+ ...(has('endDate') ? { publishScheduleEndDate: schedule.endDate } : {}),
354
+ ...(has('endDateTime') ? { publishScheduleEndDateTime: schedule.endDateTime } : {}),
355
+ };
356
+ }
357
+ /**
358
+ * The child segment definition IDs (`marketSegmentDefinitionId`, `3HX…`) in a Waterfall's
359
+ * criteria (live API 68, 2026-11-18): exactly
360
+ * `{"type":"Waterfall","segments":[{"type":"NestedSegment","segmentId":"<id>"}, ...]}` with at
361
+ * least one child. Anything else (other keys, element types, no children) is not a shape the
362
+ * file holds by name.
363
+ * @param {string} criteria Plain criteria JSON text.
364
+ * @returns {string[] | undefined} Child definition IDs in priority order, or undefined.
365
+ */
366
+ export function waterfallChildIds(criteria) {
367
+ let parsed;
368
+ try {
369
+ parsed = JSON.parse(criteria);
370
+ }
371
+ catch {
372
+ return undefined;
373
+ }
374
+ const root = parsed;
375
+ if (!root ||
376
+ typeof root !== 'object' ||
377
+ Array.isArray(root) ||
378
+ Object.keys(root).length !== 2 ||
379
+ root.type !== waterfallSegmentType ||
380
+ !Array.isArray(root.segments) ||
381
+ root.segments.length === 0)
382
+ return undefined;
383
+ const ids = [];
384
+ for (const entry of root.segments) {
385
+ const child = entry;
386
+ if (!child ||
387
+ typeof child !== 'object' ||
388
+ Array.isArray(child) ||
389
+ Object.keys(child).length !== 2 ||
390
+ child.type !== 'NestedSegment' ||
391
+ typeof child.segmentId !== 'string' ||
392
+ !/^[A-Za-z0-9]{15,18}$/u.test(child.segmentId))
393
+ return undefined;
394
+ ids.push(child.segmentId);
395
+ }
396
+ return ids;
397
+ }
398
+ /**
399
+ * The criteria string of a Waterfall write: its children as `NestedSegment` entries carrying the
400
+ * definition ID of each child in the target org, in the order of the file.
401
+ * @param {string[]} names Child segment API names of the file.
402
+ * @param {ReadonlyMap<string, string>} children Child API name to target definition ID.
403
+ * @returns {string} Criteria JSON text.
404
+ */
405
+ function waterfallCriteria(names, children) {
406
+ return JSON.stringify({
407
+ type: waterfallSegmentType,
408
+ segments: names.map((name) => {
409
+ const segmentId = children.get(name);
410
+ if (segmentId === undefined)
411
+ throw new SegmentError('SEGMENT_CHILD_NOT_FOUND');
412
+ return { type: 'NestedSegment', segmentId };
413
+ }),
414
+ });
415
+ }
416
+ /**
417
+ * The request body of a segment write, sent as written. Create names the segment
418
+ * (`developerName`); a PATCH takes the full definition. A DBT segment sends its models
419
+ * (`segmentType: Dbt`), a UI segment its criteria as a JSON string with
420
+ * `segmentCreationFlow: Headless` (what lets the API write a UI segment at all), any other type
421
+ * its type as read; a Waterfall with `childSegments` sends them as its criteria (each child by
422
+ * its definition ID in the target, from `children`). The lookback goes along when the file has
423
+ * one.
424
+ * @param {SegmentDocument} document Admitted segment.
425
+ * @param {boolean} create Whether this is the create POST.
426
+ * @param {boolean} [schedule] Whether an update sends the schedule (it changes).
427
+ * @param {ReadonlyMap<string, string>} [children] Waterfall child API name to target definition ID.
428
+ * @returns {Record<string, unknown>} Request body.
429
+ */
430
+ export function segmentWriteBody(document, create, schedule = false, children = new Map()) {
431
+ const spec = document.spec;
432
+ const ui = spec.segmentType === 'UI';
433
+ const childSegments = spec.childSegments;
434
+ return {
435
+ ...(create ? { developerName: document.identity.apiName } : {}),
436
+ displayName: spec.displayName,
437
+ description: spec.description,
438
+ segmentOnApiName: spec.segmentOn.apiName,
439
+ segmentType: spec.segmentType === 'DBT' ? 'Dbt' : spec.segmentType,
440
+ ...(spec.segmentType === 'DBT'
441
+ ? { includeDbt: { models: { models: spec.models } } }
442
+ : {}),
443
+ ...(ui ? { includeCriteria: JSON.stringify(spec.includeCriteria) } : {}),
444
+ ...(childSegments ? { includeCriteria: waterfallCriteria(childSegments, children) } : {}),
445
+ ...(spec.lookbackPeriod === undefined ? {} : { lookbackPeriod: spec.lookbackPeriod }),
446
+ ...scheduleBody(spec.schedule, create, schedule),
447
+ ...(ui ? { segmentCreationFlow: 'Headless' } : {}),
448
+ };
449
+ }
450
+ /**
451
+ * The notice for a schedule the write sends: a schedule copied from another org makes the
452
+ * segment publish on it in this one. None when the schedule is absent, unchanged, or off on a
453
+ * create (a new segment does not refresh).
454
+ * @param {SegmentDocument} desired Admitted segment.
455
+ * @param {SegmentDocument | undefined} current Projected org segment; none on create.
456
+ * @returns {{code: string; message: string} | undefined} SEGMENT_SCHEDULE_CHANGE notice.
457
+ */
458
+ export function segmentScheduleNotice(desired, current) {
459
+ const schedule = desired.spec.schedule;
460
+ if (!schedule || sameSegmentSchedule(current?.spec.schedule, schedule))
461
+ return undefined;
462
+ const name = String(schedule.frequency ?? schedule.publishInterval ?? 'as written');
463
+ return {
464
+ code: 'SEGMENT_SCHEDULE_CHANGE',
465
+ message: isOff(schedule)
466
+ ? desired.spec.segmentType === 'DBT'
467
+ ? 'The schedule of the file turns the segment refresh schedule off; Salesforce refuses to clear the schedule of a DBT segment, so it answers the write with an error (only deleting the segment removes the schedule).'
468
+ : 'The schedule of the file turns the segment refresh schedule off in this org.'
469
+ : `The schedule of the file (${name}) replaces the segment refresh schedule in this org; the segment then publishes on it there.`,
470
+ };
471
+ }
472
+ /** Every `spec.models[].sql` lives in its own `<Name>.segment.<model>.sql` file. */
473
+ export const segmentCodeFields = Object.freeze([
474
+ { path: ['spec', 'models'], each: 'sql', key: 'name', extension: 'sql' },
475
+ ]);
476
+ /**
477
+ * The code fields of one segment: only a DBT segment has SQL files.
478
+ * @param {unknown} value Segment document (complete or without its code).
479
+ * @returns {readonly CodeField[]} Code fields.
480
+ */
481
+ function codeFieldsOf(value) {
482
+ const spec = value?.spec;
483
+ return spec?.segmentType === 'DBT' ? segmentCodeFields : [];
484
+ }
485
+ /**
486
+ * The JSON text (admitted fields, stable key order, models without SQL) and one SQL file per model.
487
+ * @param {unknown} value Complete authored document.
488
+ * @param {DocumentMode} [mode] `deploy` (strict) or `retrieve` (keeps unknown keys).
489
+ * @returns {{json: string; files: CodeFile[]}} JSON with LF terminator and the SQL files in model order.
490
+ */
491
+ export function serializeSegmentFiles(value, mode = 'deploy') {
492
+ const { document, files } = splitCodeFields(validateSegmentDocument(value, mode), codeFieldsOf(value), () => new SegmentError('INVALID_SEGMENT_DOCUMENT'));
493
+ return { json: `${JSON.stringify(document, undefined, 2)}\n`, files };
494
+ }
495
+ /**
496
+ * Join a parsed segment JSON with its SQL files; a missing or extra SQL file, or SQL left in the
497
+ * JSON, is INVALID_SEGMENT_DOCUMENT.
498
+ * @param {unknown} value Parsed JSON file content.
499
+ * @param {readonly CodeFile[]} files SQL file contents.
500
+ * @param {DocumentMode} [mode] `deploy` (strict) or `retrieve` (keeps unknown keys).
501
+ * @returns {SegmentDocument} Complete admitted document.
502
+ */
503
+ export function joinSegmentFiles(value, files, mode = 'deploy') {
504
+ return validateSegmentDocument(joinCodeFields(value, codeFieldsOf(value), files, () => new SegmentError('INVALID_SEGMENT_DOCUMENT')), mode);
505
+ }
506
+ /** Keys Salesforce adds to each comparison (an object with `subject`) of UI criteria it stores. */
507
+ const serverCriteriaKeys = new Set([
508
+ 'selfReference',
509
+ 'subjectFieldBusinessType',
510
+ 'subjectFieldDataType',
511
+ 'subjectFieldSourceType',
512
+ ]);
513
+ /**
514
+ * Whether stored UI criteria equal the authored ones. Equal except that a comparison (an object
515
+ * with `subject`) may carry the keys Salesforce adds to it; any other extra key differs.
516
+ * @param {unknown} wanted Authored criteria value.
517
+ * @param {unknown} found Stored criteria value.
518
+ * @returns {boolean} Equal.
519
+ */
520
+ function sameCriteria(wanted, found) {
521
+ if (Array.isArray(wanted))
522
+ return (Array.isArray(found) &&
523
+ wanted.length === found.length &&
524
+ wanted.every((entry, index) => sameCriteria(entry, found[index])));
525
+ if (!wanted || typeof wanted !== 'object')
526
+ return isDeepStrictEqual(wanted, found);
527
+ if (!found || typeof found !== 'object' || Array.isArray(found))
528
+ return false;
529
+ const stored = found;
530
+ const added = Object.hasOwn(stored, 'subject');
531
+ return (Object.keys(stored).every((key) => Object.hasOwn(wanted, key) || (added && serverCriteriaKeys.has(key))) &&
532
+ Object.entries(wanted).every(([key, entry]) => Object.hasOwn(stored, key) && sameCriteria(entry, stored[key])));
533
+ }
534
+ /**
535
+ * Whether a segment read from the org carries the desired definition: the one comparison that
536
+ * preflight, execute and delete use. A UI segment's criteria match when they are equal except
537
+ * for the keys Salesforce adds to each comparison it stores (`selfReference`, `subjectField*`
538
+ * beside `subject`). A file without a schedule leaves the schedule out of the comparison; one
539
+ * with a schedule compares it as `sameSegmentSchedule` does; likewise a Waterfall file without
540
+ * `childSegments` leaves the children out of the comparison, and one with them compares the
541
+ * names in order. Everything else must be equal.
542
+ * @param {unknown} observed Projected candidate from a read or write response.
543
+ * @param {SegmentDocument} desired Admitted requested definition.
544
+ * @returns {boolean} Whether the org holds the desired definition.
545
+ */
546
+ export function carriesDefinition(observed, desired) {
547
+ const other = observed;
548
+ if (!other?.spec || typeof other.spec !== 'object')
549
+ return false;
550
+ const schedule = desired.spec.schedule;
551
+ if (schedule !== undefined && !sameSegmentSchedule(other.spec.schedule, schedule))
552
+ return false;
553
+ const ui = desired.spec.segmentType === 'UI';
554
+ if (ui && other.spec.segmentType !== 'UI')
555
+ return false;
556
+ const children = Object.hasOwn(desired.spec, 'childSegments');
557
+ const rest = (document) => ({
558
+ ...document,
559
+ spec: {
560
+ ...document.spec,
561
+ schedule: undefined,
562
+ ...(ui ? { includeCriteria: undefined } : {}),
563
+ ...(children ? {} : { childSegments: undefined }),
564
+ },
565
+ });
566
+ return (isDeepStrictEqual(rest(other), rest(desired)) &&
567
+ (!ui ||
568
+ sameCriteria(desired.spec.includeCriteria, other.spec.includeCriteria)));
569
+ }
570
+ export { segmentName } from './path-selector.js';