@elaraai/e3 1.0.108 → 1.0.110

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 (101) hide show
  1. package/dist/src/environment-capture.d.ts +27 -57
  2. package/dist/src/environment-capture.d.ts.map +1 -1
  3. package/dist/src/environment-capture.js +86 -455
  4. package/dist/src/environment-capture.js.map +1 -1
  5. package/dist/src/environment-capture.spec.js +215 -5
  6. package/dist/src/environment-capture.spec.js.map +1 -1
  7. package/dist/src/environment-npm-lock.d.ts +77 -0
  8. package/dist/src/environment-npm-lock.d.ts.map +1 -0
  9. package/dist/src/environment-npm-lock.js +209 -0
  10. package/dist/src/environment-npm-lock.js.map +1 -0
  11. package/dist/src/environment-uv-lock.d.ts +312 -0
  12. package/dist/src/environment-uv-lock.d.ts.map +1 -0
  13. package/dist/src/environment-uv-lock.js +494 -0
  14. package/dist/src/environment-uv-lock.js.map +1 -0
  15. package/dist/src/export.d.ts.map +1 -1
  16. package/dist/src/export.js +25 -9
  17. package/dist/src/export.js.map +1 -1
  18. package/dist/src/export.spec.js +25 -3
  19. package/dist/src/export.spec.js.map +1 -1
  20. package/dist/src/function.d.ts +136 -57
  21. package/dist/src/function.d.ts.map +1 -1
  22. package/dist/src/function.js +47 -12
  23. package/dist/src/function.js.map +1 -1
  24. package/dist/src/function.spec.d.ts +3 -1
  25. package/dist/src/function.spec.d.ts.map +1 -1
  26. package/dist/src/function.spec.js +246 -3
  27. package/dist/src/function.spec.js.map +1 -1
  28. package/dist/src/index-input.d.ts +162 -0
  29. package/dist/src/index-input.d.ts.map +1 -0
  30. package/dist/src/index-input.js +216 -0
  31. package/dist/src/index-input.js.map +1 -0
  32. package/dist/src/index-input.spec.d.ts +6 -0
  33. package/dist/src/index-input.spec.d.ts.map +1 -0
  34. package/dist/src/index-input.spec.js +269 -0
  35. package/dist/src/index-input.spec.js.map +1 -0
  36. package/dist/src/index-read.d.ts +428 -0
  37. package/dist/src/index-read.d.ts.map +1 -0
  38. package/dist/src/index-read.js +747 -0
  39. package/dist/src/index-read.js.map +1 -0
  40. package/dist/src/index-read.spec.d.ts +6 -0
  41. package/dist/src/index-read.spec.d.ts.map +1 -0
  42. package/dist/src/index-read.spec.js +1447 -0
  43. package/dist/src/index-read.spec.js.map +1 -0
  44. package/dist/src/index.d.ts +12 -5
  45. package/dist/src/index.d.ts.map +1 -1
  46. package/dist/src/index.js +6 -3
  47. package/dist/src/index.js.map +1 -1
  48. package/dist/src/package.d.ts.map +1 -1
  49. package/dist/src/package.js +3 -4
  50. package/dist/src/package.js.map +1 -1
  51. package/dist/src/record-area.d.ts +12 -0
  52. package/dist/src/record-area.d.ts.map +1 -1
  53. package/dist/src/record-area.js +26 -0
  54. package/dist/src/record-area.js.map +1 -1
  55. package/dist/src/record-area.spec.js +4 -14
  56. package/dist/src/record-area.spec.js.map +1 -1
  57. package/dist/src/record-builders.d.ts +39 -14
  58. package/dist/src/record-builders.d.ts.map +1 -1
  59. package/dist/src/record-builders.js.map +1 -1
  60. package/dist/src/record-entries.spec.js +2 -15
  61. package/dist/src/record-entries.spec.js.map +1 -1
  62. package/dist/src/record-index.d.ts +11 -5
  63. package/dist/src/record-index.d.ts.map +1 -1
  64. package/dist/src/record-index.js.map +1 -1
  65. package/dist/src/record-interval.d.ts +7 -0
  66. package/dist/src/record-interval.d.ts.map +1 -1
  67. package/dist/src/record-interval.js +7 -0
  68. package/dist/src/record-interval.js.map +1 -1
  69. package/dist/src/record-nested-programs.d.ts +63 -511
  70. package/dist/src/record-nested-programs.d.ts.map +1 -1
  71. package/dist/src/record-nested-programs.js +403 -222
  72. package/dist/src/record-nested-programs.js.map +1 -1
  73. package/dist/src/record-nested.d.ts +60 -10
  74. package/dist/src/record-nested.d.ts.map +1 -1
  75. package/dist/src/record-nested.js +65 -23
  76. package/dist/src/record-nested.js.map +1 -1
  77. package/dist/src/record-nested.spec.js +113 -34
  78. package/dist/src/record-nested.spec.js.map +1 -1
  79. package/dist/src/record-series.spec.js +6 -31
  80. package/dist/src/record-series.spec.js.map +1 -1
  81. package/dist/src/record.d.ts +9 -0
  82. package/dist/src/record.d.ts.map +1 -1
  83. package/dist/src/record.js +14 -0
  84. package/dist/src/record.js.map +1 -1
  85. package/dist/src/runner.d.ts +14 -2
  86. package/dist/src/runner.d.ts.map +1 -1
  87. package/dist/src/runner.js +16 -4
  88. package/dist/src/runner.js.map +1 -1
  89. package/dist/src/stock-platforms.spec.js +7 -1
  90. package/dist/src/stock-platforms.spec.js.map +1 -1
  91. package/dist/src/task.d.ts +28 -16
  92. package/dist/src/task.d.ts.map +1 -1
  93. package/dist/src/task.js +33 -5
  94. package/dist/src/task.js.map +1 -1
  95. package/dist/src/test-helpers.d.ts +35 -0
  96. package/dist/src/test-helpers.d.ts.map +1 -0
  97. package/dist/src/test-helpers.js +56 -0
  98. package/dist/src/test-helpers.js.map +1 -0
  99. package/dist/src/types.d.ts +86 -13
  100. package/dist/src/types.d.ts.map +1 -1
  101. package/package.json +3 -3
@@ -0,0 +1,162 @@
1
+ /**
2
+ * Copyright (c) 2025 Elara AI Pty Ltd
3
+ * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
4
+ */
5
+ /**
6
+ * An index of a record as an input of a task, a stream task or a function.
7
+ *
8
+ * A record's index is an ordinary collection — `Dict<{ ik, k }, P>`, stored as
9
+ * a manifest of segments as the record's own rows are, and maintained in the
10
+ * same commit — whose order is the order of a read the app declared it for.
11
+ * `e3.index` hands that collection to a body, which then reads the index's
12
+ * runs with `range` and `prefix`, where a body handed the record reads every
13
+ * row.
14
+ */
15
+ import { NullType, type DictType, type EastType, type Expr, type StructType } from '@elaraai/east';
16
+ import type { DatasetDef, IndexInputDef, InputDef, PartitionDef, RecordIndexDef } from './types.js';
17
+ /** A Dict record's key type. */
18
+ type RecordKeyOf<T> = T extends DictType<infer K extends EastType, unknown> ? K : EastType;
19
+ /**
20
+ * The type of an index's entries, read off the index as its record carries it:
21
+ * `Dict<{ ik, k }, P>` — `ik` the index's key, `k` the record's, and `P` what
22
+ * the index carries. A summary index's entry stands for every row of its key,
23
+ * so its `k` is Null.
24
+ *
25
+ * @typeParam D - The index, as `record.indexes.<name>` types it
26
+ *
27
+ * @remarks
28
+ * What an index carries is what its record builds it to carry
29
+ * (`RecordIndexDef`'s `Carried`). Beside a nested series index or an entries
30
+ * index of its record, an index declared with no `value` — or one that carries
31
+ * the row, as an area or a series index does — carries the lean row: the row,
32
+ * with the fields those file emptied. The record's type says so for each of
33
+ * its indexes, so a body's parameter and {@link index}'s `type` agree.
34
+ */
35
+ export type IndexEntriesOf<D> = D extends RecordIndexDef<string, infer T, infer IK, EastType, readonly string[] | undefined, infer C> ? DictType<StructType<{
36
+ ik: IK;
37
+ k: D extends {
38
+ readonly summary: object;
39
+ } | {
40
+ readonly span: object;
41
+ } ? NullType : RecordKeyOf<T>;
42
+ }>, C> : never;
43
+ /**
44
+ * Takes an index of a record as an input of a task, a stream task or a
45
+ * function: `e3.index(record.indexes.<name>)` in its `inputs`.
46
+ *
47
+ * The body's parameter is the index's entries, a `Dict<{ ik, k }, P>` opened
48
+ * lazily and frozen, as any input is: `ik` the index's key, `k` the record's
49
+ * key, and `P` what the index carries — the row, a `value` of its own, or
50
+ * nothing; beside a nested series index or an entries index of the record,
51
+ * the lean row where it would carry nothing or the row, which the parameter's
52
+ * type says. Entries with one index key are one contiguous run, in the record's
53
+ * key order, and a range of index keys is one run too, so a body reads them
54
+ * with `prefix` and `range`, by key, by size and by a loop, each at the cost
55
+ * of the entries it reaches and never of the index. A body that reads it any
56
+ * other way decodes it whole, as it would any input.
57
+ *
58
+ * It takes an index as its record carries it by name
59
+ * (`jobs.indexes.jobs_by_press`), and the indexes e3 keeps beside one: a nested
60
+ * series index's span (`jobs.indexes.<name>.nested.span`) and an entries
61
+ * index's lean rows (`jobs.indexes.<name>.entries.rows`). To read more of a row
62
+ * than the index carries, take the record as an input beside it and read the
63
+ * row by the entry's `k`.
64
+ *
65
+ * The inputs of one record — the record, and any of its indexes — are read at
66
+ * one state of it, so a body never meets an index entry for a row it reads
67
+ * otherwise. A task that takes an index is decided again when its record
68
+ * changes, and runs again when the index it reads did; a function reads it as
69
+ * the record is stored when the call starts, and its result names the record,
70
+ * the index and the hash the record was pinned at. A record with no state yet
71
+ * makes a task wait and a call `invalid`, as it does for the record as an
72
+ * input. `e3.package` collects the index's record.
73
+ *
74
+ * Its kind's readers give a body the rows a read's words say — a series
75
+ * index's `events`, an interval index's `overlapping`, a plain index's `of`
76
+ * (`IndexRead`). An `e3.function` with a spec and an `e3.streamTask` give the
77
+ * body its parameter with the readers on it; over any other expression of the
78
+ * index's type, a task's own function's parameter among them,
79
+ * `e3.index(def).read(entries)` gives that expression with the same readers.
80
+ *
81
+ * @typeParam D - The index, as `record.indexes.<name>` types it
82
+ * @param def - The index, as its record carries it by name
83
+ * @returns The input: pass it in `inputs`; its `type` is the body's parameter, and its `read` the index's readers
84
+ * @throws {Error} When given anything but an index its record carries by name
85
+ * — a record, a dataset, a mutation, a function, an index the builder made
86
+ * before its record built it — naming what it was given and what to pass
87
+ *
88
+ * @example
89
+ * ```ts
90
+ * const jobs = e3.record('jobs', DictType(StringType, JobType), {
91
+ * initial: new Map(),
92
+ * indexes: (index) => ({ jobs_by_press: index.on(['press']) }),
93
+ * mutations: (mutation) => ({ patch: mutation.patch() }),
94
+ * });
95
+ *
96
+ * // How many jobs a press holds, read from the index alone: the run of one
97
+ * // press costs its two ends and what lies between them.
98
+ * const jobsOnPress = e3.function('jobs_on_press', {
99
+ * inputs: [e3.index(jobs.indexes.jobs_by_press)],
100
+ * args: [StringType],
101
+ * output: IntegerType,
102
+ * }, ($, jobsByPress, press) => jobsByPress.prefix({ ik: press }).size());
103
+ * ```
104
+ *
105
+ * @example
106
+ * ```ts
107
+ * // A task takes it the same way: its body's parameter is the index's type.
108
+ * const byPress = e3.index(jobs.indexes.jobs_by_press);
109
+ * const busiest = e3.task('busiest_press', [byPress, presses],
110
+ * East.function([byPress.type, PressesType], StringType, ($, jobsByPress, presses) => {
111
+ * const best = $.let("");
112
+ * const most = $.let(0n);
113
+ * $.for(presses, ($, _press, code) => {
114
+ * const count = $.const(jobsByPress.prefix({ ik: code }).size());
115
+ * $.if(East.less(most, count), ($) => { $.assign(most, count); $.assign(best, code); });
116
+ * });
117
+ * return best;
118
+ * }));
119
+ * ```
120
+ */
121
+ export declare function index<const D extends RecordIndexDef>(def: D): IndexInputDef<IndexEntriesOf<D>, D>;
122
+ /**
123
+ * A body's parameters with each index input's readers on its own: the
124
+ * parameter is still the index's entries, and its kind's readers read them.
125
+ *
126
+ * @param inputs - The inputs, in the body's parameter order
127
+ * @param params - The body's parameters: the inputs', then any others
128
+ * @returns The parameters
129
+ * @internal
130
+ */
131
+ export declare function withIndexReaders<P extends readonly Expr[]>(inputs: readonly (InputDef | PartitionDef)[], params: P): P;
132
+ /**
133
+ * The dataset an input is read through: the dataset itself, a partitioned
134
+ * input's dataset, or an index's record. What a definition's dependencies are
135
+ * collected from.
136
+ *
137
+ * @param input - The input
138
+ * @returns The dataset
139
+ * @internal
140
+ */
141
+ export declare function inputDataset(input: InputDef | PartitionDef): DatasetDef;
142
+ /**
143
+ * The type of the parameter a body is given for an input: the dataset's, a
144
+ * partitioned input's dataset's — a piece is typed as the whole — or an
145
+ * index's entries'.
146
+ *
147
+ * @param input - The input
148
+ * @returns The type
149
+ * @internal
150
+ */
151
+ export declare function inputType(input: InputDef | PartitionDef): EastType;
152
+ /**
153
+ * The name an input is refused by: a dataset's, or an index's as
154
+ * `record.index`.
155
+ *
156
+ * @param input - The input
157
+ * @returns The name
158
+ * @internal
159
+ */
160
+ export declare function inputName(input: InputDef | PartitionDef): string;
161
+ export {};
162
+ //# sourceMappingURL=index-input.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-input.d.ts","sourceRoot":"","sources":["../../src/index-input.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;GASG;AAEH,OAAO,EAAE,QAAQ,EA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AY,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,CAKtH;AAkBD;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,QAAQ,GAAG,YAAY,GAAG,UAAU,CAEvE;AAED;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,QAAQ,GAAG,YAAY,GAAG,QAAQ,CAElE;AAED;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,QAAQ,GAAG,YAAY,GAAG,MAAM,CAEhE"}
@@ -0,0 +1,216 @@
1
+ /**
2
+ * Copyright (c) 2025 Elara AI Pty Ltd
3
+ * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
4
+ */
5
+ /**
6
+ * An index of a record as an input of a task, a stream task or a function.
7
+ *
8
+ * A record's index is an ordinary collection — `Dict<{ ik, k }, P>`, stored as
9
+ * a manifest of segments as the record's own rows are, and maintained in the
10
+ * same commit — whose order is the order of a read the app declared it for.
11
+ * `e3.index` hands that collection to a body, which then reads the index's
12
+ * runs with `range` and `prefix`, where a body handed the record reads every
13
+ * row.
14
+ */
15
+ import { NullType } from '@elaraai/east';
16
+ import { indexCollectionType } from '@elaraai/e3-types';
17
+ import { readersOn } from './index-read.js';
18
+ import { isRecord } from './record.js';
19
+ import { RECORD_PART } from './record-builders.js';
20
+ import { builtIndex, summed } from './record-programs.js';
21
+ /** The words for what `e3.index` was given, when it is no index a record carries: what it is, by its kind. */
22
+ function given(value) {
23
+ if (isRecord(value)) {
24
+ const names = Object.keys(value.indexes);
25
+ const has = names.length === 0 ? 'it declares no index' : `its indexes are ${names.map((name) => `'${name}'`).join(', ')}`;
26
+ return `the record '${value.name}' itself — pass one of its indexes, as ${value.name}.indexes.<name>; ${has}`;
27
+ }
28
+ if (typeof value !== 'object' || value === null)
29
+ return value === null ? 'null' : `a ${typeof value}`;
30
+ const item = value;
31
+ const named = typeof item.name === 'string' ? ` '${item.name}'` : '';
32
+ switch (item.kind) {
33
+ case 'dataset': return `the dataset${named}, which is no record: only an e3.record has indexes`;
34
+ case 'partition': return `e3.partition of '${String(item.dataset?.name)}': a partition marks a dataset, and an index is read whole`;
35
+ case 'index': return 'an e3.index already: pass the record\'s index, as record.indexes.<name>';
36
+ case 'task': return `the task${named}: a task has no index`;
37
+ case 'recordIndex':
38
+ return `an index named '${String(item.name)}' that no record carries by that name — pass it as the record holds it, record.indexes.${String(item.name)}`;
39
+ case 'mutation': return `the mutation${named}: a mutation writes its record, and has no index — pass one of the record's indexes, as record.indexes.<name>`;
40
+ case 'migration': return `the migration${named}: a migration changes its record's type, and has no index`;
41
+ case 'function': return `the function${named}: a function has no index`;
42
+ case 'package': return `the package${named}: a package has no index`;
43
+ case 'datatree': return `the data tree${named}: only an e3.record has indexes`;
44
+ case 'array':
45
+ case 'set':
46
+ case 'dict':
47
+ case 'fold': return `e3.output.${item.kind}, an output kind: it has no index`;
48
+ }
49
+ // What a record's builders make, before a record builds it
50
+ const part = value[RECORD_PART]?.part;
51
+ if (part === 'index')
52
+ return 'an index the `index` builder made, before its record built it — declare it in e3.record\'s `indexes`, and pass record.indexes.<name>';
53
+ if (part === 'mutation' || part === 'migration')
54
+ return `a ${part} the \`${part}\` builder made, which has no index`;
55
+ return 'a value that is no definition of e3\'s';
56
+ }
57
+ /**
58
+ * Takes an index of a record as an input of a task, a stream task or a
59
+ * function: `e3.index(record.indexes.<name>)` in its `inputs`.
60
+ *
61
+ * The body's parameter is the index's entries, a `Dict<{ ik, k }, P>` opened
62
+ * lazily and frozen, as any input is: `ik` the index's key, `k` the record's
63
+ * key, and `P` what the index carries — the row, a `value` of its own, or
64
+ * nothing; beside a nested series index or an entries index of the record,
65
+ * the lean row where it would carry nothing or the row, which the parameter's
66
+ * type says. Entries with one index key are one contiguous run, in the record's
67
+ * key order, and a range of index keys is one run too, so a body reads them
68
+ * with `prefix` and `range`, by key, by size and by a loop, each at the cost
69
+ * of the entries it reaches and never of the index. A body that reads it any
70
+ * other way decodes it whole, as it would any input.
71
+ *
72
+ * It takes an index as its record carries it by name
73
+ * (`jobs.indexes.jobs_by_press`), and the indexes e3 keeps beside one: a nested
74
+ * series index's span (`jobs.indexes.<name>.nested.span`) and an entries
75
+ * index's lean rows (`jobs.indexes.<name>.entries.rows`). To read more of a row
76
+ * than the index carries, take the record as an input beside it and read the
77
+ * row by the entry's `k`.
78
+ *
79
+ * The inputs of one record — the record, and any of its indexes — are read at
80
+ * one state of it, so a body never meets an index entry for a row it reads
81
+ * otherwise. A task that takes an index is decided again when its record
82
+ * changes, and runs again when the index it reads did; a function reads it as
83
+ * the record is stored when the call starts, and its result names the record,
84
+ * the index and the hash the record was pinned at. A record with no state yet
85
+ * makes a task wait and a call `invalid`, as it does for the record as an
86
+ * input. `e3.package` collects the index's record.
87
+ *
88
+ * Its kind's readers give a body the rows a read's words say — a series
89
+ * index's `events`, an interval index's `overlapping`, a plain index's `of`
90
+ * (`IndexRead`). An `e3.function` with a spec and an `e3.streamTask` give the
91
+ * body its parameter with the readers on it; over any other expression of the
92
+ * index's type, a task's own function's parameter among them,
93
+ * `e3.index(def).read(entries)` gives that expression with the same readers.
94
+ *
95
+ * @typeParam D - The index, as `record.indexes.<name>` types it
96
+ * @param def - The index, as its record carries it by name
97
+ * @returns The input: pass it in `inputs`; its `type` is the body's parameter, and its `read` the index's readers
98
+ * @throws {Error} When given anything but an index its record carries by name
99
+ * — a record, a dataset, a mutation, a function, an index the builder made
100
+ * before its record built it — naming what it was given and what to pass
101
+ *
102
+ * @example
103
+ * ```ts
104
+ * const jobs = e3.record('jobs', DictType(StringType, JobType), {
105
+ * initial: new Map(),
106
+ * indexes: (index) => ({ jobs_by_press: index.on(['press']) }),
107
+ * mutations: (mutation) => ({ patch: mutation.patch() }),
108
+ * });
109
+ *
110
+ * // How many jobs a press holds, read from the index alone: the run of one
111
+ * // press costs its two ends and what lies between them.
112
+ * const jobsOnPress = e3.function('jobs_on_press', {
113
+ * inputs: [e3.index(jobs.indexes.jobs_by_press)],
114
+ * args: [StringType],
115
+ * output: IntegerType,
116
+ * }, ($, jobsByPress, press) => jobsByPress.prefix({ ik: press }).size());
117
+ * ```
118
+ *
119
+ * @example
120
+ * ```ts
121
+ * // A task takes it the same way: its body's parameter is the index's type.
122
+ * const byPress = e3.index(jobs.indexes.jobs_by_press);
123
+ * const busiest = e3.task('busiest_press', [byPress, presses],
124
+ * East.function([byPress.type, PressesType], StringType, ($, jobsByPress, presses) => {
125
+ * const best = $.let("");
126
+ * const most = $.let(0n);
127
+ * $.for(presses, ($, _press, code) => {
128
+ * const count = $.const(jobsByPress.prefix({ ik: code }).size());
129
+ * $.if(East.less(most, count), ($) => { $.assign(most, count); $.assign(best, code); });
130
+ * });
131
+ * return best;
132
+ * }));
133
+ * ```
134
+ */
135
+ export function index(def) {
136
+ const declared = def;
137
+ const record = typeof declared === 'object' && declared !== null && declared.kind === 'recordIndex' && isRecord(declared.record)
138
+ ? declared.record : undefined;
139
+ // The record carries it by its name: its own indexes, and those e3 keeps
140
+ // beside one — a nested series index's span, an entries index's lean rows.
141
+ if (record === undefined || typeof def.name !== 'string' || !Object.hasOwn(record.indexes, def.name) || record.indexes[def.name] !== def) {
142
+ throw new Error(`e3.index takes an index of a record, as the record carries it by name — e3.index(record.indexes.<name>) — and was given ${given(def)}`);
143
+ }
144
+ const input = {
145
+ kind: 'index', index: def, record, type: indexEntriesType(record, def),
146
+ read: (entries) => readersOn(input, entries),
147
+ };
148
+ return input;
149
+ }
150
+ /**
151
+ * A body's parameters with each index input's readers on its own: the
152
+ * parameter is still the index's entries, and its kind's readers read them.
153
+ *
154
+ * @param inputs - The inputs, in the body's parameter order
155
+ * @param params - The body's parameters: the inputs', then any others
156
+ * @returns The parameters
157
+ * @internal
158
+ */
159
+ export function withIndexReaders(inputs, params) {
160
+ inputs.forEach((input, at) => {
161
+ if (input.kind === 'index')
162
+ readersOn(input, params[at]);
163
+ });
164
+ return params;
165
+ }
166
+ /**
167
+ * The type a record's state holds an index's entries as: the index as it is
168
+ * built (`builtIndex`), in the collection the store keeps it in
169
+ * (`indexCollectionType`), a summed index's `k` Null.
170
+ *
171
+ * @param record - The record
172
+ * @param def - One of its indexes
173
+ * @returns `Dict<{ ik, k }, P>`
174
+ */
175
+ function indexEntriesType(record, def) {
176
+ const built = builtIndex(record, def);
177
+ // An index is declared over a Dict record alone, whose key is its rows'.
178
+ const rowKey = record.type.key;
179
+ return indexCollectionType(summed(built) ? NullType : rowKey, built.keyType, built.valueType);
180
+ }
181
+ /**
182
+ * The dataset an input is read through: the dataset itself, a partitioned
183
+ * input's dataset, or an index's record. What a definition's dependencies are
184
+ * collected from.
185
+ *
186
+ * @param input - The input
187
+ * @returns The dataset
188
+ * @internal
189
+ */
190
+ export function inputDataset(input) {
191
+ return input.kind === 'partition' ? input.dataset : input.kind === 'index' ? input.record : input;
192
+ }
193
+ /**
194
+ * The type of the parameter a body is given for an input: the dataset's, a
195
+ * partitioned input's dataset's — a piece is typed as the whole — or an
196
+ * index's entries'.
197
+ *
198
+ * @param input - The input
199
+ * @returns The type
200
+ * @internal
201
+ */
202
+ export function inputType(input) {
203
+ return input.kind === 'partition' ? input.dataset.type : input.type;
204
+ }
205
+ /**
206
+ * The name an input is refused by: a dataset's, or an index's as
207
+ * `record.index`.
208
+ *
209
+ * @param input - The input
210
+ * @returns The name
211
+ * @internal
212
+ */
213
+ export function inputName(input) {
214
+ return input.kind === 'partition' ? input.dataset.name : input.kind === 'index' ? `${input.record.name}.${input.index.name}` : input.name;
215
+ }
216
+ //# sourceMappingURL=index-input.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-input.js","sourceRoot":"","sources":["../../src/index-input.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;GASG;AAEH,OAAO,EAAE,QAAQ,EAA4D,MAAM,eAAe,CAAC;AACnG,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB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,MAAM,CAAC,IAA8C,CAAC,GAAG,CAAC;IAC1E,OAAO,mBAAmB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC;AAChG,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,YAAY,CAAC,KAA8B;IACzD,OAAO,KAAK,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC;AACpG,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,SAAS,CAAC,KAA8B;IACtD,OAAO,KAAK,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC;AACtE,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,SAAS,CAAC,KAA8B;IACtD,OAAO,KAAK,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,IAAI,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC;AAC5I,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Copyright (c) 2025 Elara AI Pty Ltd
3
+ * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
4
+ */
5
+ export {};
6
+ //# sourceMappingURL=index-input.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-input.spec.d.ts","sourceRoot":"","sources":["../../src/index-input.spec.ts"],"names":[],"mappings":"AAAA;;;GAGG"}