@almadar/patterns 2.35.0 → 2.37.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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": "1.0.0",
3
- "exportedAt": "2026-06-02T04:23:24.655Z",
3
+ "exportedAt": "2026-06-04T18:07:03.548Z",
4
4
  "mappings": {
5
5
  "page-header": {
6
6
  "component": "PageHeader",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": "1.0.0",
3
- "exportedAt": "2026-06-02T04:23:24.655Z",
3
+ "exportedAt": "2026-06-04T18:07:03.548Z",
4
4
  "contracts": {
5
5
  "form": {
6
6
  "emits": [
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Pattern-swap compatibility — the deterministic shape gate for a contextual
3
+ * pattern swap. A swap keeps the circuit closed when the replacement shares the
4
+ * current pattern's entity-inlet cardinality and can emit the events the
5
+ * consumer's trait listens for. Semantic ranking (which compatible pattern best
6
+ * matches the user's instruction) is the embedding step, layered on top of this
7
+ * gate — never the other way around.
8
+ */
9
+ /** The data-inlet cardinality of a pattern (`record`/`collection`), or `null`
10
+ * when the pattern has no entity inlet (layout / leaf patterns). */
11
+ export declare function getEntityCardinality(patternType: string): 'record' | 'collection' | null;
12
+ /** Events a pattern emits, from its declared event-outlet contract. */
13
+ export declare function getEmittedEvents(patternType: string): string[];
14
+ export interface PatternSwapGate {
15
+ /** Events the replacement MUST be able to emit (the trait's listened set), so
16
+ * handlers still fire after the swap. Omit to skip the outlet gate. */
17
+ requiredEmits?: readonly string[];
18
+ }
19
+ /**
20
+ * Pattern types a `currentType` node can be swapped to while keeping the circuit
21
+ * closed: same entity-inlet cardinality, and — when `requiredEmits` is given —
22
+ * able to emit every required event. Deterministic and unranked; the caller
23
+ * ranks the result semantically (embeddings).
24
+ */
25
+ export declare function findCompatiblePatterns(currentType: string, gate?: PatternSwapGate): string[];
package/dist/index.d.ts CHANGED
@@ -44147,3 +44147,4 @@ export declare function getComponentForPattern(patternType: string): string | nu
44147
44147
  export declare function isEntityAwarePattern(patternType: string): boolean;
44148
44148
  export { getPatternsGroupedByCategory, getPatternPropsCompact, getPatternActionsRef, generatePatternDescription, getAllPatternTypes, getPatternMetadata, getOrbAllowedPatterns, getOrbAllowedPatternsCompact, getOrbAllowedPatternsSlim, getOrbAllowedPatternsFiltered, } from './helpers/prompt-helpers.js';
44149
44149
  export { recommendPatterns, buildRecommendationContext, formatRecommendationsForPrompt, type RecommendationContext, type PatternRecommendation, } from './helpers/pattern-recommender.js';
44150
+ export { findCompatiblePatterns, getEntityCardinality, getEmittedEvents, type PatternSwapGate, } from './helpers/pattern-swap.js';
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // src/patterns-registry.json
2
2
  var patterns_registry_default = {
3
3
  version: "1.0.0",
4
- exportedAt: "2026-06-02T04:23:24.655Z",
4
+ exportedAt: "2026-06-04T18:07:03.548Z",
5
5
  patterns: {
6
6
  "entity-table": {
7
7
  type: "entity-table",
@@ -10012,7 +10012,17 @@ var patterns_registry_default = {
10012
10012
  "dashboards",
10013
10013
  "analytics",
10014
10014
  "data visualization",
10015
- "reporting"
10015
+ "reporting",
10016
+ "bar chart",
10017
+ "line chart",
10018
+ "pie chart",
10019
+ "area chart",
10020
+ "donut chart",
10021
+ "bar",
10022
+ "line",
10023
+ "pie",
10024
+ "area",
10025
+ "donut"
10016
10026
  ],
10017
10027
  typicalSize: "medium",
10018
10028
  propsSchema: {
@@ -33753,7 +33763,7 @@ var integrators_registry_default = {
33753
33763
  // src/component-mapping.json
33754
33764
  var component_mapping_default = {
33755
33765
  version: "1.0.0",
33756
- exportedAt: "2026-06-02T04:23:24.655Z",
33766
+ exportedAt: "2026-06-04T18:07:03.548Z",
33757
33767
  mappings: {
33758
33768
  "page-header": {
33759
33769
  component: "PageHeader",
@@ -35293,7 +35303,7 @@ var component_mapping_default = {
35293
35303
  // src/event-contracts.json
35294
35304
  var event_contracts_default = {
35295
35305
  version: "1.0.0",
35296
- exportedAt: "2026-06-02T04:23:24.655Z",
35306
+ exportedAt: "2026-06-04T18:07:03.548Z",
35297
35307
  contracts: {
35298
35308
  form: {
35299
35309
  emits: [
@@ -37183,6 +37193,44 @@ function formatRecommendationsForPrompt(recommendations) {
37183
37193
  return lines.join("\n");
37184
37194
  }
37185
37195
 
37196
+ // src/helpers/pattern-swap.ts
37197
+ var PATTERNS = patterns_registry_default;
37198
+ var CONTRACTS = event_contracts_default;
37199
+ function entityInlet(patternType) {
37200
+ const propsSchema = PATTERNS.patterns?.[patternType]?.propsSchema;
37201
+ if (!propsSchema) return null;
37202
+ for (const prop of Object.values(propsSchema)) {
37203
+ if (prop.kind === "entity") return prop;
37204
+ }
37205
+ return propsSchema["entity"] ?? null;
37206
+ }
37207
+ function getEntityCardinality(patternType) {
37208
+ return entityInlet(patternType)?.cardinality ?? null;
37209
+ }
37210
+ function getEmittedEvents(patternType) {
37211
+ const emits = CONTRACTS.contracts?.[patternType]?.emits ?? [];
37212
+ const out = [];
37213
+ for (const e of emits) {
37214
+ if (typeof e.event === "string") out.push(e.event);
37215
+ }
37216
+ return out;
37217
+ }
37218
+ function findCompatiblePatterns(currentType, gate = {}) {
37219
+ const cardinality = getEntityCardinality(currentType);
37220
+ const required = gate.requiredEmits ?? [];
37221
+ const result = [];
37222
+ for (const type of Object.keys(PATTERNS.patterns ?? {})) {
37223
+ if (type === currentType) continue;
37224
+ if (getEntityCardinality(type) !== cardinality) continue;
37225
+ if (required.length > 0) {
37226
+ const emits = new Set(getEmittedEvents(type));
37227
+ if (!required.every((ev) => emits.has(ev))) continue;
37228
+ }
37229
+ result.push(type);
37230
+ }
37231
+ return result;
37232
+ }
37233
+
37186
37234
  // src/index.ts
37187
37235
  var registry = patterns_registry_default;
37188
37236
  var PATTERN_REGISTRY = patterns_registry_default;
@@ -37205,6 +37253,6 @@ function isEntityAwarePattern(patternType) {
37205
37253
  return "entity" in propsSchema;
37206
37254
  }
37207
37255
 
37208
- export { COMPONENT_MAPPING, EVENT_CONTRACTS, INTEGRATORS_REGISTRY, PATTERN_REGISTRY, PATTERN_TYPES, buildRecommendationContext, component_mapping_default as componentMapping, event_contracts_default as eventContracts, formatRecommendationsForPrompt, generatePatternDescription, getAllPatternTypes, getComponentForPattern, getOrbAllowedPatterns, getOrbAllowedPatternsCompact, getOrbAllowedPatternsFiltered, getOrbAllowedPatternsSlim, getPatternActionsRef, getPatternDefinition, getPatternMetadata, getPatternPropsCompact, getPatternsGroupedByCategory, integrators_registry_default as integratorsRegistry, isEntityAwarePattern, isValidPatternType, patterns_registry_default as patternsRegistry, recommendPatterns, registry };
37256
+ export { COMPONENT_MAPPING, EVENT_CONTRACTS, INTEGRATORS_REGISTRY, PATTERN_REGISTRY, PATTERN_TYPES, buildRecommendationContext, component_mapping_default as componentMapping, event_contracts_default as eventContracts, findCompatiblePatterns, formatRecommendationsForPrompt, generatePatternDescription, getAllPatternTypes, getComponentForPattern, getEmittedEvents, getEntityCardinality, getOrbAllowedPatterns, getOrbAllowedPatternsCompact, getOrbAllowedPatternsFiltered, getOrbAllowedPatternsSlim, getPatternActionsRef, getPatternDefinition, getPatternMetadata, getPatternPropsCompact, getPatternsGroupedByCategory, integrators_registry_default as integratorsRegistry, isEntityAwarePattern, isValidPatternType, patterns_registry_default as patternsRegistry, recommendPatterns, registry };
37209
37257
  //# sourceMappingURL=index.js.map
37210
37258
  //# sourceMappingURL=index.js.map