@wpkernel/pipeline 0.12.1-beta.0 → 0.12.2-beta.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 (43) hide show
  1. package/README.md +15 -0
  2. package/dist/createExtension.d.ts +4 -3
  3. package/dist/createExtension.d.ts.map +1 -1
  4. package/dist/createExtension.js +20 -11
  5. package/dist/createPipeline.d.ts +28 -188
  6. package/dist/createPipeline.d.ts.map +1 -1
  7. package/dist/createPipeline.js +81 -402
  8. package/dist/extensions/index.d.ts +3 -0
  9. package/dist/extensions/index.d.ts.map +1 -0
  10. package/dist/extensions/index.js +8 -0
  11. package/dist/extensions/official.d.ts +73 -0
  12. package/dist/extensions/official.d.ts.map +1 -0
  13. package/dist/extensions/official.js +111 -0
  14. package/dist/extensions.d.ts +6 -2
  15. package/dist/extensions.d.ts.map +1 -1
  16. package/dist/extensions.js +50 -45
  17. package/dist/index.d.ts +3 -1
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +18 -16
  20. package/dist/internal/diagnostic-manager.d.ts +29 -0
  21. package/dist/internal/diagnostic-manager.d.ts.map +1 -0
  22. package/dist/internal/diagnostic-manager.js +94 -0
  23. package/dist/internal/diagnostic-manager.types.d.ts +70 -0
  24. package/dist/internal/diagnostic-manager.types.d.ts.map +1 -0
  25. package/dist/internal/extension-coordinator.d.ts +21 -0
  26. package/dist/internal/extension-coordinator.d.ts.map +1 -0
  27. package/dist/internal/extension-coordinator.js +55 -0
  28. package/dist/internal/extension-coordinator.types.d.ts +42 -0
  29. package/dist/internal/extension-coordinator.types.d.ts.map +1 -0
  30. package/dist/internal/helper-execution.d.ts +32 -0
  31. package/dist/internal/helper-execution.d.ts.map +1 -0
  32. package/dist/internal/helper-execution.js +37 -0
  33. package/dist/internal/pipeline-runner.d.ts +18 -0
  34. package/dist/internal/pipeline-runner.d.ts.map +1 -0
  35. package/dist/internal/pipeline-runner.js +261 -0
  36. package/dist/internal/pipeline-runner.types.d.ts +79 -0
  37. package/dist/internal/pipeline-runner.types.d.ts.map +1 -0
  38. package/dist/registration.d.ts +3 -2
  39. package/dist/registration.d.ts.map +1 -1
  40. package/dist/registration.js +38 -27
  41. package/dist/types.d.ts +14 -1
  42. package/dist/types.d.ts.map +1 -1
  43. package/package.json +8 -3
@@ -1,447 +1,126 @@
1
- import { maybeThen as M, maybeTry as Q } from "./async-utils.js";
2
- import { createDependencyGraph as X } from "./dependency-graph.js";
3
- import { runExtensionHooks as ie, rollbackExtensionResults as ce, commitExtensionResults as ae, createRollbackErrorMetadata as Y } from "./extensions.js";
4
- import { executeHelpers as Z } from "./executor.js";
5
- import { registerHelper as _, handleExtensionRegisterResult as ue } from "./registration.js";
1
+ import { maybeThen as E, isPromiseLike as h } from "./async-utils.js";
2
+ import { registerHelper as v, handleExtensionRegisterResult as w } from "./registration.js";
3
+ import { initDiagnosticManager as V } from "./internal/diagnostic-manager.js";
4
+ import { initPipelineRunner as $ } from "./internal/pipeline-runner.js";
6
5
  /**
7
6
  * @wpkernel/pipeline
8
7
  * @license EUPL-1.2
9
8
  */
10
- function ye(c) {
11
- const b = c.fragmentKind ?? "fragment", m = c.builderKind ?? "builder", h = c.createError ?? ((e, n) => new Error(`[${e}] ${n}`)), E = [], y = [], S = [], G = /* @__PURE__ */ new WeakMap();
12
- let H;
13
- const v = [], l = b, p = m;
14
- function C(e, n) {
15
- return e === l ? `Fragment helper "${n.key}"` : e === p ? `Builder helper "${n.key}"` : `Helper "${n.key}"`;
16
- }
17
- function P(e, n, t, r) {
18
- const a = c.createConflictDiagnostic?.({
19
- helper: e,
20
- existing: n,
21
- message: r
22
- }) ?? {
23
- type: "conflict",
24
- key: e.key,
25
- mode: e.mode,
26
- helpers: [
27
- n.origin ?? n.key,
28
- e.origin ?? e.key
29
- ],
30
- message: r,
31
- kind: t
32
- };
33
- O(a);
34
- }
35
- function q(e, n, t) {
36
- const r = `${C(t, e)} depends on unknown helper "${n}".`, a = c.createMissingDependencyDiagnostic?.({
37
- helper: e,
38
- dependency: n,
39
- message: r
40
- }) ?? {
41
- type: "missing-dependency",
42
- key: e.key,
43
- dependency: n,
44
- message: r,
45
- kind: t,
46
- helper: e.origin ?? e.key
47
- };
48
- O(a);
49
- }
50
- function D(e, n, t, r) {
51
- const a = `${C(n, e)} ${t}.`, u = c.createUnusedHelperDiagnostic?.({
52
- helper: e,
53
- message: a
54
- }) ?? {
55
- type: "unused-helper",
56
- key: e.key,
57
- message: a,
58
- kind: n,
59
- helper: e.origin ?? e.key,
60
- dependsOn: r
61
- };
62
- O(u);
63
- }
64
- function T(e) {
65
- if (!H || !c.onDiagnostic)
66
- return;
67
- const n = G.get(H);
68
- if (n?.has(e))
69
- return;
70
- const t = n ?? /* @__PURE__ */ new Set();
71
- c.onDiagnostic({
72
- reporter: H,
73
- diagnostic: e
74
- }), t.add(e), n || G.set(H, t);
75
- }
76
- function O(e) {
77
- S.push(e), T(e);
78
- }
79
- function W(e, n, t) {
80
- for (const r of e)
81
- n.has(r.id) || D(
82
- r.helper,
83
- t,
84
- "was registered but never executed",
85
- r.helper.dependsOn
86
- );
87
- }
88
- function A(e, n, t) {
89
- const r = [], a = [], u = [];
90
- for (const k of e) {
91
- const f = k.helper.key;
92
- r.push(f), n.has(k.id) ? a.push(f) : u.push(f);
93
- }
94
- return {
95
- kind: t,
96
- registered: r,
97
- executed: a,
98
- missing: u
99
- };
100
- }
101
- function j(e, n, t) {
102
- if (n.missing.length === 0)
103
- return;
104
- const r = e.filter(
105
- (u) => n.missing.includes(u.helper.key) && !u.helper.optional
106
- );
107
- if (r.length === 0)
108
- return;
109
- const a = r.map(
110
- (u) => C(t, u.helper)
111
- );
112
- throw h(
113
- "ValidationError",
114
- `Pipeline finalisation aborted because ${a.join(", ")} did not execute.`
115
- );
116
- }
117
- const N = (e) => _(
9
+ function L(r) {
10
+ const i = r.fragmentKind ?? "fragment", s = r.builderKind ?? "builder", a = r.createError ?? ((e, n) => new Error(`[${e}] ${n}`)), l = [], d = [], f = [], o = [], u = V({
11
+ options: r,
12
+ fragmentKind: i,
13
+ builderKind: s
14
+ }), k = r.createRunResult ?? ((e) => ({
15
+ artifact: e.artifact,
16
+ diagnostics: e.diagnostics,
17
+ steps: e.steps
18
+ })), { prepareContext: K, executeRun: P } = $({
19
+ options: r,
20
+ fragmentEntries: l,
21
+ builderEntries: d,
22
+ fragmentKind: i,
23
+ builderKind: s,
24
+ diagnosticManager: u,
25
+ createError: a,
26
+ resolveRunResult: k,
27
+ extensionHooks: f
28
+ }), g = i, m = s, p = (e) => v(
118
29
  e,
119
- b,
120
- E,
30
+ i,
121
31
  l,
122
- (n, t, r) => P(
32
+ g,
33
+ (n, t, c) => u.flagConflict(
123
34
  n,
124
35
  t,
125
- l,
126
- r
36
+ g,
37
+ c
127
38
  ),
128
- h
129
- ), I = (e) => _(
39
+ a
40
+ ), R = (e) => v(
130
41
  e,
42
+ s,
43
+ d,
131
44
  m,
132
- y,
133
- p,
134
- (n, t, r) => P(
45
+ (n, t, c) => u.flagConflict(
135
46
  n,
136
47
  t,
137
- p,
138
- r
48
+ m,
49
+ c
139
50
  ),
140
- h
141
- ), J = (e, n) => ue(e, n, v);
142
- function ee(e) {
143
- const n = c.createBuildOptions(e), t = c.createContext(e);
144
- H = t.reporter;
145
- for (const o of S)
146
- T(o);
147
- const r = c.createFragmentState({
148
- options: e,
149
- context: t,
150
- buildOptions: n
151
- }), a = X(
152
- E,
153
- {
154
- onMissingDependency: ({ dependant: o, dependencyKey: i }) => {
155
- const s = o.helper;
156
- q(
157
- s,
158
- i,
159
- l
160
- ), D(
161
- s,
162
- l,
163
- `could not execute because dependency "${i}" was not found`,
164
- s.dependsOn
165
- );
166
- },
167
- onUnresolvedHelpers: ({ unresolved: o }) => {
168
- for (const i of o) {
169
- const s = i.helper;
170
- D(
171
- s,
172
- l,
173
- "could not execute because its dependencies never resolved",
174
- s.dependsOn
175
- );
176
- }
177
- }
178
- },
179
- h
180
- ).order, u = [], k = (o) => {
181
- const i = o.helper;
182
- u.push({
183
- id: o.id,
184
- index: u.length,
185
- key: i.key,
186
- kind: i.kind,
187
- mode: i.mode,
188
- priority: i.priority,
189
- dependsOn: i.dependsOn,
190
- origin: i.origin
51
+ a
52
+ ), C = (e, n) => w(e, n, f), H = (e) => {
53
+ if (e && h(e)) {
54
+ Promise.resolve(e).catch(() => {
191
55
  });
192
- }, f = {
193
- onMissingDependency: ({ dependant: o, dependencyKey: i }) => {
194
- const s = o.helper;
195
- q(
196
- s,
197
- i,
198
- p
199
- ), D(
200
- s,
201
- p,
202
- `could not execute because dependency "${i}" was not found`,
203
- s.dependsOn
204
- );
205
- },
206
- onUnresolvedHelpers: ({ unresolved: o }) => {
207
- for (const i of o) {
208
- const s = i.helper;
209
- D(
210
- s,
211
- p,
212
- "could not execute because its dependencies never resolved",
213
- s.dependsOn
214
- );
215
- }
216
- }
217
- }, K = c.createExtensionHookOptions ?? ((o) => ({
218
- context: o.context,
219
- options: o.options,
220
- artifact: o.artifact
221
- })), U = (o) => K({
222
- context: t,
223
- options: e,
224
- buildOptions: n,
225
- artifact: o
226
- }), $ = c.onExtensionRollbackError ?? ((o) => {
227
- const { reporter: i } = o.context, s = i.warn;
228
- typeof s == "function" && s.call(i, "Pipeline extension rollback failed.", {
229
- error: o.error,
230
- errorName: o.errorMetadata.name,
231
- errorMessage: o.errorMetadata.message,
232
- errorStack: o.errorMetadata.stack,
233
- errorCause: o.errorMetadata.cause,
234
- extensions: o.extensionKeys,
235
- hookKeys: o.hookSequence
56
+ const n = Promise.resolve(e).then(() => {
236
57
  });
237
- });
238
- return {
239
- runOptions: e,
240
- buildOptions: n,
241
- context: t,
242
- draft: r,
243
- fragmentOrder: a,
244
- steps: u,
245
- pushStep: k,
246
- builderGraphOptions: f,
247
- createHookOptions: U,
248
- handleRollbackError: $
249
- };
250
- }
251
- const ne = c.createRunResult ?? ((e) => ({
252
- artifact: e.artifact,
253
- diagnostics: e.diagnostics,
254
- steps: e.steps
255
- }));
256
- function te(e) {
257
- const {
258
- runOptions: n,
259
- buildOptions: t,
260
- context: r,
261
- draft: a,
262
- fragmentOrder: u,
263
- steps: k,
264
- pushStep: f,
265
- builderGraphOptions: K,
266
- createHookOptions: U,
267
- handleRollbackError: $
268
- } = e;
269
- let o = A(
270
- y,
271
- /* @__PURE__ */ new Set(),
272
- m
273
- );
274
- const i = Z(
275
- u,
276
- (s) => c.createFragmentArgs({
277
- helper: s.helper,
278
- options: n,
279
- context: r,
280
- buildOptions: t,
281
- draft: a
282
- }),
283
- (s, F, x) => s.apply(F, x),
284
- (s) => f(s)
285
- );
286
- return M(i, (s) => {
287
- W(
288
- E,
289
- s,
290
- l
291
- );
292
- const F = A(
293
- E,
294
- s,
295
- b
296
- );
297
- j(
298
- E,
299
- F,
300
- l
301
- );
302
- let x = c.finalizeFragmentState({
303
- draft: a,
304
- options: n,
305
- context: r,
306
- buildOptions: t,
307
- helpers: { fragments: F }
58
+ n.catch(() => {
59
+ }), o.push(n), n.finally(() => {
60
+ const t = o.indexOf(n);
61
+ t !== -1 && o.splice(t, 1);
62
+ }).catch(() => {
308
63
  });
309
- const re = X(
310
- y,
311
- K,
312
- h
313
- ).order, oe = ie(
314
- v,
315
- U(x),
316
- ({ error: R, extensionKeys: B, hookSequence: z }) => $({
317
- error: R,
318
- extensionKeys: B,
319
- hookSequence: z,
320
- errorMetadata: Y(R),
321
- context: r
322
- })
64
+ }
65
+ return e;
66
+ }, b = () => {
67
+ if (o.length !== 0)
68
+ return Promise.all([...o]).then(
69
+ () => {
70
+ }
323
71
  );
324
- return M(oe, (R) => {
325
- x = R.artifact;
326
- const B = () => (d) => M(
327
- ce(
328
- R.results,
329
- v,
330
- ({
331
- error: g,
332
- extensionKeys: w,
333
- hookSequence: V
334
- }) => $({
335
- error: g,
336
- extensionKeys: w,
337
- hookSequence: V,
338
- errorMetadata: Y(
339
- g
340
- ),
341
- context: r
342
- })
343
- ),
344
- () => {
345
- throw d;
346
- }
347
- ), z = B(), se = (d) => {
348
- W(
349
- y,
350
- d,
351
- p
352
- );
353
- const g = A(
354
- y,
355
- d,
356
- m
357
- );
358
- j(
359
- y,
360
- g,
361
- p
362
- ), o = g;
363
- const w = () => ne({
364
- artifact: x,
365
- diagnostics: S.slice(),
366
- steps: k,
367
- context: r,
368
- buildOptions: t,
369
- options: n,
370
- helpers: {
371
- fragments: F,
372
- builders: o
373
- }
374
- }), V = B();
375
- return M(
376
- Q(
377
- () => ae(
378
- R.results
379
- ),
380
- V
381
- ),
382
- w
383
- );
384
- };
385
- return Q(() => M(
386
- Z(
387
- re,
388
- (d) => c.createBuilderArgs({
389
- helper: d.helper,
390
- options: n,
391
- context: r,
392
- buildOptions: t,
393
- artifact: x
394
- }),
395
- (d, g, w) => d.apply(g, w),
396
- (d) => f(d)
397
- ),
398
- se
399
- ), z);
400
- });
401
- });
402
- }
403
- const L = {
404
- fragmentKind: b,
405
- builderKind: m,
72
+ }, x = {
73
+ fragmentKind: i,
74
+ builderKind: s,
406
75
  ir: {
407
76
  use(e) {
408
- N(e);
77
+ p(e);
409
78
  }
410
79
  },
411
80
  builders: {
412
81
  use(e) {
413
- I(e);
82
+ R(e);
414
83
  }
415
84
  },
416
85
  extensions: {
417
86
  use(e) {
418
- const n = e.register(L);
419
- return n && typeof n?.then == "function" ? n.then(
420
- (t) => J(e.key, t)
421
- ) : J(e.key, n);
87
+ const n = e.register(x);
88
+ n && h(n) && Promise.resolve(n).catch(() => {
89
+ });
90
+ const t = E(
91
+ n,
92
+ (c) => C(e.key, c)
93
+ );
94
+ return H(t);
422
95
  }
423
96
  },
424
97
  use(e) {
425
- if (e.kind === b) {
426
- N(e);
98
+ if (e.kind === i) {
99
+ p(e);
427
100
  return;
428
101
  }
429
- if (e.kind === m) {
430
- I(e);
102
+ if (e.kind === s) {
103
+ R(e);
431
104
  return;
432
105
  }
433
- throw h(
106
+ throw a(
434
107
  "ValidationError",
435
108
  `Unsupported helper kind "${e.kind}".`
436
109
  );
437
110
  },
438
111
  run(e) {
439
- const n = ee(e);
440
- return te(n);
112
+ const n = () => {
113
+ const t = K(e);
114
+ return P(t);
115
+ };
116
+ return E(
117
+ b(),
118
+ () => n()
119
+ );
441
120
  }
442
121
  };
443
- return L;
122
+ return x;
444
123
  }
445
124
  export {
446
- ye as createPipeline
125
+ L as createPipeline
447
126
  };
@@ -0,0 +1,3 @@
1
+ export { OFFICIAL_EXTENSION_BLUEPRINTS } from './official';
2
+ export type { OfficialExtensionBlueprint, ExtensionBlueprint, ExtensionBehaviour, ExtensionFactorySignature, } from './official';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/extensions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,YAAY,CAAC;AAC3D,YAAY,EACX,0BAA0B,EAC1B,kBAAkB,EAClB,kBAAkB,EAClB,yBAAyB,GACzB,MAAM,YAAY,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { OFFICIAL_EXTENSION_BLUEPRINTS as N } from "./official.js";
2
+ /**
3
+ * @wpkernel/pipeline
4
+ * @license EUPL-1.2
5
+ */
6
+ export {
7
+ N as OFFICIAL_EXTENSION_BLUEPRINTS
8
+ };
@@ -0,0 +1,73 @@
1
+ import { PipelineExtension } from '../types';
2
+ /**
3
+ * Identifier for a pipeline extension factory.
4
+ *
5
+ * @category Pipeline
6
+ */
7
+ export interface ExtensionFactorySignature<TOptions = unknown> {
8
+ /**
9
+ * Human readable name for documentation and diagnostics.
10
+ */
11
+ readonly name: string;
12
+ /**
13
+ * Suffix appended to the canonical pipeline extension namespace.
14
+ */
15
+ readonly slug: string;
16
+ /**
17
+ * Shape of the options object accepted by the factory.
18
+ */
19
+ readonly options: TOptions;
20
+ }
21
+ /**
22
+ * Individual behaviour exposed by an extension blueprint.
23
+ *
24
+ * @category Pipeline
25
+ */
26
+ export interface ExtensionBehaviour {
27
+ readonly name: string;
28
+ readonly description: string;
29
+ readonly helperAnnotations?: readonly string[];
30
+ readonly reporterEvents?: readonly string[];
31
+ readonly integrations?: readonly string[];
32
+ }
33
+ /**
34
+ * Documentation-first blueprint for an extension incubated in this package.
35
+ *
36
+ * @category Pipeline
37
+ */
38
+ export interface ExtensionBlueprint {
39
+ readonly id: string;
40
+ readonly status: 'planned' | 'in-development';
41
+ readonly summary: string;
42
+ readonly factory?: ExtensionFactorySignature;
43
+ readonly behaviours: readonly ExtensionBehaviour[];
44
+ readonly pipelineTouchPoints: readonly string[];
45
+ readonly rolloutNotes: readonly string[];
46
+ }
47
+ /**
48
+ * Pipeline extension factory type used throughout the blueprints.
49
+ *
50
+ * @category Pipeline
51
+ */
52
+ export type AnyPipelineExtensionFactory = (options?: unknown) => PipelineExtension<unknown, unknown, unknown, unknown>;
53
+ /**
54
+ * Blueprint catalogue for official extensions that the pipeline team will own.
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * import { OFFICIAL_EXTENSION_BLUEPRINTS } from '@wpkernel/pipeline/extensions';
59
+ *
60
+ * const liveRunner = OFFICIAL_EXTENSION_BLUEPRINTS.find(
61
+ * (entry) => entry.id === 'live-runner'
62
+ * );
63
+ *
64
+ * if (liveRunner?.factory) {
65
+ * console.log(`Factory slug: ${liveRunner.factory.slug}`);
66
+ * }
67
+ * ```
68
+ *
69
+ * @category Pipeline
70
+ */
71
+ export declare const OFFICIAL_EXTENSION_BLUEPRINTS: readonly ExtensionBlueprint[];
72
+ export type { ExtensionBlueprint as OfficialExtensionBlueprint };
73
+ //# sourceMappingURL=official.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"official.d.ts","sourceRoot":"","sources":["../../src/extensions/official.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAElD;;;;GAIG;AACH,MAAM,WAAW,yBAAyB,CAAC,QAAQ,GAAG,OAAO;IAC5D;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC;CAC3B;AAED;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IAClC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,iBAAiB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/C,QAAQ,CAAC,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5C,QAAQ,CAAC,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC1C;AAED;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IAClC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,MAAM,EAAE,SAAS,GAAG,gBAAgB,CAAC;IAC9C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,CAAC,EAAE,yBAAyB,CAAC;IAC7C,QAAQ,CAAC,UAAU,EAAE,SAAS,kBAAkB,EAAE,CAAC;IACnD,QAAQ,CAAC,mBAAmB,EAAE,SAAS,MAAM,EAAE,CAAC;IAChD,QAAQ,CAAC,YAAY,EAAE,SAAS,MAAM,EAAE,CAAC;CACzC;AAED;;;;GAIG;AACH,MAAM,MAAM,2BAA2B,GAAG,CACzC,OAAO,CAAC,EAAE,OAAO,KACb,iBAAiB,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;AAE3D;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,6BAA6B,EAAE,SAAS,kBAAkB,EA+GtE,CAAC;AAEF,YAAY,EAAE,kBAAkB,IAAI,0BAA0B,EAAE,CAAC"}