sf-plugin-data 0.0.0-stage → 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 (256) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +589 -2
  3. package/bin/run.js +4 -0
  4. package/docs/artifact-format.md +527 -0
  5. package/docs/capabilities.md +1208 -0
  6. package/docs/git-workflow.md +160 -0
  7. package/docs/handover.md +10446 -0
  8. package/lib/api.d.ts +7 -0
  9. package/lib/api.js +7 -0
  10. package/lib/artifacts/code-fields.d.ts +49 -0
  11. package/lib/artifacts/code-fields.js +142 -0
  12. package/lib/artifacts/data-graph-document.d.ts +29 -0
  13. package/lib/artifacts/data-graph-document.js +52 -0
  14. package/lib/artifacts/data-space-field.d.ts +65 -0
  15. package/lib/artifacts/data-space-field.js +98 -0
  16. package/lib/artifacts/data-stream-document.d.ts +264 -0
  17. package/lib/artifacts/data-stream-document.js +680 -0
  18. package/lib/artifacts/data-transform-document.d.ts +152 -0
  19. package/lib/artifacts/data-transform-document.js +560 -0
  20. package/lib/artifacts/dependency-selection.d.ts +51 -0
  21. package/lib/artifacts/dependency-selection.js +154 -0
  22. package/lib/artifacts/dlo-document.d.ts +93 -0
  23. package/lib/artifacts/dlo-document.js +253 -0
  24. package/lib/artifacts/enum-case.d.ts +39 -0
  25. package/lib/artifacts/enum-case.js +67 -0
  26. package/lib/artifacts/git-deploy-selection.d.ts +68 -0
  27. package/lib/artifacts/git-deploy-selection.js +474 -0
  28. package/lib/artifacts/identity-resolution-document.d.ts +133 -0
  29. package/lib/artifacts/identity-resolution-document.js +625 -0
  30. package/lib/artifacts/mapping-document.d.ts +1 -0
  31. package/lib/artifacts/mapping-document.js +1 -0
  32. package/lib/artifacts/native-calculated-insight-document.d.ts +142 -0
  33. package/lib/artifacts/native-calculated-insight-document.js +321 -0
  34. package/lib/artifacts/native-data-graph-document.d.ts +124 -0
  35. package/lib/artifacts/native-data-graph-document.js +780 -0
  36. package/lib/artifacts/native-dmo-document.d.ts +151 -0
  37. package/lib/artifacts/native-dmo-document.js +313 -0
  38. package/lib/artifacts/native-mapping-document.d.ts +67 -0
  39. package/lib/artifacts/native-mapping-document.js +187 -0
  40. package/lib/artifacts/native-relationship-document.d.ts +76 -0
  41. package/lib/artifacts/native-relationship-document.js +232 -0
  42. package/lib/artifacts/path-selector.d.ts +55 -0
  43. package/lib/artifacts/path-selector.js +167 -0
  44. package/lib/artifacts/read-deploy-input.d.ts +239 -0
  45. package/lib/artifacts/read-deploy-input.js +1359 -0
  46. package/lib/artifacts/segment-document.d.ts +183 -0
  47. package/lib/artifacts/segment-document.js +570 -0
  48. package/lib/artifacts/verbatim-document.d.ts +203 -0
  49. package/lib/artifacts/verbatim-document.js +339 -0
  50. package/lib/artifacts/write-data-graph.d.ts +17 -0
  51. package/lib/artifacts/write-data-graph.js +162 -0
  52. package/lib/artifacts/write-data-stream.d.ts +11 -0
  53. package/lib/artifacts/write-data-stream.js +175 -0
  54. package/lib/artifacts/write-data-transform.d.ts +11 -0
  55. package/lib/artifacts/write-data-transform.js +180 -0
  56. package/lib/artifacts/write-dlo.d.ts +11 -0
  57. package/lib/artifacts/write-dlo.js +158 -0
  58. package/lib/artifacts/write-identity-resolution.d.ts +18 -0
  59. package/lib/artifacts/write-identity-resolution.js +165 -0
  60. package/lib/artifacts/write-mapping-definition.d.ts +17 -0
  61. package/lib/artifacts/write-mapping-definition.js +127 -0
  62. package/lib/artifacts/write-member-export.d.ts +88 -0
  63. package/lib/artifacts/write-member-export.js +199 -0
  64. package/lib/artifacts/write-native-calculated-insight.d.ts +21 -0
  65. package/lib/artifacts/write-native-calculated-insight.js +176 -0
  66. package/lib/artifacts/write-native-dmo.d.ts +11 -0
  67. package/lib/artifacts/write-native-dmo.js +158 -0
  68. package/lib/artifacts/write-native-mapping.d.ts +11 -0
  69. package/lib/artifacts/write-native-mapping.js +157 -0
  70. package/lib/artifacts/write-native-relationship.d.ts +11 -0
  71. package/lib/artifacts/write-native-relationship.js +157 -0
  72. package/lib/artifacts/write-segment.d.ts +26 -0
  73. package/lib/artifacts/write-segment.js +212 -0
  74. package/lib/commands/data360/delete.d.ts +280 -0
  75. package/lib/commands/data360/delete.js +2297 -0
  76. package/lib/commands/data360/deploy.d.ts +303 -0
  77. package/lib/commands/data360/deploy.js +2400 -0
  78. package/lib/commands/data360/publish.d.ts +93 -0
  79. package/lib/commands/data360/publish.js +292 -0
  80. package/lib/commands/data360/retrieve.d.ts +322 -0
  81. package/lib/commands/data360/retrieve.js +1963 -0
  82. package/lib/commands/data360/segment/members/export.d.ts +101 -0
  83. package/lib/commands/data360/segment/members/export.js +318 -0
  84. package/lib/errors/codes/calculated-insight.d.ts +2 -0
  85. package/lib/errors/codes/calculated-insight.js +25 -0
  86. package/lib/errors/codes/data-graph.d.ts +2 -0
  87. package/lib/errors/codes/data-graph.js +22 -0
  88. package/lib/errors/codes/data-stream.d.ts +2 -0
  89. package/lib/errors/codes/data-stream.js +70 -0
  90. package/lib/errors/codes/data-transform.d.ts +2 -0
  91. package/lib/errors/codes/data-transform.js +35 -0
  92. package/lib/errors/codes/dependency.d.ts +2 -0
  93. package/lib/errors/codes/dependency.js +11 -0
  94. package/lib/errors/codes/dlo.d.ts +2 -0
  95. package/lib/errors/codes/dlo.js +31 -0
  96. package/lib/errors/codes/dmo.d.ts +2 -0
  97. package/lib/errors/codes/dmo.js +28 -0
  98. package/lib/errors/codes/general.d.ts +2 -0
  99. package/lib/errors/codes/general.js +57 -0
  100. package/lib/errors/codes/identity-resolution.d.ts +2 -0
  101. package/lib/errors/codes/identity-resolution.js +24 -0
  102. package/lib/errors/codes/mapping.d.ts +2 -0
  103. package/lib/errors/codes/mapping.js +42 -0
  104. package/lib/errors/codes/relationship.d.ts +2 -0
  105. package/lib/errors/codes/relationship.js +21 -0
  106. package/lib/errors/codes/segment.d.ts +2 -0
  107. package/lib/errors/codes/segment.js +49 -0
  108. package/lib/errors/registry.d.ts +60 -0
  109. package/lib/errors/registry.js +123 -0
  110. package/lib/plugin.d.ts +5 -0
  111. package/lib/plugin.js +5 -0
  112. package/lib/services/acquire-retrieve-selection.d.ts +43 -0
  113. package/lib/services/acquire-retrieve-selection.js +145 -0
  114. package/lib/services/bind-identity-resolution-dependencies.d.ts +53 -0
  115. package/lib/services/bind-identity-resolution-dependencies.js +238 -0
  116. package/lib/services/bind-segment-dependencies.d.ts +49 -0
  117. package/lib/services/bind-segment-dependencies.js +115 -0
  118. package/lib/services/bounded-reads.d.ts +17 -0
  119. package/lib/services/bounded-reads.js +42 -0
  120. package/lib/services/calculated-insight-sql-checks.d.ts +33 -0
  121. package/lib/services/calculated-insight-sql-checks.js +193 -0
  122. package/lib/services/command-dlo.d.ts +48 -0
  123. package/lib/services/command-dlo.js +103 -0
  124. package/lib/services/command-native-data-graph.d.ts +54 -0
  125. package/lib/services/command-native-data-graph.js +485 -0
  126. package/lib/services/command-native-data-stream.d.ts +104 -0
  127. package/lib/services/command-native-data-stream.js +257 -0
  128. package/lib/services/command-native-dmo.d.ts +124 -0
  129. package/lib/services/command-native-dmo.js +338 -0
  130. package/lib/services/command-native-mapping.d.ts +65 -0
  131. package/lib/services/command-native-mapping.js +129 -0
  132. package/lib/services/command-native-relationship.d.ts +46 -0
  133. package/lib/services/command-native-relationship.js +103 -0
  134. package/lib/services/cross-dataspace-deploy.d.ts +111 -0
  135. package/lib/services/cross-dataspace-deploy.js +493 -0
  136. package/lib/services/cross-dataspace-rename.d.ts +74 -0
  137. package/lib/services/cross-dataspace-rename.js +1314 -0
  138. package/lib/services/cross-dataspace-sql.d.ts +109 -0
  139. package/lib/services/cross-dataspace-sql.js +1301 -0
  140. package/lib/services/cross-space-context.d.ts +23 -0
  141. package/lib/services/cross-space-context.js +36 -0
  142. package/lib/services/crud-plan.d.ts +137 -0
  143. package/lib/services/crud-plan.js +408 -0
  144. package/lib/services/data-space-check.d.ts +89 -0
  145. package/lib/services/data-space-check.js +162 -0
  146. package/lib/services/data-space-prefix.d.ts +77 -0
  147. package/lib/services/data-space-prefix.js +127 -0
  148. package/lib/services/data-transform-space.d.ts +31 -0
  149. package/lib/services/data-transform-space.js +79 -0
  150. package/lib/services/delete-calculated-insight.d.ts +44 -0
  151. package/lib/services/delete-calculated-insight.js +101 -0
  152. package/lib/services/delete-data-transform.d.ts +52 -0
  153. package/lib/services/delete-data-transform.js +222 -0
  154. package/lib/services/delete-dmo-field.d.ts +211 -0
  155. package/lib/services/delete-dmo-field.js +472 -0
  156. package/lib/services/delete-identity-resolution.d.ts +43 -0
  157. package/lib/services/delete-identity-resolution.js +295 -0
  158. package/lib/services/delete-segment.d.ts +42 -0
  159. package/lib/services/delete-segment.js +248 -0
  160. package/lib/services/deploy-result.d.ts +54 -0
  161. package/lib/services/deploy-result.js +60 -0
  162. package/lib/services/escaped-copy.d.ts +23 -0
  163. package/lib/services/escaped-copy.js +88 -0
  164. package/lib/services/execute-calculated-insight-deploy.d.ts +42 -0
  165. package/lib/services/execute-calculated-insight-deploy.js +96 -0
  166. package/lib/services/execute-data-transform-deploy.d.ts +56 -0
  167. package/lib/services/execute-data-transform-deploy.js +168 -0
  168. package/lib/services/execute-native-identity-resolution-deploy.d.ts +48 -0
  169. package/lib/services/execute-native-identity-resolution-deploy.js +360 -0
  170. package/lib/services/execute-segment-deploy.d.ts +45 -0
  171. package/lib/services/execute-segment-deploy.js +393 -0
  172. package/lib/services/local-file-removal.d.ts +36 -0
  173. package/lib/services/local-file-removal.js +103 -0
  174. package/lib/services/native-calculated-insight.d.ts +87 -0
  175. package/lib/services/native-calculated-insight.js +164 -0
  176. package/lib/services/native-crm-data-stream.d.ts +91 -0
  177. package/lib/services/native-crm-data-stream.js +272 -0
  178. package/lib/services/native-data-graph-context.d.ts +12 -0
  179. package/lib/services/native-data-graph-context.js +139 -0
  180. package/lib/services/native-data-graph-crd.d.ts +261 -0
  181. package/lib/services/native-data-graph-crd.js +866 -0
  182. package/lib/services/native-data-stream.d.ts +329 -0
  183. package/lib/services/native-data-stream.js +1830 -0
  184. package/lib/services/native-dlo.d.ts +163 -0
  185. package/lib/services/native-dlo.js +402 -0
  186. package/lib/services/native-dmo.d.ts +191 -0
  187. package/lib/services/native-dmo.js +614 -0
  188. package/lib/services/native-mapping.d.ts +255 -0
  189. package/lib/services/native-mapping.js +1226 -0
  190. package/lib/services/native-relationship.d.ts +132 -0
  191. package/lib/services/native-relationship.js +512 -0
  192. package/lib/services/operation-diagnostic.d.ts +83 -0
  193. package/lib/services/operation-diagnostic.js +272 -0
  194. package/lib/services/preflight-calculated-insight-deploy.d.ts +58 -0
  195. package/lib/services/preflight-calculated-insight-deploy.js +95 -0
  196. package/lib/services/preflight-data-transform-deploy.d.ts +33 -0
  197. package/lib/services/preflight-data-transform-deploy.js +104 -0
  198. package/lib/services/preflight-identity-resolution-deploy.d.ts +107 -0
  199. package/lib/services/preflight-identity-resolution-deploy.js +281 -0
  200. package/lib/services/preflight-segment-deploy.d.ts +31 -0
  201. package/lib/services/preflight-segment-deploy.js +109 -0
  202. package/lib/services/publish-calculated-insight.d.ts +40 -0
  203. package/lib/services/publish-calculated-insight.js +95 -0
  204. package/lib/services/publish-segment.d.ts +65 -0
  205. package/lib/services/publish-segment.js +194 -0
  206. package/lib/services/readback-pace.d.ts +16 -0
  207. package/lib/services/readback-pace.js +23 -0
  208. package/lib/services/retrieve-data-transform.d.ts +26 -0
  209. package/lib/services/retrieve-data-transform.js +65 -0
  210. package/lib/services/retrieve-identity-resolution.d.ts +40 -0
  211. package/lib/services/retrieve-identity-resolution.js +87 -0
  212. package/lib/services/retrieve-inventory.d.ts +32 -0
  213. package/lib/services/retrieve-inventory.js +151 -0
  214. package/lib/services/retrieve-segment.d.ts +120 -0
  215. package/lib/services/retrieve-segment.js +502 -0
  216. package/lib/services/segment-lookup.d.ts +46 -0
  217. package/lib/services/segment-lookup.js +108 -0
  218. package/lib/services/segment-members.d.ts +144 -0
  219. package/lib/services/segment-members.js +402 -0
  220. package/lib/services/select-native-retrieve.d.ts +60 -0
  221. package/lib/services/select-native-retrieve.js +226 -0
  222. package/lib/services/settle-calculated-insight.d.ts +22 -0
  223. package/lib/services/settle-calculated-insight.js +53 -0
  224. package/lib/services/sql-tokens.d.ts +58 -0
  225. package/lib/services/sql-tokens.js +147 -0
  226. package/lib/transport/api-version.d.ts +36 -0
  227. package/lib/transport/api-version.js +89 -0
  228. package/lib/transport/bound-ssot.d.ts +27 -0
  229. package/lib/transport/bound-ssot.js +116 -0
  230. package/lib/transport/calculated-insight-rest.d.ts +28 -0
  231. package/lib/transport/calculated-insight-rest.js +62 -0
  232. package/lib/transport/connect-client.d.ts +129 -0
  233. package/lib/transport/connect-client.js +446 -0
  234. package/lib/transport/connect-diagnostic.d.ts +89 -0
  235. package/lib/transport/connect-diagnostic.js +331 -0
  236. package/lib/transport/data-graph-rest.d.ts +27 -0
  237. package/lib/transport/data-graph-rest.js +76 -0
  238. package/lib/transport/data-stream-rest.d.ts +62 -0
  239. package/lib/transport/data-stream-rest.js +348 -0
  240. package/lib/transport/data-transform-rest.d.ts +25 -0
  241. package/lib/transport/data-transform-rest.js +100 -0
  242. package/lib/transport/dlo-native-rest.d.ts +22 -0
  243. package/lib/transport/dlo-native-rest.js +89 -0
  244. package/lib/transport/dlo-rest.d.ts +23 -0
  245. package/lib/transport/dlo-rest.js +135 -0
  246. package/lib/transport/dmo-native-rest.d.ts +18 -0
  247. package/lib/transport/dmo-native-rest.js +55 -0
  248. package/lib/transport/dmo-rest.d.ts +30 -0
  249. package/lib/transport/dmo-rest.js +163 -0
  250. package/lib/transport/mapping-rest.d.ts +63 -0
  251. package/lib/transport/mapping-rest.js +341 -0
  252. package/lib/transport/project-metadata.d.ts +36 -0
  253. package/lib/transport/project-metadata.js +118 -0
  254. package/lib/transport/relationship-rest.d.ts +43 -0
  255. package/lib/transport/relationship-rest.js +201 -0
  256. package/package.json +96 -4
@@ -0,0 +1,203 @@
1
+ /**
2
+ * The normal document kind of each family. A verbatim document carries the kind of the document
3
+ * it stands in for, so it lives at the same path and a later retrieve replaces it cleanly.
4
+ */
5
+ export type VerbatimKind = 'dlo' | 'dmo' | 'mapping' | 'relationship' | 'data-stream' | 'data-transform' | 'native-data-graph' | 'calculated-insight' | 'identity-resolution' | 'segment';
6
+ /** Kinds whose files carry their data space in the top-level `c__dataSpace` key. */
7
+ export type SpaceFieldVerbatimKind = 'dmo' | 'mapping' | 'relationship' | 'calculated-insight' | 'segment' | 'data-transform' | 'native-data-graph' | 'identity-resolution';
8
+ /**
9
+ * Whether a kind's file carries its data space in a single `c__dataSpace` (every kind but the
10
+ * DLO and the data stream, whose files list several and whose verbatim files keep
11
+ * `identity.dataSpace`).
12
+ * @param {string} kind Document kind.
13
+ * @returns {boolean} The kind uses `c__dataSpace`.
14
+ */
15
+ export declare function usesDataSpaceField(kind: string): kind is SpaceFieldVerbatimKind;
16
+ /**
17
+ * An org object written as Salesforce returned it, because the plugin cannot represent it.
18
+ * `native` is the raw GET response with its keys sorted recursively. Deploy never sends it.
19
+ * Every kind but the DLO and the data stream carries its data space in `c__dataSpace`, like its
20
+ * normal file.
21
+ */
22
+ export type VerbatimDocument = {
23
+ schemaVersion: 1;
24
+ kind: Exclude<VerbatimKind, SpaceFieldVerbatimKind>;
25
+ identity: {
26
+ dataSpace: string;
27
+ apiName: string;
28
+ };
29
+ verbatim: {
30
+ reason: string;
31
+ native: unknown;
32
+ };
33
+ } | {
34
+ schemaVersion: 1;
35
+ kind: SpaceFieldVerbatimKind;
36
+ c__dataSpace: string;
37
+ identity: {
38
+ apiName: string;
39
+ };
40
+ verbatim: {
41
+ reason: string;
42
+ native: unknown;
43
+ };
44
+ };
45
+ /**
46
+ * The data space of a verbatim document, wherever its kind keeps it.
47
+ * @param {VerbatimDocument} document Verbatim document.
48
+ * @returns {string} Its data space.
49
+ */
50
+ export declare function verbatimDataSpace(document: VerbatimDocument): string;
51
+ /**
52
+ * The identity of a verbatim document as results report it: its data space and name.
53
+ * @param {VerbatimDocument} document Verbatim document.
54
+ * @returns {{dataSpace: string; apiName: string}} Reported identity.
55
+ */
56
+ export declare function verbatimIdentity(document: VerbatimDocument): {
57
+ dataSpace: string;
58
+ apiName: string;
59
+ };
60
+ /** Reason of a verbatim file whose projection failed without a usable error code. */
61
+ export declare const unmodelledResponseReason = "UNMODELLED_RESPONSE";
62
+ /**
63
+ * How strictly a document is checked: `deploy` (the default everywhere) admits only what the
64
+ * plugin can send; `retrieve` keeps what the org returned and checks only what names and places
65
+ * the file, so the deploy of such a file refuses and names the key.
66
+ */
67
+ export type DocumentMode = 'retrieve' | 'deploy';
68
+ /**
69
+ * A copy of a JSON value with the keys of every object sorted; array order is kept.
70
+ * @param {unknown} value JSON value.
71
+ * @returns {unknown} Copy with sorted keys.
72
+ */
73
+ export declare function sortKeysDeep(value: unknown): unknown;
74
+ /**
75
+ * Whether a value is a verbatim document, optionally of one kind.
76
+ * @param {unknown} value Candidate.
77
+ * @param {VerbatimKind} [kind] Required kind.
78
+ * @returns {boolean} Exact verbatim shape.
79
+ */
80
+ export declare function isVerbatimDocument<K extends VerbatimKind = VerbatimKind>(value: unknown, kind?: K): value is VerbatimDocument & {
81
+ kind: K;
82
+ };
83
+ /**
84
+ * Build a verbatim document, or undefined when the name, data space or reason is unusable (the
85
+ * item then stays a failure).
86
+ * @param {VerbatimKind} kind Normal document kind.
87
+ * @param {object} identity Normal identity.
88
+ * @param {string} identity.dataSpace Data space.
89
+ * @param {string} identity.apiName API name.
90
+ * @param {string} reason Error code of the refused projection.
91
+ * @param {unknown} [native] Raw GET response (none for a delete by name: written as null).
92
+ * @returns {VerbatimDocument | undefined} Document with sorted native keys.
93
+ */
94
+ export declare function createVerbatimDocument(kind: VerbatimKind, identity: {
95
+ dataSpace: string;
96
+ apiName: string;
97
+ }, reason: string, native?: unknown): VerbatimDocument | undefined;
98
+ /**
99
+ * File bytes of a verbatim document: two-space JSON with a final line break.
100
+ * @param {VerbatimDocument} document Verbatim document.
101
+ * @returns {string} JSON text.
102
+ */
103
+ export declare function serializeVerbatimDocument(document: VerbatimDocument): string;
104
+ /**
105
+ * The verbatim document in JSON text, if it is one.
106
+ * @param {string} text File text.
107
+ * @returns {VerbatimDocument | undefined} Verbatim document, or undefined for anything else.
108
+ */
109
+ export declare function parseVerbatimDocument(text: string): VerbatimDocument | undefined;
110
+ /**
111
+ * Family name of a kind, as selectors and messages use it.
112
+ * @param {VerbatimKind} kind Document kind.
113
+ * @returns {string} Family such as `data-graph`.
114
+ */
115
+ export declare function verbatimFamily(kind: VerbatimKind): string;
116
+ /**
117
+ * Why deploy and publish refuse a verbatim file that was named explicitly.
118
+ * @param {VerbatimDocument} document Verbatim document.
119
+ * @returns {string} Message naming kind, name and reason.
120
+ */
121
+ export declare function verbatimRefusalMessage(document: VerbatimDocument): string;
122
+ /**
123
+ * Warning for a verbatim file that a folder or Git-range deploy left out.
124
+ * @param {VerbatimDocument} document Verbatim document.
125
+ * @param {string} file File path.
126
+ * @returns {string} Warning text.
127
+ */
128
+ export declare function verbatimSkipWarning(document: VerbatimDocument, file: string): string;
129
+ /**
130
+ * Remember the raw GET response an object (a projected document, an acquisition or an error) was
131
+ * built from, so a later projection or validation failure can still write it verbatim.
132
+ * @template T
133
+ * @param {T} carrier Object.
134
+ * @param {unknown} native Raw GET response.
135
+ * @returns {T} The same object.
136
+ */
137
+ export declare function carryNativeResponse<T>(carrier: T, native: unknown): T;
138
+ /**
139
+ * The raw GET response remembered for an object.
140
+ * @param {unknown} carrier Object.
141
+ * @returns {{native: unknown} | undefined} Response, or undefined when none was remembered.
142
+ */
143
+ export declare function carriedNativeResponse(carrier: unknown): {
144
+ native: unknown;
145
+ } | undefined;
146
+ /** The raw GET responses read through wrapped clients, by name. */
147
+ export type NativeReadRecorder = {
148
+ /** Wrap a client; its first successful `get` of each name is remembered. */
149
+ wrap: <T>(client: T) => T;
150
+ nativeOf: (name: string) => {
151
+ native: unknown;
152
+ } | undefined;
153
+ };
154
+ /**
155
+ * Remember the first successful `get` of each name through the clients it wraps. A client
156
+ * without `get` is returned unchanged; every other member is reached through the prototype.
157
+ * @param {(response: unknown) => {native: unknown} | undefined} [pick] The raw response inside
158
+ * a read result, or undefined when the read did not succeed.
159
+ * @returns {NativeReadRecorder} Recorder.
160
+ */
161
+ export declare function nativeReadRecorder(pick?: (response: unknown) => {
162
+ native: unknown;
163
+ } | undefined): NativeReadRecorder;
164
+ /**
165
+ * Wrap one read client so the first successful `get` of each name is remembered.
166
+ * @template T
167
+ * @param {T} client Read client.
168
+ * @param {(response: unknown) => {native: unknown} | undefined} [pick] The raw response inside
169
+ * a read result, or undefined when the read did not succeed.
170
+ * @returns {{client: T; nativeOf: (name: string) => {native: unknown} | undefined}} Wrapped client.
171
+ */
172
+ export declare function recordNativeReads<T>(client: T, pick?: (response: unknown) => {
173
+ native: unknown;
174
+ } | undefined): {
175
+ client: T;
176
+ nativeOf: (name: string) => {
177
+ native: unknown;
178
+ } | undefined;
179
+ };
180
+ /**
181
+ * The reason a failed projection or validation is written verbatim: the error's code, or
182
+ * `UNMODELLED_RESPONSE` when it has none (such as a TypeError on an unexpected shape). HTTP and
183
+ * Connect errors, local system errors, and the item-failure codes above stay item failures.
184
+ * @param {unknown} error Caught error.
185
+ * @returns {string | undefined} Reason code, or undefined when the item stays a failure.
186
+ */
187
+ export declare function verbatimReason(error: unknown): string | undefined;
188
+ /**
189
+ * Identity of the file a writer is about to replace: the strict document's when it validates,
190
+ * otherwise a verbatim file's or a non-strict JSON object's (`{}` when it names none). Text that
191
+ * is not a JSON object is refused with the strict validator's error.
192
+ * @param {string} text Existing file text.
193
+ * @param {(value: unknown) => {dataSpace?: string; apiName?: string}} strict Strict validator,
194
+ * returning the identity.
195
+ * @returns {{dataSpace?: string; apiName?: string}} Identity of the existing file.
196
+ */
197
+ export declare function previousIdentity(text: string, strict: (value: unknown) => {
198
+ dataSpace?: string;
199
+ apiName?: string;
200
+ }): {
201
+ dataSpace?: string;
202
+ apiName?: string;
203
+ };
@@ -0,0 +1,339 @@
1
+ import { getConnectDiagnostic } from '../transport/connect-diagnostic.js';
2
+ import { dataSpaceKey } from './data-space-field.js';
3
+ const spaceFieldKinds = new Set([
4
+ 'dmo',
5
+ 'mapping',
6
+ 'relationship',
7
+ 'calculated-insight',
8
+ 'segment',
9
+ 'data-transform',
10
+ 'native-data-graph',
11
+ 'identity-resolution',
12
+ ]);
13
+ /**
14
+ * Whether a kind's file carries its data space in a single `c__dataSpace` (every kind but the
15
+ * DLO and the data stream, whose files list several and whose verbatim files keep
16
+ * `identity.dataSpace`).
17
+ * @param {string} kind Document kind.
18
+ * @returns {boolean} The kind uses `c__dataSpace`.
19
+ */
20
+ export function usesDataSpaceField(kind) {
21
+ return spaceFieldKinds.has(kind);
22
+ }
23
+ /**
24
+ * The data space of a verbatim document, wherever its kind keeps it.
25
+ * @param {VerbatimDocument} document Verbatim document.
26
+ * @returns {string} Its data space.
27
+ */
28
+ export function verbatimDataSpace(document) {
29
+ return 'c__dataSpace' in document ? document.c__dataSpace : document.identity.dataSpace;
30
+ }
31
+ /**
32
+ * The identity of a verbatim document as results report it: its data space and name.
33
+ * @param {VerbatimDocument} document Verbatim document.
34
+ * @returns {{dataSpace: string; apiName: string}} Reported identity.
35
+ */
36
+ export function verbatimIdentity(document) {
37
+ return { dataSpace: verbatimDataSpace(document), apiName: document.identity.apiName };
38
+ }
39
+ const kinds = new Set([
40
+ 'dlo',
41
+ 'dmo',
42
+ 'mapping',
43
+ 'relationship',
44
+ 'data-stream',
45
+ 'data-transform',
46
+ 'native-data-graph',
47
+ 'calculated-insight',
48
+ 'identity-resolution',
49
+ 'segment',
50
+ ]);
51
+ // File-name safe: no separators, dots or spaces, so the normal path stays inside its folder.
52
+ const safeName = /^[A-Za-z0-9_]{1,255}$/u;
53
+ const safeReason = /^[A-Z][A-Z0-9_]{0,99}$/u;
54
+ // Codes that stay item failures. On the GET of the item itself: absence, a name or identity
55
+ // that differs from the selected one (`*_IDENTITY_MISMATCH`, `*_TARGET_MISMATCH`,
56
+ // `*_NAME_MISMATCH`, `IDENTITY_CHANGED`) and data-space scope (every `*DATASPACE*` code such as
57
+ // `UNSUPPORTED_DLO_DATASPACE`, and `INVALID_SCOPE`). Around the projection, never about the
58
+ // response's content: HTTP and read failures, dependency binding, target org, selection, project,
59
+ // path and output checks. Read-state codes say the org was caught mid-change or an inventory was
60
+ // not complete (`INCOMPLETE*`, `*PENDING`, `PROCESSING_ACKNOWLEDGEMENT_REQUIRED`, `*_DRIFT` between
61
+ // two reads); they are not about the content either. Two drift codes are lasting content the plugin
62
+ // cannot model and stay verbatim reasons: `STREAM_DLO_DRIFT` (the DLO's fields differ from the
63
+ // stream's) and `STREAM_SOURCE_DRIFT` (the stream's source fields differ from its event schema). Every other check (including variant checks such as
64
+ // `STREAM_CONNECTION_MISMATCH`, a connection that is not CONNECTED) writes the GET verbatim.
65
+ const itemFailure = /DATASPACE|NOT_FOUND|IDENTITY_MISMATCH|TARGET_MISMATCH|NAME_MISMATCH|IDENTITY_CHANGED|DEPENDENCY|TARGET_ORG|HTTP|RUNTIME_UNKNOWN|INVALID_SCOPE|INVALID_SELECTION|UNSAFE|OUTPUT|OVERWRITE|PARTIAL|COLLISION|LIMIT_EXCEEDED|ACQUISITION_FAILED|RETRIEVE_FAILED|INCOMPLETE|PENDING|PROCESSING_ACKNOWLEDGEMENT|(?<!STREAM_DLO_|STREAM_SOURCE_)DRIFT/u;
66
+ /** Reason of a verbatim file whose projection failed without a usable error code. */
67
+ export const unmodelledResponseReason = 'UNMODELLED_RESPONSE';
68
+ /**
69
+ * Whether a value is a plain JSON object.
70
+ * @param {unknown} value Candidate.
71
+ * @returns {boolean} Object and not an array.
72
+ */
73
+ function isBag(value) {
74
+ return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
75
+ }
76
+ /**
77
+ * Whether an object has exactly these own keys.
78
+ * @param {Bag} value Object.
79
+ * @param {string[]} keys Expected keys.
80
+ * @returns {boolean} Exact key set.
81
+ */
82
+ function exactKeys(value, keys) {
83
+ const own = Object.keys(value);
84
+ return own.length === keys.length && keys.every((key) => Object.hasOwn(value, key));
85
+ }
86
+ /**
87
+ * A copy of a JSON value with the keys of every object sorted; array order is kept.
88
+ * @param {unknown} value JSON value.
89
+ * @returns {unknown} Copy with sorted keys.
90
+ */
91
+ export function sortKeysDeep(value) {
92
+ if (Array.isArray(value))
93
+ return value.map((entry) => sortKeysDeep(entry));
94
+ if (!isBag(value))
95
+ return value;
96
+ // eslint-disable-next-line unicorn/no-array-sort -- Sort a fresh key array within the ES2022 library target.
97
+ const keys = Object.keys(value).sort();
98
+ return Object.fromEntries(keys.map((key) => [key, sortKeysDeep(value[key])]));
99
+ }
100
+ /**
101
+ * Whether a value is a verbatim document, optionally of one kind.
102
+ * @param {unknown} value Candidate.
103
+ * @param {VerbatimKind} [kind] Required kind.
104
+ * @returns {boolean} Exact verbatim shape.
105
+ */
106
+ export function isVerbatimDocument(value, kind) {
107
+ if (!isBag(value) || typeof value.kind !== 'string')
108
+ return false;
109
+ const field = usesDataSpaceField(value.kind);
110
+ if (!exactKeys(value, field
111
+ ? ['schemaVersion', 'kind', dataSpaceKey, 'identity', 'verbatim']
112
+ : ['schemaVersion', 'kind', 'identity', 'verbatim']))
113
+ return false;
114
+ const { identity, verbatim } = value;
115
+ const dataSpace = field ? value[dataSpaceKey] : isBag(identity) ? identity.dataSpace : undefined;
116
+ return (value.schemaVersion === 1 &&
117
+ kinds.has(value.kind) &&
118
+ (kind === undefined || value.kind === kind) &&
119
+ isBag(identity) &&
120
+ exactKeys(identity, field ? ['apiName'] : ['dataSpace', 'apiName']) &&
121
+ typeof dataSpace === 'string' &&
122
+ safeName.test(dataSpace) &&
123
+ typeof identity.apiName === 'string' &&
124
+ safeName.test(identity.apiName) &&
125
+ isBag(verbatim) &&
126
+ exactKeys(verbatim, ['reason', 'native']) &&
127
+ typeof verbatim.reason === 'string' &&
128
+ safeReason.test(verbatim.reason));
129
+ }
130
+ /**
131
+ * Build a verbatim document, or undefined when the name, data space or reason is unusable (the
132
+ * item then stays a failure).
133
+ * @param {VerbatimKind} kind Normal document kind.
134
+ * @param {object} identity Normal identity.
135
+ * @param {string} identity.dataSpace Data space.
136
+ * @param {string} identity.apiName API name.
137
+ * @param {string} reason Error code of the refused projection.
138
+ * @param {unknown} [native] Raw GET response (none for a delete by name: written as null).
139
+ * @returns {VerbatimDocument | undefined} Document with sorted native keys.
140
+ */
141
+ export function createVerbatimDocument(kind, identity, reason, native) {
142
+ // eslint-disable-next-line unicorn/no-null -- An empty response is written as JSON null.
143
+ const verbatim = { reason, native: sortKeysDeep(native ?? null) };
144
+ const document = usesDataSpaceField(kind)
145
+ ? {
146
+ schemaVersion: 1,
147
+ kind,
148
+ [dataSpaceKey]: identity.dataSpace,
149
+ identity: { apiName: identity.apiName },
150
+ verbatim,
151
+ }
152
+ : {
153
+ schemaVersion: 1,
154
+ kind,
155
+ identity: { dataSpace: identity.dataSpace, apiName: identity.apiName },
156
+ verbatim,
157
+ };
158
+ return isVerbatimDocument(document) ? document : undefined;
159
+ }
160
+ /**
161
+ * File bytes of a verbatim document: two-space JSON with a final line break.
162
+ * @param {VerbatimDocument} document Verbatim document.
163
+ * @returns {string} JSON text.
164
+ */
165
+ export function serializeVerbatimDocument(document) {
166
+ return `${JSON.stringify({
167
+ schemaVersion: 1,
168
+ kind: document.kind,
169
+ ...('c__dataSpace' in document
170
+ ? {
171
+ [dataSpaceKey]: document.c__dataSpace,
172
+ identity: { apiName: document.identity.apiName },
173
+ }
174
+ : {
175
+ identity: {
176
+ dataSpace: document.identity.dataSpace,
177
+ apiName: document.identity.apiName,
178
+ },
179
+ }),
180
+ verbatim: {
181
+ reason: document.verbatim.reason,
182
+ native: sortKeysDeep(document.verbatim.native),
183
+ },
184
+ }, undefined, 2)}\n`;
185
+ }
186
+ /**
187
+ * The verbatim document in JSON text, if it is one.
188
+ * @param {string} text File text.
189
+ * @returns {VerbatimDocument | undefined} Verbatim document, or undefined for anything else.
190
+ */
191
+ export function parseVerbatimDocument(text) {
192
+ try {
193
+ const value = JSON.parse(text);
194
+ return isVerbatimDocument(value) ? value : undefined;
195
+ }
196
+ catch {
197
+ return undefined;
198
+ }
199
+ }
200
+ /**
201
+ * Family name of a kind, as selectors and messages use it.
202
+ * @param {VerbatimKind} kind Document kind.
203
+ * @returns {string} Family such as `data-graph`.
204
+ */
205
+ export function verbatimFamily(kind) {
206
+ return kind === 'native-data-graph' ? 'data-graph' : kind;
207
+ }
208
+ /**
209
+ * Why deploy and publish refuse a verbatim file that was named explicitly.
210
+ * @param {VerbatimDocument} document Verbatim document.
211
+ * @returns {string} Message naming kind, name and reason.
212
+ */
213
+ export function verbatimRefusalMessage(document) {
214
+ return `The ${verbatimFamily(document.kind)} ${document.identity.apiName} was retrieved as-is (verbatim, reason ${document.verbatim.reason}) because the plugin cannot represent it, so it cannot be deployed or published. Change it in the org, or deploy a file the plugin can represent.`;
215
+ }
216
+ /**
217
+ * Warning for a verbatim file that a folder or Git-range deploy left out.
218
+ * @param {VerbatimDocument} document Verbatim document.
219
+ * @param {string} file File path.
220
+ * @returns {string} Warning text.
221
+ */
222
+ export function verbatimSkipWarning(document, file) {
223
+ return `Skipped ${file}: the ${verbatimFamily(document.kind)} ${document.identity.apiName} was retrieved as-is (verbatim, reason ${document.verbatim.reason}) and cannot be deployed.`;
224
+ }
225
+ const carried = new WeakMap();
226
+ /**
227
+ * Remember the raw GET response an object (a projected document, an acquisition or an error) was
228
+ * built from, so a later projection or validation failure can still write it verbatim.
229
+ * @template T
230
+ * @param {T} carrier Object.
231
+ * @param {unknown} native Raw GET response.
232
+ * @returns {T} The same object.
233
+ */
234
+ export function carryNativeResponse(carrier, native) {
235
+ if (carrier && typeof carrier === 'object')
236
+ carried.set(carrier, { native });
237
+ return carrier;
238
+ }
239
+ /**
240
+ * The raw GET response remembered for an object.
241
+ * @param {unknown} carrier Object.
242
+ * @returns {{native: unknown} | undefined} Response, or undefined when none was remembered.
243
+ */
244
+ export function carriedNativeResponse(carrier) {
245
+ return carrier && typeof carrier === 'object' ? carried.get(carrier) : undefined;
246
+ }
247
+ /**
248
+ * Remember the first successful `get` of each name through the clients it wraps. A client
249
+ * without `get` is returned unchanged; every other member is reached through the prototype.
250
+ * @param {(response: unknown) => {native: unknown} | undefined} [pick] The raw response inside
251
+ * a read result, or undefined when the read did not succeed.
252
+ * @returns {NativeReadRecorder} Recorder.
253
+ */
254
+ export function nativeReadRecorder(pick = (response) => ({
255
+ native: response,
256
+ })) {
257
+ const reads = new Map();
258
+ const wrap = (client) => {
259
+ if (!client || typeof client !== 'object')
260
+ return client;
261
+ const original = client.get;
262
+ if (typeof original !== 'function')
263
+ return client;
264
+ const wrapped = Object.create(client);
265
+ wrapped.get = async (name, ...rest) => {
266
+ const response = await original.call(client, name, ...rest);
267
+ if (typeof name === 'string' && !reads.has(name)) {
268
+ const picked = pick(response);
269
+ if (picked)
270
+ reads.set(name, picked);
271
+ }
272
+ return response;
273
+ };
274
+ return wrapped;
275
+ };
276
+ return { wrap, nativeOf: (name) => reads.get(name) };
277
+ }
278
+ /**
279
+ * Wrap one read client so the first successful `get` of each name is remembered.
280
+ * @template T
281
+ * @param {T} client Read client.
282
+ * @param {(response: unknown) => {native: unknown} | undefined} [pick] The raw response inside
283
+ * a read result, or undefined when the read did not succeed.
284
+ * @returns {{client: T; nativeOf: (name: string) => {native: unknown} | undefined}} Wrapped client.
285
+ */
286
+ export function recordNativeReads(client, pick) {
287
+ const recorder = nativeReadRecorder(pick);
288
+ return { client: recorder.wrap(client), nativeOf: recorder.nativeOf };
289
+ }
290
+ /**
291
+ * The reason a failed projection or validation is written verbatim: the error's code, or
292
+ * `UNMODELLED_RESPONSE` when it has none (such as a TypeError on an unexpected shape). HTTP and
293
+ * Connect errors, local system errors, and the item-failure codes above stay item failures.
294
+ * @param {unknown} error Caught error.
295
+ * @returns {string | undefined} Reason code, or undefined when the item stays a failure.
296
+ */
297
+ export function verbatimReason(error) {
298
+ if (!(error instanceof Error))
299
+ return unmodelledResponseReason;
300
+ if (error.name === 'ConnectError')
301
+ return undefined;
302
+ const { code, status, statusCode, syscall } = error;
303
+ if (typeof status === 'number' || typeof statusCode === 'number')
304
+ return undefined;
305
+ if (getConnectDiagnostic(error))
306
+ return undefined;
307
+ // A local file-system error (EPERM, ENOENT) is not about the response.
308
+ if (typeof syscall === 'string')
309
+ return undefined;
310
+ if (typeof code !== 'string' || !safeReason.test(code))
311
+ return unmodelledResponseReason;
312
+ return itemFailure.test(code) ? undefined : code;
313
+ }
314
+ /**
315
+ * Identity of the file a writer is about to replace: the strict document's when it validates,
316
+ * otherwise a verbatim file's or a non-strict JSON object's (`{}` when it names none). Text that
317
+ * is not a JSON object is refused with the strict validator's error.
318
+ * @param {string} text Existing file text.
319
+ * @param {(value: unknown) => {dataSpace?: string; apiName?: string}} strict Strict validator,
320
+ * returning the identity.
321
+ * @returns {{dataSpace?: string; apiName?: string}} Identity of the existing file.
322
+ */
323
+ export function previousIdentity(text, strict) {
324
+ const value = JSON.parse(text);
325
+ try {
326
+ return strict(value);
327
+ }
328
+ catch (error) {
329
+ if (!isBag(value))
330
+ throw error;
331
+ const { identity } = value;
332
+ if (!isBag(identity))
333
+ return {};
334
+ return {
335
+ ...(typeof identity.dataSpace === 'string' ? { dataSpace: identity.dataSpace } : {}),
336
+ ...(typeof identity.apiName === 'string' ? { apiName: identity.apiName } : {}),
337
+ };
338
+ }
339
+ }
@@ -0,0 +1,17 @@
1
+ import { link, rename, unlink } from 'node:fs/promises';
2
+ /**
3
+ * Publish native Graph JSON only, with owned OS-temp staging and no-clobber publication.
4
+ * @param {unknown} value Complete portable document.
5
+ * @param {string} projectRoot Absolute output project root.
6
+ * @param {boolean} overwrite Permit differing existing bytes.
7
+ * @param {object} publish Native publication seam for offline failure tests.
8
+ * @returns {Promise<{path: string; outcome: 'retrieved' | 'unchanged'}>} Receipt.
9
+ */
10
+ export declare function writeDataGraphDocument(value: unknown, projectRoot: string, overwrite: boolean, publish?: {
11
+ link: typeof link;
12
+ rename: typeof rename;
13
+ unlink: typeof unlink;
14
+ }): Promise<{
15
+ path: string;
16
+ outcome: 'retrieved' | 'unchanged';
17
+ }>;