@almadar/patterns 2.35.0 → 2.36.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",
@@ -33753,7 +33753,7 @@ var integrators_registry_default = {
33753
33753
  // src/component-mapping.json
33754
33754
  var component_mapping_default = {
33755
33755
  version: "1.0.0",
33756
- exportedAt: "2026-06-02T04:23:24.655Z",
33756
+ exportedAt: "2026-06-04T18:07:03.548Z",
33757
33757
  mappings: {
33758
33758
  "page-header": {
33759
33759
  component: "PageHeader",
@@ -35293,7 +35293,7 @@ var component_mapping_default = {
35293
35293
  // src/event-contracts.json
35294
35294
  var event_contracts_default = {
35295
35295
  version: "1.0.0",
35296
- exportedAt: "2026-06-02T04:23:24.655Z",
35296
+ exportedAt: "2026-06-04T18:07:03.548Z",
35297
35297
  contracts: {
35298
35298
  form: {
35299
35299
  emits: [
@@ -37183,6 +37183,44 @@ function formatRecommendationsForPrompt(recommendations) {
37183
37183
  return lines.join("\n");
37184
37184
  }
37185
37185
 
37186
+ // src/helpers/pattern-swap.ts
37187
+ var PATTERNS = patterns_registry_default;
37188
+ var CONTRACTS = event_contracts_default;
37189
+ function entityInlet(patternType) {
37190
+ const propsSchema = PATTERNS.patterns?.[patternType]?.propsSchema;
37191
+ if (!propsSchema) return null;
37192
+ for (const prop of Object.values(propsSchema)) {
37193
+ if (prop.kind === "entity") return prop;
37194
+ }
37195
+ return propsSchema["entity"] ?? null;
37196
+ }
37197
+ function getEntityCardinality(patternType) {
37198
+ return entityInlet(patternType)?.cardinality ?? null;
37199
+ }
37200
+ function getEmittedEvents(patternType) {
37201
+ const emits = CONTRACTS.contracts?.[patternType]?.emits ?? [];
37202
+ const out = [];
37203
+ for (const e of emits) {
37204
+ if (typeof e.event === "string") out.push(e.event);
37205
+ }
37206
+ return out;
37207
+ }
37208
+ function findCompatiblePatterns(currentType, gate = {}) {
37209
+ const cardinality = getEntityCardinality(currentType);
37210
+ const required = gate.requiredEmits ?? [];
37211
+ const result = [];
37212
+ for (const type of Object.keys(PATTERNS.patterns ?? {})) {
37213
+ if (type === currentType) continue;
37214
+ if (getEntityCardinality(type) !== cardinality) continue;
37215
+ if (required.length > 0) {
37216
+ const emits = new Set(getEmittedEvents(type));
37217
+ if (!required.every((ev) => emits.has(ev))) continue;
37218
+ }
37219
+ result.push(type);
37220
+ }
37221
+ return result;
37222
+ }
37223
+
37186
37224
  // src/index.ts
37187
37225
  var registry = patterns_registry_default;
37188
37226
  var PATTERN_REGISTRY = patterns_registry_default;
@@ -37205,6 +37243,6 @@ function isEntityAwarePattern(patternType) {
37205
37243
  return "entity" in propsSchema;
37206
37244
  }
37207
37245
 
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 };
37246
+ 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
37247
  //# sourceMappingURL=index.js.map
37210
37248
  //# sourceMappingURL=index.js.map