@rcrsr/rill 0.17.0 → 0.18.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 (83) hide show
  1. package/dist/ast-nodes.d.ts +14 -4
  2. package/dist/ast-unions.d.ts +1 -1
  3. package/dist/constants.d.ts +1 -1
  4. package/dist/constants.js +1 -0
  5. package/dist/error-registry.js +228 -0
  6. package/dist/ext/crypto/index.js +5 -5
  7. package/dist/ext/exec/index.js +3 -3
  8. package/dist/ext/fetch/index.js +4 -4
  9. package/dist/ext/fetch/request.js +1 -1
  10. package/dist/ext/fs/index.js +101 -114
  11. package/dist/ext/fs/sandbox.d.ts +18 -0
  12. package/dist/ext/fs/sandbox.js +33 -0
  13. package/dist/ext/kv/index.js +12 -12
  14. package/dist/ext/kv/store.d.ts +1 -1
  15. package/dist/ext/kv/store.js +1 -1
  16. package/dist/generated/version-data.d.ts +1 -1
  17. package/dist/generated/version-data.js +2 -2
  18. package/dist/highlight-map.js +1 -0
  19. package/dist/index.d.ts +1 -15
  20. package/dist/index.js +1 -14
  21. package/dist/lexer/operators.js +1 -0
  22. package/dist/parser/helpers.js +1 -0
  23. package/dist/parser/parser-expr.js +44 -5
  24. package/dist/parser/parser-literals.js +111 -4
  25. package/dist/parser/parser-shape.js +2 -2
  26. package/dist/parser/parser-use.js +19 -2
  27. package/dist/parser/parser.d.ts +2 -0
  28. package/dist/parser/parser.js +2 -0
  29. package/dist/runtime/core/callable.d.ts +5 -6
  30. package/dist/runtime/core/callable.js +10 -17
  31. package/dist/runtime/core/context.d.ts +2 -2
  32. package/dist/runtime/core/context.js +8 -8
  33. package/dist/runtime/core/eval/base.d.ts +2 -2
  34. package/dist/runtime/core/eval/base.js +2 -0
  35. package/dist/runtime/core/eval/evaluator.d.ts +1 -1
  36. package/dist/runtime/core/eval/index.d.ts +2 -2
  37. package/dist/runtime/core/eval/mixins/closures.js +367 -27
  38. package/dist/runtime/core/eval/mixins/collections.js +81 -6
  39. package/dist/runtime/core/eval/mixins/control-flow.js +1 -1
  40. package/dist/runtime/core/eval/mixins/conversion.js +17 -12
  41. package/dist/runtime/core/eval/mixins/core.js +15 -2
  42. package/dist/runtime/core/eval/mixins/expressions.js +3 -2
  43. package/dist/runtime/core/eval/mixins/extraction.js +2 -3
  44. package/dist/runtime/core/eval/mixins/list-dispatch.js +1 -1
  45. package/dist/runtime/core/eval/mixins/literals.js +14 -3
  46. package/dist/runtime/core/eval/mixins/types.js +30 -1
  47. package/dist/runtime/core/eval/mixins/variables.js +3 -1
  48. package/dist/runtime/core/execute.d.ts +1 -1
  49. package/dist/runtime/core/field-descriptor.d.ts +1 -1
  50. package/dist/runtime/core/introspection.d.ts +2 -2
  51. package/dist/runtime/core/introspection.js +2 -1
  52. package/dist/runtime/core/resolvers.d.ts +1 -1
  53. package/dist/runtime/core/signals.d.ts +6 -1
  54. package/dist/runtime/core/signals.js +9 -0
  55. package/dist/runtime/core/types/constructors.d.ts +54 -0
  56. package/dist/runtime/core/types/constructors.js +201 -0
  57. package/dist/runtime/core/types/guards.d.ts +42 -0
  58. package/dist/runtime/core/types/guards.js +88 -0
  59. package/dist/runtime/core/types/index.d.ts +18 -0
  60. package/dist/runtime/core/types/index.js +19 -0
  61. package/dist/runtime/core/types/operations.d.ts +98 -0
  62. package/dist/runtime/core/types/operations.js +804 -0
  63. package/dist/runtime/core/{type-registrations.d.ts → types/registrations.d.ts} +12 -22
  64. package/dist/runtime/core/{type-registrations.js → types/registrations.js} +94 -92
  65. package/dist/runtime/core/{types.d.ts → types/runtime.d.ts} +8 -8
  66. package/dist/runtime/core/{type-structures.d.ts → types/structures.d.ts} +21 -3
  67. package/dist/runtime/core/values.d.ts +13 -102
  68. package/dist/runtime/core/values.js +26 -722
  69. package/dist/runtime/ext/builtins.js +9 -8
  70. package/dist/runtime/ext/extensions.d.ts +2 -2
  71. package/dist/runtime/ext/extensions.js +2 -1
  72. package/dist/runtime/ext/test-context.d.ts +2 -2
  73. package/dist/runtime/ext/test-context.js +3 -2
  74. package/dist/runtime/index.d.ts +8 -22
  75. package/dist/runtime/index.js +10 -16
  76. package/dist/signature-parser.d.ts +1 -1
  77. package/dist/token-types.d.ts +1 -0
  78. package/dist/token-types.js +1 -0
  79. package/package.json +1 -1
  80. /package/dist/runtime/core/{markers.d.ts → types/markers.d.ts} +0 -0
  81. /package/dist/runtime/core/{markers.js → types/markers.js} +0 -0
  82. /package/dist/runtime/core/{types.js → types/runtime.js} +0 -0
  83. /package/dist/runtime/core/{type-structures.js → types/structures.js} +0 -0
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Type Guards
3
+ *
4
+ * Centralized type guard functions for all Rill value types.
5
+ * Extracted from values.ts and callable.ts to break the circular
6
+ * dependency between those modules.
7
+ *
8
+ * Import constraints:
9
+ * - Imports ONLY from ./markers.js and ./structures.js
10
+ * - No imports from values.ts or callable.ts
11
+ */
12
+ import type { CallableMarker } from './markers.js';
13
+ import type { RillIterator, RillOrdered, RillStream, RillTuple, RillTypeValue, RillValue, RillVector } from './structures.js';
14
+ /** Type guard for RillTuple (spread args) */
15
+ export declare function isTuple(value: RillValue): value is RillTuple;
16
+ /** Type guard for RillVector */
17
+ export declare function isVector(value: RillValue): value is RillVector;
18
+ /** Type guard for RillOrdered (named spread args) */
19
+ export declare function isOrdered(value: RillValue): value is RillOrdered;
20
+ /** Type guard for RillTypeValue */
21
+ export declare function isTypeValue(value: RillValue): value is RillTypeValue;
22
+ /** Type guard for any callable */
23
+ export declare function isCallable(value: RillValue): value is CallableMarker;
24
+ /** Type guard for dict (plain object, not array, not callable, not tuple) */
25
+ export declare function isDict(value: RillValue): value is Record<string, RillValue>;
26
+ /**
27
+ * Type guard for RillStream (async lazy sequence with resolution).
28
+ * A stream has the __rill_stream discriminator set to true.
29
+ * Must precede isIterator in dispatch order because streams
30
+ * satisfy the iterator structural shape.
31
+ */
32
+ export declare function isStream(value: RillValue): value is RillStream;
33
+ /** Public API alias for isStream */
34
+ export declare const isRillStream: (value: RillValue) => value is RillStream;
35
+ /**
36
+ * Type guard for Rill iterator (lazy sequence).
37
+ * An iterator is a dict with:
38
+ * - done: boolean - whether iteration is complete
39
+ * - next: callable - function to get next iterator
40
+ * - value: any (only required when not done) - current element
41
+ */
42
+ export declare function isIterator(value: RillValue): value is RillIterator;
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Type Guards
3
+ *
4
+ * Centralized type guard functions for all Rill value types.
5
+ * Extracted from values.ts and callable.ts to break the circular
6
+ * dependency between those modules.
7
+ *
8
+ * Import constraints:
9
+ * - Imports ONLY from ./markers.js and ./structures.js
10
+ * - No imports from values.ts or callable.ts
11
+ */
12
+ /** Type guard for RillTuple (spread args) */
13
+ export function isTuple(value) {
14
+ return (typeof value === 'object' &&
15
+ value !== null &&
16
+ '__rill_tuple' in value &&
17
+ value.__rill_tuple === true);
18
+ }
19
+ /** Type guard for RillVector */
20
+ export function isVector(value) {
21
+ return (typeof value === 'object' &&
22
+ value !== null &&
23
+ '__rill_vector' in value &&
24
+ value.__rill_vector === true);
25
+ }
26
+ /** Type guard for RillOrdered (named spread args) */
27
+ export function isOrdered(value) {
28
+ return (typeof value === 'object' &&
29
+ value !== null &&
30
+ '__rill_ordered' in value &&
31
+ value.__rill_ordered === true);
32
+ }
33
+ /** Type guard for RillTypeValue */
34
+ export function isTypeValue(value) {
35
+ return (typeof value === 'object' &&
36
+ value !== null &&
37
+ '__rill_type' in value &&
38
+ value.__rill_type === true);
39
+ }
40
+ /** Type guard for any callable */
41
+ export function isCallable(value) {
42
+ return (typeof value === 'object' &&
43
+ value !== null &&
44
+ '__type' in value &&
45
+ value.__type === 'callable');
46
+ }
47
+ /** Type guard for dict (plain object, not array, not callable, not tuple) */
48
+ export function isDict(value) {
49
+ return (typeof value === 'object' &&
50
+ value !== null &&
51
+ !Array.isArray(value) &&
52
+ !isCallable(value) &&
53
+ !isTuple(value));
54
+ }
55
+ /**
56
+ * Type guard for RillStream (async lazy sequence with resolution).
57
+ * A stream has the __rill_stream discriminator set to true.
58
+ * Must precede isIterator in dispatch order because streams
59
+ * satisfy the iterator structural shape.
60
+ */
61
+ export function isStream(value) {
62
+ return (typeof value === 'object' &&
63
+ value !== null &&
64
+ '__rill_stream' in value &&
65
+ value.__rill_stream === true);
66
+ }
67
+ /** Public API alias for isStream */
68
+ export const isRillStream = isStream;
69
+ /**
70
+ * Type guard for Rill iterator (lazy sequence).
71
+ * An iterator is a dict with:
72
+ * - done: boolean - whether iteration is complete
73
+ * - next: callable - function to get next iterator
74
+ * - value: any (only required when not done) - current element
75
+ */
76
+ export function isIterator(value) {
77
+ if (!isDict(value))
78
+ return false;
79
+ const dict = value;
80
+ if (!('done' in dict && typeof dict['done'] === 'boolean'))
81
+ return false;
82
+ if (!('next' in dict && isCallable(dict['next'])))
83
+ return false;
84
+ // 'value' field only required when not done
85
+ if (!dict['done'] && !('value' in dict))
86
+ return false;
87
+ return true;
88
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Types Module Barrel
3
+ *
4
+ * Re-exports all public symbols from the types/ sub-modules.
5
+ * Internal runtime code may import sub-modules directly;
6
+ * this barrel provides a single import path for runtime/index.ts
7
+ * and other consumers.
8
+ */
9
+ export type { RillFieldDef, RillIterator, RillOrdered, RillStream, RillTuple, RillTypeValue, RillValue, RillVector, TypeStructure, } from './structures.js';
10
+ export type { CallableMarker, FieldDescriptorMarker } from './markers.js';
11
+ export { isCallable, isDict, isIterator, isOrdered, isRillStream, isStream, isTuple, isTypeValue, isVector, } from './guards.js';
12
+ export { copyValue, createOrdered, createRillStream, createTuple, createVector, emptyForType, } from './constructors.js';
13
+ export type { DictStructure, FieldComparisonCallbacks, OrderedStructure, TupleStructure, } from './operations.js';
14
+ export { commonType, compareStructuredFields, formatRillLiteral, formatStructure, inferElementType, inferStructure, paramToFieldDef, structureEquals, structureMatches, } from './operations.js';
15
+ export type { TypeDefinition, TypeProtocol } from './registrations.js';
16
+ export { BUILT_IN_TYPES, deepEquals, deserializeValue, formatValue, inferType, populateBuiltinMethods, serializeValue, } from './registrations.js';
17
+ export type { CaptureEvent, ErrorEvent, ExecutionResult, ExecutionStepper, ExtensionEvent, FunctionReturnEvent, HostCallEvent, NativeArray, NativePlainObject, NativeValue, ObservabilityCallbacks, ResolverResult, RuntimeCallbacks, RuntimeContext, RuntimeOptions, SchemeResolver, StepEndEvent, StepResult, StepStartEvent, } from './runtime.js';
18
+ export { bindDictCallables } from './runtime.js';
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Types Module Barrel
3
+ *
4
+ * Re-exports all public symbols from the types/ sub-modules.
5
+ * Internal runtime code may import sub-modules directly;
6
+ * this barrel provides a single import path for runtime/index.ts
7
+ * and other consumers.
8
+ */
9
+ // ============================================================
10
+ // GUARDS (type guard functions for all Rill value types)
11
+ // ============================================================
12
+ export { isCallable, isDict, isIterator, isOrdered, isRillStream, isStream, isTuple, isTypeValue, isVector, } from './guards.js';
13
+ // ============================================================
14
+ // CONSTRUCTORS (factory functions for compound values)
15
+ // ============================================================
16
+ export { copyValue, createOrdered, createRillStream, createTuple, createVector, emptyForType, } from './constructors.js';
17
+ export { commonType, compareStructuredFields, formatRillLiteral, formatStructure, inferElementType, inferStructure, paramToFieldDef, structureEquals, structureMatches, } from './operations.js';
18
+ export { BUILT_IN_TYPES, deepEquals, deserializeValue, formatValue, inferType, populateBuiltinMethods, serializeValue, } from './registrations.js';
19
+ export { bindDictCallables } from './runtime.js';
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Type Structure Operations
3
+ *
4
+ * Structural comparison, matching, inference, and formatting functions
5
+ * extracted from values.ts. Provides `compareStructuredFields()` to
6
+ * deduplicate dict/tuple/ordered dispatch across structureEquals,
7
+ * structureMatches, and formatStructure.
8
+ *
9
+ * Import constraints:
10
+ * - Imports from ./structures.js, ./guards.js, ./registrations.js
11
+ * - Circular with registrations.ts (runtime-safe: no init-time cross-calls)
12
+ */
13
+ import type { RillFieldDef, RillValue, TypeStructure } from './structures.js';
14
+ export type DictStructure = {
15
+ kind: 'dict';
16
+ fields?: Record<string, RillFieldDef>;
17
+ valueType?: TypeStructure;
18
+ };
19
+ export type TupleStructure = {
20
+ kind: 'tuple';
21
+ elements?: RillFieldDef[];
22
+ valueType?: TypeStructure;
23
+ };
24
+ export type OrderedStructure = {
25
+ kind: 'ordered';
26
+ fields?: RillFieldDef[];
27
+ valueType?: TypeStructure;
28
+ };
29
+ /**
30
+ * Callbacks for kind-specific field dispatch in dict/tuple/ordered types.
31
+ * `compareStructuredFields` handles the common valueType check and
32
+ * kind-based field extraction, then delegates to these callbacks.
33
+ */
34
+ export interface FieldComparisonCallbacks<T> {
35
+ /** Both structures carry a uniform valueType */
36
+ onValueType(aValueType: TypeStructure, bValueType: TypeStructure): T;
37
+ /** One structure has valueType, the other does not */
38
+ onValueTypeMismatch(): T;
39
+ /** Neither structure has fields/elements */
40
+ onBothEmpty(): T;
41
+ /** One structure has fields/elements, the other does not */
42
+ onFieldPresenceMismatch(): T;
43
+ /** Dict with keyed fields on both sides */
44
+ onDictFields(aFields: Record<string, RillFieldDef>, bFields: Record<string, RillFieldDef>): T;
45
+ /** Tuple with positional elements on both sides */
46
+ onTupleElements(aElements: RillFieldDef[], bElements: RillFieldDef[]): T;
47
+ /** Ordered with named positional fields on both sides */
48
+ onOrderedFields(aFields: RillFieldDef[], bFields: RillFieldDef[]): T;
49
+ }
50
+ /**
51
+ * Shared dispatch for dict/tuple/ordered field comparison.
52
+ * Handles valueType check and field iteration across
53
+ * structureEquals, structureMatches, and formatStructure.
54
+ *
55
+ * Constraints:
56
+ * - Dict: keyed fields, sorted key comparison
57
+ * - Tuple: positional elements
58
+ * - Ordered: named positional fields
59
+ * - Recurses via caller-provided callbacks
60
+ *
61
+ * Callers validate that a.kind === b.kind before calling.
62
+ * Invalid kind values fall through to the final return.
63
+ */
64
+ export declare function compareStructuredFields<T>(a: TypeStructure, b: TypeStructure, callbacks: FieldComparisonCallbacks<T>, fallback: T): T;
65
+ /** Format a RillValue as a rill literal for use in type signatures. */
66
+ export declare function formatRillLiteral(value: RillValue): string;
67
+ /** Compare two structural types for equality. */
68
+ export declare function structureEquals(a: TypeStructure, b: TypeStructure): boolean;
69
+ /**
70
+ * Check if a value matches a structural type descriptor.
71
+ * Used for runtime type checking (`:?` operator).
72
+ */
73
+ export declare function structureMatches(value: RillValue, type: TypeStructure): boolean;
74
+ /** Format a structural type descriptor as a human-readable string. */
75
+ export declare function formatStructure(type: TypeStructure): string;
76
+ /** Build a closure param field definition from name, type, and optional default. */
77
+ export declare function paramToFieldDef(name: string, type: TypeStructure, defaultValue: RillValue | undefined): RillFieldDef;
78
+ /**
79
+ * Infer the element type for a homogeneous list.
80
+ * Empty arrays return { kind: 'any' }.
81
+ * Mixed types throw RILL-R002.
82
+ */
83
+ export declare function inferElementType(elements: RillValue[]): TypeStructure;
84
+ /** Infer the structural type descriptor for any Rill value. */
85
+ export declare function inferStructure(value: RillValue): TypeStructure;
86
+ /**
87
+ * Return the most specific shared type for two TypeStructure values.
88
+ * Returns null when types are incompatible at the top level.
89
+ *
90
+ * Cascade priority:
91
+ * 1. Any-narrowing: if either side is `any`, return the other
92
+ * 2. Structural match: delegate to structureEquals; on true, return a
93
+ * 3. Recursive list: merge inner element types
94
+ * 3b. Uniform valueType: merge dict/tuple/ordered value types
95
+ * 4. Bare type fallback: same compound type but structural mismatch
96
+ * 5. Incompatible: different top-level types return null
97
+ */
98
+ export declare function commonType(a: TypeStructure, b: TypeStructure): TypeStructure | null;