@rcrsr/rill 0.16.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 (97) hide show
  1. package/README.md +37 -21
  2. package/dist/ast-nodes.d.ts +14 -4
  3. package/dist/ast-unions.d.ts +1 -1
  4. package/dist/constants.d.ts +1 -1
  5. package/dist/constants.js +1 -0
  6. package/dist/error-registry.js +228 -0
  7. package/dist/ext/crypto/index.d.ts +3 -3
  8. package/dist/ext/crypto/index.js +62 -59
  9. package/dist/ext/exec/index.d.ts +3 -3
  10. package/dist/ext/exec/index.js +15 -9
  11. package/dist/ext/fetch/index.d.ts +3 -3
  12. package/dist/ext/fetch/index.js +17 -12
  13. package/dist/ext/fetch/request.js +1 -1
  14. package/dist/ext/fs/index.d.ts +3 -3
  15. package/dist/ext/fs/index.js +256 -266
  16. package/dist/ext/fs/sandbox.d.ts +18 -0
  17. package/dist/ext/fs/sandbox.js +33 -0
  18. package/dist/ext/kv/index.d.ts +3 -3
  19. package/dist/ext/kv/index.js +198 -196
  20. package/dist/ext/kv/store.d.ts +1 -1
  21. package/dist/ext/kv/store.js +2 -1
  22. package/dist/ext-parse-bridge.d.ts +10 -0
  23. package/dist/ext-parse-bridge.js +10 -0
  24. package/dist/generated/introspection-data.d.ts +1 -1
  25. package/dist/generated/introspection-data.js +385 -296
  26. package/dist/generated/version-data.d.ts +1 -1
  27. package/dist/generated/version-data.js +2 -2
  28. package/dist/highlight-map.js +1 -0
  29. package/dist/index.d.ts +1 -4
  30. package/dist/index.js +1 -5
  31. package/dist/lexer/operators.js +1 -0
  32. package/dist/parser/helpers.js +1 -0
  33. package/dist/parser/parser-expr.js +44 -5
  34. package/dist/parser/parser-literals.js +111 -4
  35. package/dist/parser/parser-shape.js +2 -2
  36. package/dist/parser/parser-types.js +12 -0
  37. package/dist/parser/parser-use.js +26 -3
  38. package/dist/parser/parser.d.ts +2 -0
  39. package/dist/parser/parser.js +2 -0
  40. package/dist/runtime/core/callable.d.ts +24 -13
  41. package/dist/runtime/core/callable.js +71 -38
  42. package/dist/runtime/core/context.d.ts +2 -13
  43. package/dist/runtime/core/context.js +80 -79
  44. package/dist/runtime/core/eval/base.d.ts +2 -2
  45. package/dist/runtime/core/eval/base.js +2 -0
  46. package/dist/runtime/core/eval/evaluator.d.ts +1 -1
  47. package/dist/runtime/core/eval/index.d.ts +3 -3
  48. package/dist/runtime/core/eval/index.js +11 -0
  49. package/dist/runtime/core/eval/mixins/closures.js +381 -41
  50. package/dist/runtime/core/eval/mixins/collections.js +81 -6
  51. package/dist/runtime/core/eval/mixins/control-flow.js +1 -1
  52. package/dist/runtime/core/eval/mixins/conversion.js +61 -115
  53. package/dist/runtime/core/eval/mixins/core.js +17 -4
  54. package/dist/runtime/core/eval/mixins/expressions.js +36 -27
  55. package/dist/runtime/core/eval/mixins/extraction.js +2 -3
  56. package/dist/runtime/core/eval/mixins/list-dispatch.js +1 -1
  57. package/dist/runtime/core/eval/mixins/literals.js +17 -6
  58. package/dist/runtime/core/eval/mixins/types.js +73 -54
  59. package/dist/runtime/core/eval/mixins/variables.js +12 -8
  60. package/dist/runtime/core/execute.d.ts +1 -1
  61. package/dist/runtime/core/field-descriptor.d.ts +3 -3
  62. package/dist/runtime/core/field-descriptor.js +2 -1
  63. package/dist/runtime/core/introspection.d.ts +2 -2
  64. package/dist/runtime/core/introspection.js +7 -6
  65. package/dist/runtime/core/resolvers.d.ts +1 -1
  66. package/dist/runtime/core/signals.d.ts +6 -1
  67. package/dist/runtime/core/signals.js +9 -0
  68. package/dist/runtime/core/types/constructors.d.ts +54 -0
  69. package/dist/runtime/core/types/constructors.js +201 -0
  70. package/dist/runtime/core/types/guards.d.ts +42 -0
  71. package/dist/runtime/core/types/guards.js +88 -0
  72. package/dist/runtime/core/types/index.d.ts +18 -0
  73. package/dist/runtime/core/types/index.js +19 -0
  74. package/dist/runtime/core/types/markers.d.ts +12 -0
  75. package/dist/runtime/core/types/markers.js +7 -0
  76. package/dist/runtime/core/types/operations.d.ts +98 -0
  77. package/dist/runtime/core/types/operations.js +804 -0
  78. package/dist/runtime/core/types/registrations.d.ts +126 -0
  79. package/dist/runtime/core/types/registrations.js +751 -0
  80. package/dist/runtime/core/{types.d.ts → types/runtime.d.ts} +22 -10
  81. package/dist/runtime/core/types/structures.d.ts +146 -0
  82. package/dist/runtime/core/types/structures.js +12 -0
  83. package/dist/runtime/core/values.d.ts +29 -209
  84. package/dist/runtime/core/values.js +56 -968
  85. package/dist/runtime/ext/builtins.js +88 -68
  86. package/dist/runtime/ext/extensions.d.ts +31 -125
  87. package/dist/runtime/ext/extensions.js +2 -94
  88. package/dist/runtime/ext/test-context.d.ts +28 -0
  89. package/dist/runtime/ext/test-context.js +155 -0
  90. package/dist/runtime/index.d.ts +12 -12
  91. package/dist/runtime/index.js +13 -5
  92. package/dist/signature-parser.d.ts +2 -2
  93. package/dist/signature-parser.js +14 -14
  94. package/dist/token-types.d.ts +1 -0
  95. package/dist/token-types.js +1 -0
  96. package/package.json +1 -1
  97. /package/dist/runtime/core/{types.js → types/runtime.js} +0 -0
@@ -0,0 +1,126 @@
1
+ /**
2
+ * Type Registration Definitions
3
+ *
4
+ * Defines the TypeDefinition interface, TypeProtocol interface, and
5
+ * BUILT_IN_TYPES registration array. Each of the 12 built-in types
6
+ * carries identity predicates, protocol functions (format, eq, compare,
7
+ * convertTo, serialize), and a methods record populated from BUILTIN_METHODS.
8
+ *
9
+ * Dispatch functions (inferType, formatValue, deepEquals, serializeValue,
10
+ * deserializeValue) iterate registrations and delegate to per-type
11
+ * protocol implementations.
12
+ *
13
+ * Registration order:
14
+ * primitives -> discriminator-based -> structural -> list -> dict fallback
15
+ *
16
+ * @internal
17
+ */
18
+ import type { TypeStructure, RillValue, RillFieldDef, RillTuple, RillOrdered, RillVector, RillTypeValue, RillIterator, RillStream } from './structures.js';
19
+ import type { RillFunction } from '../callable.js';
20
+ import { isStream, isTuple, isVector, isOrdered, isTypeValue, isIterator } from './guards.js';
21
+ import { createTuple, createOrdered, createVector } from './constructors.js';
22
+ /**
23
+ * Protocol functions that define per-type behavior.
24
+ * Every type must provide `format`. All other protocols are optional.
25
+ */
26
+ export interface TypeProtocol {
27
+ format: (v: RillValue) => string;
28
+ structure?: ((v: RillValue) => TypeStructure) | undefined;
29
+ eq?: ((a: RillValue, b: RillValue) => boolean) | undefined;
30
+ compare?: ((a: RillValue, b: RillValue) => number) | undefined;
31
+ convertTo?: Record<string, (v: RillValue) => RillValue> | undefined;
32
+ serialize?: ((v: RillValue) => unknown) | undefined;
33
+ deserialize?: ((data: unknown) => RillValue) | undefined;
34
+ }
35
+ /**
36
+ * A single type registration record. Each of the 12 built-in types
37
+ * has exactly one TypeDefinition in the BUILT_IN_TYPES array.
38
+ */
39
+ export interface TypeDefinition {
40
+ name: string;
41
+ identity: (v: RillValue) => boolean;
42
+ isLeaf: boolean;
43
+ immutable: boolean;
44
+ methods: Record<string, RillFunction>;
45
+ protocol: TypeProtocol;
46
+ }
47
+ /**
48
+ * All 13 built-in type registrations.
49
+ *
50
+ * Registration order:
51
+ * 1. Primitives: string, number, bool
52
+ * 2. Discriminator-based: tuple, ordered, vector, type, closure, field_descriptor
53
+ * 3. Structural: iterator, stream
54
+ * 4. list
55
+ * 5. dict (fallback, must be last)
56
+ *
57
+ * AC-1: 13 registrations, one per type.
58
+ * BC-2: Vector identity checked before dict fallback.
59
+ * EC-3: Iterator has no protocol.eq.
60
+ * EC-4: Bool has no protocol.compare.
61
+ * EC-8: Non-serializable types throw RuntimeError (RILL-R067).
62
+ */
63
+ export declare const BUILT_IN_TYPES: readonly TypeDefinition[];
64
+ /**
65
+ * Infer the Rill type name from a runtime value.
66
+ * Iterates registrations in order; returns first matching name.
67
+ * Returns 'string' as fallback (BC-1: null IS type string, not a coercion).
68
+ *
69
+ * IR-2: Return type widens from RillTypeName to string for extensibility.
70
+ */
71
+ export declare function inferType(value: RillValue): string;
72
+ /**
73
+ * Format a value as a human-readable string.
74
+ * Determines type via inferType, then calls protocol.format.
75
+ * Falls back to String(value) when no registration matches.
76
+ *
77
+ * IR-3: Protocol dispatcher for formatting.
78
+ */
79
+ export declare function formatValue(value: RillValue): string;
80
+ /**
81
+ * Deep equality comparison for two Rill values.
82
+ * Short-circuit: a === b returns true.
83
+ * Dispatches to left operand's protocol.eq.
84
+ * No protocol.eq returns false.
85
+ *
86
+ * IR-4: Container protocol.eq calls deepEquals recursively.
87
+ */
88
+ export declare function deepEquals(a: RillValue, b: RillValue): boolean;
89
+ /**
90
+ * Serialize a Rill value for JSON transport.
91
+ * Dispatches to protocol.serialize; container types recurse.
92
+ *
93
+ * IR-7: Renamed from valueToJSON.
94
+ */
95
+ export declare function serializeValue(value: RillValue): unknown;
96
+ /**
97
+ * Deserialize raw data into a Rill value.
98
+ * Dispatches to protocol.deserialize for the given type name.
99
+ * Falls back to raw value when no protocol.deserialize exists (primitives).
100
+ *
101
+ * IR-8: Raw value fallback rejects null/undefined inputs with RILL-R004.
102
+ * EC-9: Invalid data raises RILL-R004.
103
+ * EC-10: null/undefined input raises RILL-R004.
104
+ */
105
+ export declare function deserializeValue(data: unknown, typeName: string): RillValue;
106
+ /**
107
+ * Populate registration `methods` fields from BUILTIN_METHODS.
108
+ *
109
+ * Called after builtins.ts finishes initialization to avoid circular
110
+ * dependency at module load time. The 6 method-bearing types (string,
111
+ * number, bool, list, dict, vector) receive their methods records;
112
+ * other types keep `methods: {}`.
113
+ *
114
+ * AC-3: Consolidates method data into registrations.
115
+ *
116
+ * MUTATION NOTE: BUILT_IN_TYPES is shallow-frozen (the array), but each
117
+ * registration object is mutable. This function relies on that mutability.
118
+ * If registration objects are ever deep-frozen (e.g. Object.freeze(reg)),
119
+ * this assignment will throw in strict mode. The runtime guard below catches
120
+ * that condition early with a clear error rather than a silent no-op.
121
+ */
122
+ export declare function populateBuiltinMethods(builtinMethods: Record<string, Record<string, RillFunction>>): void;
123
+ export { createTuple, createOrdered, createVector };
124
+ export { isStream, isTuple, isVector, isTypeValue, isOrdered, isIterator };
125
+ export type { TypeStructure };
126
+ export type { RillValue, RillTuple, RillOrdered, RillVector, RillTypeValue, RillIterator, RillStream, RillFieldDef, };