/** * Portable logic primitive registry. * * This table names host-language patterns that KERN treats as portable intent * rather than target-specific syntax. Target packages still own the concrete * lowering, but the supported surface is declared once here so conformance * gaps do not become anonymous string-rewrite patches. */ export type PortableLogicPrimitiveId = 'collection.has' | 'collection.count' | 'collection.filter' | 'collection.compact' | 'collection.pluck' | 'collection.take' | 'collection.drop' | 'collection.slice' | 'collection.reverse' | 'collection.at' | 'collection.join' | 'collection.concat' | 'collection.includes' | 'collection.indexOf' | 'collection.lastIndexOf' | 'collection.sort' | 'collection.uniqueBy' | 'collection.groupBy' | 'collection.partition' | 'collection.indexBy' | 'collection.countBy' | 'logic.firstTruthy' | 'logic.coalesce' | 'time.epochMs' | 'logic.not' | 'number.clamp' | 'object.keys' | 'object.values' | 'object.entries' | 'object.merge' | 'object.omit' | 'object.pick' | 'string.trim' | 'string.split' | 'string.replaceFirst' | 'string.replaceAll' | 'logic.firstDefined' | 'string.coerce'; export type PortableLogicTarget = 'ts' | 'python' | 'go'; export type PortableLogicSupport = 'stable' | 'preview' | 'unsupported'; export type GoPortableLogicSupport = 'preview' | 'unsupported'; export type PortableLogicPurity = 'pure' | 'reads-time'; export type PortableLogicIntent = 'semantic-gap' | 'host-pattern' | 'language-operator'; export interface PortableLogicPrimitive { id: PortableLogicPrimitiveId; description: string; purity: PortableLogicPurity; intent: PortableLogicIntent; hostPatterns: readonly string[]; portabilityNotes: readonly string[]; operatorRationale?: string; targets: { ts: PortableLogicSupport; python: PortableLogicSupport; go: GoPortableLogicSupport; }; } export declare const PORTABLE_LOGIC_PRIMITIVES: { readonly 'collection.has': { readonly id: "collection.has"; readonly description: "Membership test over a constructed collection, e.g. JS new Set(xs).has(x)."; readonly purity: "pure"; readonly intent: "semantic-gap"; readonly hostPatterns: readonly ["new Set(xs).has(x)"]; readonly portabilityNotes: readonly ["Membership intent is explicit; target helpers own Set/list membership mechanics."]; readonly targets: { readonly ts: "stable"; readonly python: "stable"; readonly go: "unsupported"; }; }; readonly 'collection.count': { readonly id: "collection.count"; readonly description: "Collection cardinality, optionally after a predicate, e.g. JS xs.length or xs.filter(pred).length."; readonly purity: "pure"; readonly intent: "semantic-gap"; readonly hostPatterns: readonly ["xs.length", "xs.filter(x => pred).length", "len(xs)"]; readonly portabilityNotes: readonly ["Count is non-mutating; filtered counts evaluate the predicate once per item in source order."]; readonly targets: { readonly ts: "stable"; readonly python: "stable"; readonly go: "unsupported"; }; }; readonly 'collection.filter': { readonly id: "collection.filter"; readonly description: "Filters collection elements by a portable predicate while preserving source order."; readonly purity: "pure"; readonly intent: "semantic-gap"; readonly hostPatterns: readonly ["xs.filter(x => pred)", "[x for x in xs if pred]"]; readonly portabilityNotes: readonly ["Predicate v1 supports eq, neq, gt, gte, and over bool/number/string/null scalar values; object/list equality is intentionally outside v1. Missing paths and numeric comparison semantics are target-normalized."]; readonly targets: { readonly ts: "stable"; readonly python: "stable"; readonly go: "unsupported"; }; }; readonly 'collection.compact': { readonly id: "collection.compact"; readonly description: "Filters a collection by KERN portable truthiness while preserving source order."; readonly purity: "pure"; readonly intent: "semantic-gap"; readonly hostPatterns: readonly ["xs.filter(Boolean)"]; readonly portabilityNotes: readonly ["Drops null/None/undefined, false, numeric zero, NaN, and empty string; keeps arrays and objects as truthy."]; readonly targets: { readonly ts: "stable"; readonly python: "stable"; readonly go: "unsupported"; }; }; readonly 'collection.pluck': { readonly id: "collection.pluck"; readonly description: "Projects a dotted element path from each collection item."; readonly purity: "pure"; readonly intent: "semantic-gap"; readonly hostPatterns: readonly ["xs.map(x => x.path)", "[x.path for x in xs]"]; readonly portabilityNotes: readonly ["Route lowering uses safe dotted lookup and returns null/None for missing path segments."]; readonly targets: { readonly ts: "stable"; readonly python: "stable"; readonly go: "unsupported"; }; }; readonly 'collection.take': { readonly id: "collection.take"; readonly description: "Takes the first N collection elements."; readonly purity: "pure"; readonly intent: "semantic-gap"; readonly hostPatterns: readonly ["xs.slice(0, n)", "xs[:n]"]; readonly portabilityNotes: readonly ["Route lowering requires a non-negative integer literal to avoid target slicing divergence."]; readonly targets: { readonly ts: "stable"; readonly python: "stable"; readonly go: "unsupported"; }; }; readonly 'collection.drop': { readonly id: "collection.drop"; readonly description: "Drops the first N collection elements."; readonly purity: "pure"; readonly intent: "semantic-gap"; readonly hostPatterns: readonly ["xs.slice(n)", "xs[n:]"]; readonly portabilityNotes: readonly ["Route lowering requires a non-negative integer literal to avoid target slicing divergence."]; readonly targets: { readonly ts: "stable"; readonly python: "stable"; readonly go: "unsupported"; }; }; readonly 'collection.slice': { readonly id: "collection.slice"; readonly description: "Copies a half-open collection range without mutating the source."; readonly purity: "pure"; readonly intent: "semantic-gap"; readonly hostPatterns: readonly ["xs.slice(start, end)", "xs[start:end]"]; readonly portabilityNotes: readonly ["Route lowering requires non-negative integer literal bounds and clamps out-of-range values."]; readonly targets: { readonly ts: "stable"; readonly python: "stable"; readonly go: "unsupported"; }; }; readonly 'collection.reverse': { readonly id: "collection.reverse"; readonly description: "Returns collection elements in reverse order without mutating the source."; readonly purity: "pure"; readonly intent: "semantic-gap"; readonly hostPatterns: readonly ["[...xs].reverse()", "xs[::-1]"]; readonly portabilityNotes: readonly ["Source collections are copied before reversal so route logic cannot mutate request data."]; readonly targets: { readonly ts: "stable"; readonly python: "stable"; readonly go: "unsupported"; }; }; readonly 'collection.at': { readonly id: "collection.at"; readonly description: "Reads an element by zero-based index and returns null/None when out of range."; readonly purity: "pure"; readonly intent: "semantic-gap"; readonly hostPatterns: readonly ["index < xs.length ? xs[index] : null", "xs[index] if index < len(xs) else None"]; readonly portabilityNotes: readonly ["Route lowering requires a non-negative integer literal index; negative indexing is deferred."]; readonly targets: { readonly ts: "stable"; readonly python: "stable"; readonly go: "unsupported"; }; }; readonly 'collection.join': { readonly id: "collection.join"; readonly description: "Joins scalar/null collection elements into a string with a separator."; readonly purity: "pure"; readonly intent: "semantic-gap"; readonly hostPatterns: readonly ["xs.join(separator)", "separator.join(str(x) for x in xs)"]; readonly portabilityNotes: readonly ["Route lowering supports list receivers with scalar/null elements only; null slots become empty strings and booleans use JS lowercase spelling."]; readonly targets: { readonly ts: "stable"; readonly python: "stable"; readonly go: "unsupported"; }; }; readonly 'collection.concat': { readonly id: "collection.concat"; readonly description: "Concatenates two lists without mutating either source list."; readonly purity: "pure"; readonly intent: "semantic-gap"; readonly hostPatterns: readonly ["xs.concat(ys)", "[...xs, ...ys]", "list(xs) + list(ys)"]; readonly portabilityNotes: readonly ["Route lowering supports exactly one list-valued with= operand; scalar concat and varargs are deferred."]; readonly targets: { readonly ts: "stable"; readonly python: "stable"; readonly go: "unsupported"; }; }; readonly 'collection.includes': { readonly id: "collection.includes"; readonly description: "Tests whether a list contains a JSON scalar/null value using JS SameValueZero equality."; readonly purity: "pure"; readonly intent: "semantic-gap"; readonly hostPatterns: readonly ["xs.includes(value)"]; readonly portabilityNotes: readonly ["Route lowering supports scalar/null search values only, with type-sensitive bool/number/string/null comparison and NaN matching NaN."]; readonly targets: { readonly ts: "stable"; readonly python: "stable"; readonly go: "unsupported"; }; }; readonly 'collection.indexOf': { readonly id: "collection.indexOf"; readonly description: "Returns the first index of a JSON scalar/null value or -1 when absent."; readonly purity: "pure"; readonly intent: "semantic-gap"; readonly hostPatterns: readonly ["xs.indexOf(value)"]; readonly portabilityNotes: readonly ["Route lowering supports scalar/null search values only and mirrors JS strict equality; NaN never matches."]; readonly targets: { readonly ts: "stable"; readonly python: "stable"; readonly go: "unsupported"; }; }; readonly 'collection.lastIndexOf': { readonly id: "collection.lastIndexOf"; readonly description: "Returns the last index of a JSON scalar/null value or -1 when absent."; readonly purity: "pure"; readonly intent: "semantic-gap"; readonly hostPatterns: readonly ["xs.lastIndexOf(value)"]; readonly portabilityNotes: readonly ["Route lowering supports scalar/null search values only and mirrors JS strict equality; from= remains deferred."]; readonly targets: { readonly ts: "stable"; readonly python: "stable"; readonly go: "unsupported"; }; }; readonly 'collection.sort': { readonly id: "collection.sort"; readonly description: "Immutable collection sort with optional comparator."; readonly purity: "pure"; readonly intent: "semantic-gap"; readonly hostPatterns: readonly ["[...xs].sort()", "[...xs].sort((a, b) => compare)", "sorted(xs)"]; readonly portabilityNotes: readonly ["Default sort follows JS lexicographic string ordering; comparator sort uses the declared two-item comparison expression."]; readonly targets: { readonly ts: "stable"; readonly python: "stable"; readonly go: "unsupported"; }; }; readonly 'collection.uniqueBy': { readonly id: "collection.uniqueBy"; readonly description: "Unique collection elements by a selector key."; readonly purity: "pure"; readonly intent: "semantic-gap"; readonly hostPatterns: readonly ["xs.uniqueBy(x => x.id)"]; readonly portabilityNotes: readonly ["Evaluates a scalar/hashable selector once per item; first-wins semantics."]; readonly targets: { readonly ts: "stable"; readonly python: "stable"; readonly go: "unsupported"; }; }; readonly 'collection.groupBy': { readonly id: "collection.groupBy"; readonly description: "Groups collection elements by a selector key."; readonly purity: "pure"; readonly intent: "semantic-gap"; readonly hostPatterns: readonly ["xs.groupBy(x => x.type)"]; readonly portabilityNotes: readonly ["Groups items into source-order buckets by scalar/hashable selector key."]; readonly targets: { readonly ts: "stable"; readonly python: "stable"; readonly go: "unsupported"; }; }; readonly 'collection.partition': { readonly id: "collection.partition"; readonly description: "Partitions collection elements into pass and fail arrays based on a predicate."; readonly purity: "pure"; readonly intent: "semantic-gap"; readonly hostPatterns: readonly ["xs.partition(x => pred)"]; readonly portabilityNotes: readonly ["Splits items into two lists based on predicate evaluations; type= denotes the element type."]; readonly targets: { readonly ts: "stable"; readonly python: "stable"; readonly go: "unsupported"; }; }; readonly 'collection.indexBy': { readonly id: "collection.indexBy"; readonly description: "Indexes collection elements by a selector key."; readonly purity: "pure"; readonly intent: "semantic-gap"; readonly hostPatterns: readonly ["xs.indexBy(x => x.id)"]; readonly portabilityNotes: readonly ["Indexes items by scalar/hashable selector key with last-write-wins semantics."]; readonly targets: { readonly ts: "stable"; readonly python: "stable"; readonly go: "unsupported"; }; }; readonly 'collection.countBy': { readonly id: "collection.countBy"; readonly description: "Counts collection elements by a selector key."; readonly purity: "pure"; readonly intent: "semantic-gap"; readonly hostPatterns: readonly ["xs.countBy(x => x.type)"]; readonly portabilityNotes: readonly ["Counts occurrences of each scalar/hashable selector key as integers."]; readonly targets: { readonly ts: "stable"; readonly python: "stable"; readonly go: "unsupported"; }; }; readonly 'logic.firstTruthy': { readonly id: "logic.firstTruthy"; readonly description: "Ordered truthy fallback selection, e.g. JS a || b || c and Python a or b or c."; readonly purity: "pure"; readonly intent: "language-operator"; readonly hostPatterns: readonly ["a || b || c", "a or b or c"]; readonly portabilityNotes: readonly ["Uses host truthiness: false, 0, empty string, null/None, and undefined fall through; empty collections are target-specific because [] and {} are truthy in JS while empty lists/dicts are falsy in Python."]; readonly operatorRationale: "KERN firstTruthy names this common fallback operator chain as portable intent."; readonly targets: { readonly ts: "stable"; readonly python: "stable"; readonly go: "unsupported"; }; }; readonly 'logic.coalesce': { readonly id: "logic.coalesce"; readonly description: "Ordered nullish fallback selection that preserves false, zero, and empty string."; readonly purity: "pure"; readonly intent: "language-operator"; readonly hostPatterns: readonly ["a ?? b ?? c"]; readonly portabilityNotes: readonly ["Uses null/None-only fallback; undefined is normalized to null only at target boundaries."]; readonly operatorRationale: "KERN coalesce names the portable nullish fallback operator chain for body and route lowering."; readonly targets: { readonly ts: "stable"; readonly python: "stable"; readonly go: "unsupported"; }; }; readonly 'time.epochMs': { readonly id: "time.epochMs"; readonly description: "Epoch-milliseconds extraction from a date/time value, e.g. JS new Date(x).getTime()."; readonly purity: "pure"; readonly intent: "semantic-gap"; readonly hostPatterns: readonly ["new Date(x).getTime()"]; readonly portabilityNotes: readonly ["Only value-to-epoch conversion is portable; current time stays target-native."]; readonly targets: { readonly ts: "stable"; readonly python: "stable"; readonly go: "unsupported"; }; }; readonly 'logic.not': { readonly id: "logic.not"; readonly description: "Boolean negation over the portable truthiness domain, e.g. JS !x."; readonly purity: "pure"; readonly intent: "language-operator"; readonly hostPatterns: readonly ["!x", "!!x"]; readonly portabilityNotes: readonly ["Registered for review visibility over portable truthiness, not as a new KERN operator."]; readonly operatorRationale: "KERN already has expression negation; this entry documents target truthiness parity only."; readonly targets: { readonly ts: "stable"; readonly python: "stable"; readonly go: "unsupported"; }; }; readonly 'number.clamp': { readonly id: "number.clamp"; readonly description: "Bounds a numeric value between inclusive low/high limits, e.g. Math.max(lo, Math.min(hi, value))."; readonly purity: "pure"; readonly intent: "semantic-gap"; readonly hostPatterns: readonly ["Math.max(lo, Math.min(hi, value))", "Math.min(hi, Math.max(lo, value))"]; readonly portabilityNotes: readonly ["Bounds must be side-effect-free expressions because host clamp idioms evaluate them directly."]; readonly targets: { readonly ts: "stable"; readonly python: "stable"; readonly go: "unsupported"; }; }; readonly 'object.keys': { readonly id: "object.keys"; readonly description: "Own enumerable key extraction for portable record objects, e.g. JS Object.keys(obj)."; readonly purity: "pure"; readonly intent: "host-pattern"; readonly hostPatterns: readonly ["Object.keys(obj)"]; readonly portabilityNotes: readonly ["Own-property order is target-normalized for numeric-like keys before string keys."]; readonly targets: { readonly ts: "stable"; readonly python: "stable"; readonly go: "unsupported"; }; }; readonly 'object.values': { readonly id: "object.values"; readonly description: "Own enumerable value extraction for portable record objects, e.g. JS Object.values(obj)."; readonly purity: "pure"; readonly intent: "host-pattern"; readonly hostPatterns: readonly ["Object.values(obj)"]; readonly portabilityNotes: readonly ["Own-property order follows the matching object.keys primitive."]; readonly targets: { readonly ts: "stable"; readonly python: "stable"; readonly go: "unsupported"; }; }; readonly 'object.entries': { readonly id: "object.entries"; readonly description: "Own enumerable entry extraction for portable record objects, e.g. JS Object.entries(obj)."; readonly purity: "pure"; readonly intent: "host-pattern"; readonly hostPatterns: readonly ["Object.entries(obj)"]; readonly portabilityNotes: readonly ["Entries preserve JS key order and return array-like key/value pairs."]; readonly targets: { readonly ts: "stable"; readonly python: "stable"; readonly go: "unsupported"; }; }; readonly 'object.merge': { readonly id: "object.merge"; readonly description: "Shallow own-enumerable record merge, e.g. JS Object.assign({}, a, b) or { ...a, ...b }."; readonly purity: "pure"; readonly intent: "semantic-gap"; readonly hostPatterns: readonly ["Object.assign({}, a, b)", "{ ...a, ...b }"]; readonly portabilityNotes: readonly ["Merge is shallow, non-mutating, left-to-right, and duplicate keys are last-write-wins."]; readonly targets: { readonly ts: "stable"; readonly python: "stable"; readonly go: "unsupported"; }; }; readonly 'object.omit': { readonly id: "object.omit"; readonly description: "Shallow own string-key record omission, e.g. JS destructuring assignment with rest parameters."; readonly purity: "pure"; readonly intent: "semantic-gap"; readonly hostPatterns: readonly ["const { a, b, ...rest } = obj"]; readonly portabilityNotes: readonly ["Omit is shallow, non-mutating, and preserves falsy values."]; readonly targets: { readonly ts: "stable"; readonly python: "stable"; readonly go: "unsupported"; }; }; readonly 'object.pick': { readonly id: "object.pick"; readonly description: "Shallow own string-key record selection, e.g. JS Object.fromEntries(keys.map(k => [k, obj[k]]))"; readonly purity: "pure"; readonly intent: "semantic-gap"; readonly hostPatterns: readonly ["Object.fromEntries(keys.map(k => [k, obj[k]]))"]; readonly portabilityNotes: readonly ["Pick preserves key order and includes missing keys as null (TS) or None (Python)."]; readonly targets: { readonly ts: "stable"; readonly python: "stable"; readonly go: "unsupported"; }; }; readonly 'string.trim': { readonly id: "string.trim"; readonly description: "String boundary-whitespace trimming, e.g. JS value.trim()."; readonly purity: "pure"; readonly intent: "host-pattern"; readonly hostPatterns: readonly ["value.trim()"]; readonly portabilityNotes: readonly ["Whitespace trimming follows the target-normalized portable string domain."]; readonly targets: { readonly ts: "stable"; readonly python: "stable"; readonly go: "unsupported"; }; }; readonly 'string.split': { readonly id: "string.split"; readonly description: "String splitting by a non-regex separator; Python lowering must emulate JS limit as result-length truncation."; readonly purity: "pure"; readonly intent: "semantic-gap"; readonly hostPatterns: readonly ["value.split(separator)", "value.split(separator, limit)"]; readonly portabilityNotes: readonly ["Regex separators and unresolved empty separators stay outside the portable primitive."]; readonly targets: { readonly ts: "stable"; readonly python: "stable"; readonly go: "unsupported"; }; }; readonly 'string.replaceFirst': { readonly id: "string.replaceFirst"; readonly description: "First occurrence string replacement with non-regex search and literal replacement text, e.g. JS value.replace(a, b)."; readonly purity: "pure"; readonly intent: "semantic-gap"; readonly hostPatterns: readonly ["value.replace(search, replacement)"]; readonly portabilityNotes: readonly ["Replacement callbacks, regex searches, and substitution-token replacements are excluded."]; readonly targets: { readonly ts: "stable"; readonly python: "stable"; readonly go: "unsupported"; }; }; readonly 'string.replaceAll': { readonly id: "string.replaceAll"; readonly description: "All occurrences string replacement with non-regex search and literal replacement text, e.g. JS value.replaceAll(a, b)."; readonly purity: "pure"; readonly intent: "semantic-gap"; readonly hostPatterns: readonly ["value.replaceAll(search, replacement)"]; readonly portabilityNotes: readonly ["Replacement callbacks, regex searches, and substitution-token replacements are excluded."]; readonly targets: { readonly ts: "stable"; readonly python: "stable"; readonly go: "unsupported"; }; }; readonly 'logic.firstDefined': { readonly id: "logic.firstDefined"; readonly description: "First defined (non-null/non-undefined) value selection."; readonly purity: "pure"; readonly intent: "language-operator"; readonly hostPatterns: readonly ["a ?? b"]; readonly portabilityNotes: readonly ["Returns the first value that is not null or undefined."]; readonly operatorRationale: "Names the nullish coalescing fallback intent."; readonly targets: { readonly ts: "stable"; readonly python: "stable"; readonly go: "unsupported"; }; }; readonly 'string.coerce': { readonly id: "string.coerce"; readonly description: "Portable scalar-to-string coercion for null, booleans, strings, and numbers."; readonly purity: "pure"; readonly intent: "language-operator"; readonly hostPatterns: readonly ["String(value)", "_kern_fmt(value)"]; readonly portabilityNotes: readonly ["Null becomes \"null\", booleans use lowercase spelling, strings pass through, and numbers use JS decimal text."]; readonly operatorRationale: "String coercion is a host operator in TS/Python; KERN documents the expression-v1 subset explicitly."; readonly targets: { readonly ts: "stable"; readonly python: "stable"; readonly go: "unsupported"; }; }; }; export declare function validatePortableLogicPrimitiveRegistry(primitives?: Record): void; export declare const PORTABLE_LOGIC_PRIMITIVE_IDS: PortableLogicPrimitiveId[]; export declare function lookupPortableLogicPrimitive(id: string): PortableLogicPrimitive | null; export declare function portableLogicSupportForTarget(id: PortableLogicPrimitiveId, target: PortableLogicTarget): PortableLogicSupport;