@pgflow/dsl 0.9.1 → 0.11.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.
package/dist/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @pgflow/dsl
2
2
 
3
+ ## 0.11.0
4
+
5
+ ## 0.10.0
6
+
7
+ ### Patch Changes
8
+
9
+ - 0b84bb0: Add automatic flow compilation at worker startup. Workers now call ensure_flow_compiled to verify flows are up-to-date. In development, mismatched flows are recompiled automatically. In production, mismatches cause errors. Use ensureCompiledOnStartup: false to opt-out.
10
+
3
11
  ## 0.9.1
4
12
 
5
13
  ### Patch Changes
@@ -0,0 +1,81 @@
1
+ import { AnyFlow } from './dsl.js';
2
+ /**
3
+ * Step-level options that can be included in the shape for creation,
4
+ * but are NOT compared during shape comparison (runtime tunable).
5
+ */
6
+ export interface StepShapeOptions {
7
+ maxAttempts?: number;
8
+ baseDelay?: number;
9
+ timeout?: number;
10
+ startDelay?: number;
11
+ }
12
+ /**
13
+ * Flow-level options that can be included in the shape for creation,
14
+ * but are NOT compared during shape comparison (runtime tunable).
15
+ */
16
+ export interface FlowShapeOptions {
17
+ maxAttempts?: number;
18
+ baseDelay?: number;
19
+ timeout?: number;
20
+ }
21
+ /**
22
+ * StepShape captures the structural definition of a step for drift detection.
23
+ *
24
+ * The `options` field is included for flow creation but NOT compared during
25
+ * shape comparison. Options can be tuned at runtime via SQL without
26
+ * requiring recompilation. See: /deploy/tune-flow-config/
27
+ */
28
+ export interface StepShape {
29
+ slug: string;
30
+ stepType: 'single' | 'map';
31
+ dependencies: string[];
32
+ options?: StepShapeOptions;
33
+ }
34
+ /**
35
+ * FlowShape captures the structural definition of a flow for drift detection.
36
+ *
37
+ * This represents the DAG topology - which steps exist, their types, and how
38
+ * they connect via dependencies.
39
+ *
40
+ * The `options` field is included for flow creation but NOT compared during
41
+ * shape comparison. Options can be tuned at runtime via SQL without recompilation.
42
+ *
43
+ * Note: flowSlug is intentionally excluded - it's an identifier, not structural
44
+ * data. The slug comes from context (URL, registry lookup, function parameter).
45
+ */
46
+ export interface FlowShape {
47
+ steps: StepShape[];
48
+ options?: FlowShapeOptions;
49
+ }
50
+ /**
51
+ * Result of comparing two FlowShapes.
52
+ */
53
+ export interface ShapeComparisonResult {
54
+ match: boolean;
55
+ differences: string[];
56
+ }
57
+ /**
58
+ * Extracts a FlowShape from a Flow object.
59
+ * The shape captures structural information needed for drift detection,
60
+ * plus options for flow creation.
61
+ *
62
+ * Options are included in the shape for proper flow/step creation, but
63
+ * are NOT compared during shape comparison (they're runtime tunable).
64
+ *
65
+ * @param flow - The Flow object to extract shape from
66
+ * @returns A FlowShape representing the flow's structure and options
67
+ */
68
+ export declare function extractFlowShape(flow: AnyFlow): FlowShape;
69
+ /**
70
+ * Compares two FlowShapes and returns detailed differences.
71
+ * Used by ControlPlane for Layer 1 comparison (Worker vs ControlPlane).
72
+ *
73
+ * Only compares structural aspects (steps, types, dependencies).
74
+ * Runtime options are not compared as they can be tuned independently.
75
+ *
76
+ * @param a - First FlowShape (typically from worker)
77
+ * @param b - Second FlowShape (typically from ControlPlane or database)
78
+ * @returns ShapeComparisonResult with match status and list of differences
79
+ */
80
+ export declare function compareFlowShapes(a: FlowShape, b: FlowShape): ShapeComparisonResult;
81
+ //# sourceMappingURL=flow-shape.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flow-shape.d.ts","sourceRoot":"","sources":["../src/flow-shape.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAMnC;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,QAAQ,GAAG,KAAK,CAAC;IAC3B,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,OAAO,CAAC,EAAE,gBAAgB,CAAC;CAC5B;AAED;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,SAAS,EAAE,CAAC;IACnB,OAAO,CAAC,EAAE,gBAAgB,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,OAAO,CAAC;IACf,WAAW,EAAE,MAAM,EAAE,CAAC;CACvB;AAyBD;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,OAAO,GAAG,SAAS,CAwCzD;AAMD;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAC/B,CAAC,EAAE,SAAS,EACZ,CAAC,EAAE,SAAS,GACX,qBAAqB,CA6BvB"}
@@ -0,0 +1,119 @@
1
+ // ========================
2
+ // SHAPE EXTRACTION
3
+ // ========================
4
+ /**
5
+ * Checks if an options object has any defined (non-undefined) values.
6
+ */
7
+ function hasDefinedOptions(options) {
8
+ return Object.values(options).some((v) => v !== undefined);
9
+ }
10
+ /**
11
+ * Filters out undefined values from an options object.
12
+ * Returns only the keys with defined values.
13
+ */
14
+ function filterDefinedOptions(options) {
15
+ return Object.fromEntries(Object.entries(options).filter(([_, v]) => v !== undefined));
16
+ }
17
+ /**
18
+ * Extracts a FlowShape from a Flow object.
19
+ * The shape captures structural information needed for drift detection,
20
+ * plus options for flow creation.
21
+ *
22
+ * Options are included in the shape for proper flow/step creation, but
23
+ * are NOT compared during shape comparison (they're runtime tunable).
24
+ *
25
+ * @param flow - The Flow object to extract shape from
26
+ * @returns A FlowShape representing the flow's structure and options
27
+ */
28
+ export function extractFlowShape(flow) {
29
+ const steps = flow.stepOrder.map((stepSlug) => {
30
+ const stepDef = flow.getStepDefinition(stepSlug);
31
+ const stepShape = {
32
+ slug: stepSlug,
33
+ stepType: stepDef.stepType ?? 'single',
34
+ // Sort dependencies alphabetically for deterministic comparison
35
+ dependencies: [...stepDef.dependencies].sort(),
36
+ };
37
+ // Only include options if at least one is defined
38
+ const stepOptions = {
39
+ maxAttempts: stepDef.options.maxAttempts,
40
+ baseDelay: stepDef.options.baseDelay,
41
+ timeout: stepDef.options.timeout,
42
+ startDelay: stepDef.options.startDelay,
43
+ };
44
+ if (hasDefinedOptions(stepOptions)) {
45
+ stepShape.options = filterDefinedOptions(stepOptions);
46
+ }
47
+ return stepShape;
48
+ });
49
+ const shape = { steps };
50
+ // Only include flow options if at least one is defined
51
+ const flowOptions = {
52
+ maxAttempts: flow.options.maxAttempts,
53
+ baseDelay: flow.options.baseDelay,
54
+ timeout: flow.options.timeout,
55
+ };
56
+ if (hasDefinedOptions(flowOptions)) {
57
+ shape.options = filterDefinedOptions(flowOptions);
58
+ }
59
+ return shape;
60
+ }
61
+ // ========================
62
+ // SHAPE COMPARISON
63
+ // ========================
64
+ /**
65
+ * Compares two FlowShapes and returns detailed differences.
66
+ * Used by ControlPlane for Layer 1 comparison (Worker vs ControlPlane).
67
+ *
68
+ * Only compares structural aspects (steps, types, dependencies).
69
+ * Runtime options are not compared as they can be tuned independently.
70
+ *
71
+ * @param a - First FlowShape (typically from worker)
72
+ * @param b - Second FlowShape (typically from ControlPlane or database)
73
+ * @returns ShapeComparisonResult with match status and list of differences
74
+ */
75
+ export function compareFlowShapes(a, b) {
76
+ const differences = [];
77
+ // Compare step counts
78
+ if (a.steps.length !== b.steps.length) {
79
+ differences.push(`Step count differs: ${a.steps.length} vs ${b.steps.length}`);
80
+ }
81
+ // Compare steps by index (order matters)
82
+ const maxLen = Math.max(a.steps.length, b.steps.length);
83
+ for (let i = 0; i < maxLen; i++) {
84
+ const aStep = a.steps[i];
85
+ const bStep = b.steps[i];
86
+ if (!aStep) {
87
+ differences.push(`Step at index ${i}: missing in first shape (second has '${bStep.slug}')`);
88
+ }
89
+ else if (!bStep) {
90
+ differences.push(`Step at index ${i}: missing in second shape (first has '${aStep.slug}')`);
91
+ }
92
+ else {
93
+ compareSteps(aStep, bStep, i, differences);
94
+ }
95
+ }
96
+ return {
97
+ match: differences.length === 0,
98
+ differences,
99
+ };
100
+ }
101
+ /**
102
+ * Compares two steps at the same index and adds differences to the list.
103
+ */
104
+ function compareSteps(a, b, index, differences) {
105
+ // Compare slug (order matters, so slugs must match at same index)
106
+ if (a.slug !== b.slug) {
107
+ differences.push(`Step at index ${index}: slug differs '${a.slug}' vs '${b.slug}'`);
108
+ }
109
+ // Compare step type
110
+ if (a.stepType !== b.stepType) {
111
+ differences.push(`Step at index ${index}: type differs '${a.stepType}' vs '${b.stepType}'`);
112
+ }
113
+ // Compare dependencies (already sorted)
114
+ const aDeps = a.dependencies.join(',');
115
+ const bDeps = b.dependencies.join(',');
116
+ if (aDeps !== bDeps) {
117
+ differences.push(`Step at index ${index}: dependencies differ [${a.dependencies.join(', ')}] vs [${b.dependencies.join(', ')}]`);
118
+ }
119
+ }
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './dsl.js';
2
2
  export * from './compile-flow.js';
3
+ export * from './flow-shape.js';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC"}
package/dist/index.js CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './dsl.js';
2
2
  export * from './compile-flow.js';
3
+ export * from './flow-shape.js';
package/dist/package.json CHANGED
@@ -1,7 +1,12 @@
1
1
  {
2
2
  "name": "@pgflow/dsl",
3
- "version": "0.9.1",
3
+ "version": "0.11.0",
4
4
  "license": "Apache-2.0",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/pgflow-dev/pgflow",
8
+ "directory": "pkgs/dsl"
9
+ },
5
10
  "type": "module",
6
11
  "main": "./dist/index.js",
7
12
  "module": "./dist/index.js",
package/package.json CHANGED
@@ -1,7 +1,12 @@
1
1
  {
2
2
  "name": "@pgflow/dsl",
3
- "version": "0.9.1",
3
+ "version": "0.11.0",
4
4
  "license": "Apache-2.0",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/pgflow-dev/pgflow",
8
+ "directory": "pkgs/dsl"
9
+ },
5
10
  "type": "module",
6
11
  "main": "./dist/index.js",
7
12
  "module": "./dist/index.js",