@ontrails/core 1.0.0-beta.3 → 1.0.0-beta.32
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.
- package/CHANGELOG.md +323 -8
- package/README.md +114 -33
- package/package.json +11 -1
- package/src/activation-provenance.ts +111 -0
- package/src/activation-source-compatibility.ts +430 -0
- package/src/activation-source-projection.ts +221 -0
- package/src/activation-source.ts +91 -0
- package/src/blob-ref.ts +51 -0
- package/src/branded.ts +1 -1
- package/src/compose-batch.ts +69 -0
- package/src/compose-schema.ts +36 -0
- package/src/context.ts +44 -10
- package/src/contour.ts +346 -0
- package/src/derive.ts +250 -19
- package/src/detours.ts +8 -0
- package/src/diagnostics.ts +21 -0
- package/src/draft.ts +350 -0
- package/src/error-projection.ts +51 -0
- package/src/errors.ts +335 -48
- package/src/execute.ts +1577 -0
- package/src/fire.ts +1169 -0
- package/src/glob.ts +81 -0
- package/src/index.ts +526 -35
- package/src/internal/fork-ctx.ts +69 -0
- package/src/layer-projection.ts +193 -0
- package/src/layer.ts +43 -6
- package/src/observe.ts +361 -0
- package/src/path-scope.ts +66 -0
- package/src/path-security.ts +1 -1
- package/src/permits.ts +12 -0
- package/src/redaction/patterns.ts +6 -3
- package/src/resilience.ts +11 -11
- package/src/resource-config.ts +792 -0
- package/src/resource.ts +194 -0
- package/src/result.ts +18 -0
- package/src/run.ts +76 -0
- package/src/schedule-runtime.ts +689 -0
- package/src/schedule.ts +326 -0
- package/src/serialization.ts +92 -55
- package/src/signal-diagnostics.ts +633 -0
- package/src/signal-ref.ts +87 -0
- package/src/signal.ts +104 -0
- package/src/store/accessor-protocol.ts +56 -0
- package/src/store/index.ts +4 -0
- package/src/structured-examples.ts +248 -0
- package/src/surface-derivation.ts +91 -0
- package/src/surface-filter.ts +101 -0
- package/src/surface-versioning.ts +42 -0
- package/src/topo.ts +769 -67
- package/src/tracing.ts +345 -0
- package/src/trail-id-glob.ts +15 -0
- package/src/trail.ts +1168 -30
- package/src/trails/derive-trail.ts +842 -0
- package/src/trails/index.ts +9 -0
- package/src/trails/ingest.ts +139 -0
- package/src/trails-db.ts +206 -0
- package/src/transport-error-map.ts +174 -0
- package/src/type-utils.ts +87 -0
- package/src/types.ts +254 -12
- package/src/validate-established-topo.ts +69 -0
- package/src/validate-topo.ts +414 -56
- package/src/validation.ts +152 -4
- package/src/version-marker.ts +716 -0
- package/src/version-resolution.ts +308 -0
- package/src/version-runtime.ts +120 -0
- package/src/webhook.ts +278 -0
- package/src/workspace.ts +162 -1
- package/src/zod-wrappers.ts +72 -0
- package/.turbo/turbo-build.log +0 -1
- package/.turbo/turbo-lint.log +0 -3
- package/.turbo/turbo-typecheck.log +0 -1
- package/dist/adapters.d.ts +0 -39
- package/dist/adapters.d.ts.map +0 -1
- package/dist/adapters.js +0 -2
- package/dist/adapters.js.map +0 -1
- package/dist/blob-ref.d.ts +0 -20
- package/dist/blob-ref.d.ts.map +0 -1
- package/dist/blob-ref.js +0 -22
- package/dist/blob-ref.js.map +0 -1
- package/dist/branded.d.ts +0 -36
- package/dist/branded.d.ts.map +0 -1
- package/dist/branded.js +0 -89
- package/dist/branded.js.map +0 -1
- package/dist/collections.d.ts +0 -31
- package/dist/collections.d.ts.map +0 -1
- package/dist/collections.js +0 -60
- package/dist/collections.js.map +0 -1
- package/dist/context.d.ts +0 -10
- package/dist/context.d.ts.map +0 -1
- package/dist/context.js +0 -15
- package/dist/context.js.map +0 -1
- package/dist/derive.d.ts +0 -33
- package/dist/derive.d.ts.map +0 -1
- package/dist/derive.js +0 -125
- package/dist/derive.js.map +0 -1
- package/dist/errors.d.ts +0 -83
- package/dist/errors.d.ts.map +0 -1
- package/dist/errors.js +0 -142
- package/dist/errors.js.map +0 -1
- package/dist/event.d.ts +0 -45
- package/dist/event.d.ts.map +0 -1
- package/dist/event.js +0 -17
- package/dist/event.js.map +0 -1
- package/dist/fetch.d.ts +0 -15
- package/dist/fetch.d.ts.map +0 -1
- package/dist/fetch.js +0 -102
- package/dist/fetch.js.map +0 -1
- package/dist/guards.d.ts +0 -17
- package/dist/guards.d.ts.map +0 -1
- package/dist/guards.js +0 -25
- package/dist/guards.js.map +0 -1
- package/dist/health.d.ts +0 -18
- package/dist/health.d.ts.map +0 -1
- package/dist/health.js +0 -5
- package/dist/health.js.map +0 -1
- package/dist/hike.d.ts +0 -36
- package/dist/hike.d.ts.map +0 -1
- package/dist/hike.js +0 -20
- package/dist/hike.js.map +0 -1
- package/dist/index.d.ts +0 -36
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -40
- package/dist/index.js.map +0 -1
- package/dist/job.d.ts +0 -24
- package/dist/job.d.ts.map +0 -1
- package/dist/job.js +0 -17
- package/dist/job.js.map +0 -1
- package/dist/layer.d.ts +0 -17
- package/dist/layer.d.ts.map +0 -1
- package/dist/layer.js +0 -21
- package/dist/layer.js.map +0 -1
- package/dist/path-security.d.ts +0 -28
- package/dist/path-security.d.ts.map +0 -1
- package/dist/path-security.js +0 -63
- package/dist/path-security.js.map +0 -1
- package/dist/patterns/bulk.d.ts +0 -15
- package/dist/patterns/bulk.d.ts.map +0 -1
- package/dist/patterns/bulk.js +0 -14
- package/dist/patterns/bulk.js.map +0 -1
- package/dist/patterns/change.d.ts +0 -10
- package/dist/patterns/change.d.ts.map +0 -1
- package/dist/patterns/change.js +0 -10
- package/dist/patterns/change.js.map +0 -1
- package/dist/patterns/date-range.d.ts +0 -10
- package/dist/patterns/date-range.d.ts.map +0 -1
- package/dist/patterns/date-range.js +0 -10
- package/dist/patterns/date-range.js.map +0 -1
- package/dist/patterns/index.d.ts +0 -9
- package/dist/patterns/index.d.ts.map +0 -1
- package/dist/patterns/index.js +0 -9
- package/dist/patterns/index.js.map +0 -1
- package/dist/patterns/pagination.d.ts +0 -18
- package/dist/patterns/pagination.d.ts.map +0 -1
- package/dist/patterns/pagination.js +0 -18
- package/dist/patterns/pagination.js.map +0 -1
- package/dist/patterns/progress.d.ts +0 -11
- package/dist/patterns/progress.d.ts.map +0 -1
- package/dist/patterns/progress.js +0 -11
- package/dist/patterns/progress.js.map +0 -1
- package/dist/patterns/sorting.d.ts +0 -13
- package/dist/patterns/sorting.d.ts.map +0 -1
- package/dist/patterns/sorting.js +0 -10
- package/dist/patterns/sorting.js.map +0 -1
- package/dist/patterns/status.d.ts +0 -15
- package/dist/patterns/status.d.ts.map +0 -1
- package/dist/patterns/status.js +0 -9
- package/dist/patterns/status.js.map +0 -1
- package/dist/patterns/timestamps.d.ts +0 -10
- package/dist/patterns/timestamps.d.ts.map +0 -1
- package/dist/patterns/timestamps.js +0 -10
- package/dist/patterns/timestamps.js.map +0 -1
- package/dist/redaction/index.d.ts +0 -4
- package/dist/redaction/index.d.ts.map +0 -1
- package/dist/redaction/index.js +0 -3
- package/dist/redaction/index.js.map +0 -1
- package/dist/redaction/patterns.d.ts +0 -9
- package/dist/redaction/patterns.d.ts.map +0 -1
- package/dist/redaction/patterns.js +0 -39
- package/dist/redaction/patterns.js.map +0 -1
- package/dist/redaction/redactor.d.ts +0 -27
- package/dist/redaction/redactor.d.ts.map +0 -1
- package/dist/redaction/redactor.js +0 -89
- package/dist/redaction/redactor.js.map +0 -1
- package/dist/resilience.d.ts +0 -34
- package/dist/resilience.d.ts.map +0 -1
- package/dist/resilience.js +0 -164
- package/dist/resilience.js.map +0 -1
- package/dist/result.d.ts +0 -57
- package/dist/result.d.ts.map +0 -1
- package/dist/result.js +0 -156
- package/dist/result.js.map +0 -1
- package/dist/serialization.d.ts +0 -27
- package/dist/serialization.d.ts.map +0 -1
- package/dist/serialization.js +0 -153
- package/dist/serialization.js.map +0 -1
- package/dist/topo.d.ts +0 -18
- package/dist/topo.d.ts.map +0 -1
- package/dist/topo.js +0 -80
- package/dist/topo.js.map +0 -1
- package/dist/trail.d.ts +0 -83
- package/dist/trail.d.ts.map +0 -1
- package/dist/trail.js +0 -16
- package/dist/trail.js.map +0 -1
- package/dist/types.d.ts +0 -46
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
- package/dist/validate-topo.d.ts +0 -24
- package/dist/validate-topo.d.ts.map +0 -1
- package/dist/validate-topo.js +0 -156
- package/dist/validate-topo.js.map +0 -1
- package/dist/validation.d.ts +0 -27
- package/dist/validation.d.ts.map +0 -1
- package/dist/validation.js +0 -134
- package/dist/validation.js.map +0 -1
- package/dist/workspace.d.ts +0 -25
- package/dist/workspace.d.ts.map +0 -1
- package/dist/workspace.js +0 -57
- package/dist/workspace.js.map +0 -1
- package/src/__tests__/blob-ref.test.ts +0 -103
- package/src/__tests__/branded.test.ts +0 -148
- package/src/__tests__/collections.test.ts +0 -126
- package/src/__tests__/context.test.ts +0 -66
- package/src/__tests__/derive.test.ts +0 -203
- package/src/__tests__/errors.test.ts +0 -309
- package/src/__tests__/event.test.ts +0 -82
- package/src/__tests__/fetch.test.ts +0 -217
- package/src/__tests__/guards.test.ts +0 -102
- package/src/__tests__/hike.test.ts +0 -117
- package/src/__tests__/job.test.ts +0 -98
- package/src/__tests__/layer.test.ts +0 -224
- package/src/__tests__/path-security.test.ts +0 -114
- package/src/__tests__/patterns.test.ts +0 -273
- package/src/__tests__/redaction.test.ts +0 -244
- package/src/__tests__/resilience.test.ts +0 -246
- package/src/__tests__/result.test.ts +0 -155
- package/src/__tests__/serialization.test.ts +0 -401
- package/src/__tests__/topo.test.ts +0 -220
- package/src/__tests__/trail.test.ts +0 -179
- package/src/__tests__/validate-topo.test.ts +0 -280
- package/src/__tests__/validation.test.ts +0 -283
- package/src/__tests__/workspace.test.ts +0 -183
- package/src/adapters.ts +0 -68
- package/src/event.ts +0 -77
- package/src/health.ts +0 -23
- package/src/hike.ts +0 -77
- package/src/job.ts +0 -20
- package/tsconfig.json +0 -9
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import { describe, test, expect } from 'bun:test';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
brand,
|
|
5
|
-
unbrand,
|
|
6
|
-
uuid,
|
|
7
|
-
email,
|
|
8
|
-
nonEmptyString,
|
|
9
|
-
positiveInt,
|
|
10
|
-
shortId,
|
|
11
|
-
hashId,
|
|
12
|
-
} from '../branded';
|
|
13
|
-
|
|
14
|
-
describe('branded', () => {
|
|
15
|
-
describe('brand / unbrand', () => {
|
|
16
|
-
test('brand wraps and unbrand unwraps', () => {
|
|
17
|
-
const branded = brand('Tag', 'hello');
|
|
18
|
-
expect(unbrand(branded)).toBe('hello');
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
test('branded value is still usable as base type at runtime', () => {
|
|
22
|
-
const branded = brand('PositiveInt', 42);
|
|
23
|
-
expect(branded + 1).toBe(43);
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
describe('uuid()', () => {
|
|
28
|
-
test('accepts a valid v4 UUID', () => {
|
|
29
|
-
const result = uuid('550e8400-e29b-41d4-a716-446655440000');
|
|
30
|
-
expect(result.isOk()).toBe(true);
|
|
31
|
-
const value: string = unbrand(result.unwrap());
|
|
32
|
-
expect(value).toBe('550e8400-e29b-41d4-a716-446655440000');
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
test('rejects an empty string', () => {
|
|
36
|
-
const result = uuid('');
|
|
37
|
-
expect(result.isErr()).toBe(true);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
test('rejects a malformed UUID', () => {
|
|
41
|
-
const result = uuid('not-a-uuid');
|
|
42
|
-
expect(result.isErr()).toBe(true);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
test('rejects UUID missing hyphens', () => {
|
|
46
|
-
const result = uuid('550e8400e29b41d4a716446655440000');
|
|
47
|
-
expect(result.isErr()).toBe(true);
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
describe('email()', () => {
|
|
52
|
-
test('accepts a simple email', () => {
|
|
53
|
-
const result = email('test@example.com');
|
|
54
|
-
expect(result.isOk()).toBe(true);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
test('rejects missing @', () => {
|
|
58
|
-
const result = email('testexample.com');
|
|
59
|
-
expect(result.isErr()).toBe(true);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
test('rejects missing domain', () => {
|
|
63
|
-
const result = email('test@');
|
|
64
|
-
expect(result.isErr()).toBe(true);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
test('rejects empty string', () => {
|
|
68
|
-
const result = email('');
|
|
69
|
-
expect(result.isErr()).toBe(true);
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
describe('nonEmptyString()', () => {
|
|
74
|
-
test('accepts a non-empty string', () => {
|
|
75
|
-
const result = nonEmptyString('hello');
|
|
76
|
-
expect(result.isOk()).toBe(true);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
test('rejects an empty string', () => {
|
|
80
|
-
const result = nonEmptyString('');
|
|
81
|
-
expect(result.isErr()).toBe(true);
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
describe('positiveInt()', () => {
|
|
86
|
-
test('accepts 1', () => {
|
|
87
|
-
const result = positiveInt(1);
|
|
88
|
-
expect(result.isOk()).toBe(true);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
test('accepts a large integer', () => {
|
|
92
|
-
const result = positiveInt(1_000_000);
|
|
93
|
-
expect(result.isOk()).toBe(true);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
test('rejects 0', () => {
|
|
97
|
-
const result = positiveInt(0);
|
|
98
|
-
expect(result.isErr()).toBe(true);
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
test('rejects negative numbers', () => {
|
|
102
|
-
const result = positiveInt(-5);
|
|
103
|
-
expect(result.isErr()).toBe(true);
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
test('rejects non-integers', () => {
|
|
107
|
-
const result = positiveInt(1.5);
|
|
108
|
-
expect(result.isErr()).toBe(true);
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
describe('shortId()', () => {
|
|
113
|
-
test('returns a string of default length 8', () => {
|
|
114
|
-
const id = shortId();
|
|
115
|
-
expect(id).toHaveLength(8);
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
test('respects custom length', () => {
|
|
119
|
-
const id = shortId(16);
|
|
120
|
-
expect(id).toHaveLength(16);
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
test('contains only alphanumeric characters', () => {
|
|
124
|
-
const id = shortId(100);
|
|
125
|
-
expect(id).toMatch(/^[A-Za-z0-9]+$/);
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
test('produces unique values', () => {
|
|
129
|
-
const ids = new Set(Array.from({ length: 50 }, () => shortId()));
|
|
130
|
-
expect(ids.size).toBe(50);
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
describe('hashId()', () => {
|
|
135
|
-
test('returns a hex string', () => {
|
|
136
|
-
const id = hashId('test');
|
|
137
|
-
expect(id).toMatch(/^[0-9a-f]{8}$/);
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
test('is deterministic', () => {
|
|
141
|
-
expect(hashId('hello')).toBe(hashId('hello'));
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
test('different inputs produce different outputs', () => {
|
|
145
|
-
expect(hashId('a')).not.toBe(hashId('b'));
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
});
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import { describe, test, expect } from 'bun:test';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
chunk,
|
|
5
|
-
dedupe,
|
|
6
|
-
groupBy,
|
|
7
|
-
sortBy,
|
|
8
|
-
isNonEmptyArray,
|
|
9
|
-
} from '../collections';
|
|
10
|
-
|
|
11
|
-
describe('collections', () => {
|
|
12
|
-
describe('chunk()', () => {
|
|
13
|
-
test('splits into even chunks', () => {
|
|
14
|
-
expect(chunk([1, 2, 3, 4], 2)).toEqual([
|
|
15
|
-
[1, 2],
|
|
16
|
-
[3, 4],
|
|
17
|
-
]);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
test('handles remainder', () => {
|
|
21
|
-
expect(chunk([1, 2, 3, 4, 5], 2)).toEqual([[1, 2], [3, 4], [5]]);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
test('returns empty array for empty input', () => {
|
|
25
|
-
expect(chunk([], 3)).toEqual([]);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
test('single-element chunks', () => {
|
|
29
|
-
expect(chunk([1, 2, 3], 1)).toEqual([[1], [2], [3]]);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
test('chunk size larger than array', () => {
|
|
33
|
-
expect(chunk([1, 2], 10)).toEqual([[1, 2]]);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
test('throws on size < 1', () => {
|
|
37
|
-
expect(() => chunk([1], 0)).toThrow(RangeError);
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
describe('dedupe()', () => {
|
|
42
|
-
test('removes primitive duplicates', () => {
|
|
43
|
-
expect(dedupe([1, 2, 2, 3, 1])).toEqual([1, 2, 3]);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
test('dedupes by key function', () => {
|
|
47
|
-
const items = [
|
|
48
|
-
{ id: 1, name: 'a' },
|
|
49
|
-
{ id: 2, name: 'b' },
|
|
50
|
-
{ id: 1, name: 'c' },
|
|
51
|
-
];
|
|
52
|
-
const result = dedupe(items, (i) => i.id);
|
|
53
|
-
expect(result).toEqual([
|
|
54
|
-
{ id: 1, name: 'a' },
|
|
55
|
-
{ id: 2, name: 'b' },
|
|
56
|
-
]);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
test('preserves order', () => {
|
|
60
|
-
expect(dedupe([3, 1, 2, 1, 3])).toEqual([3, 1, 2]);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
test('handles empty array', () => {
|
|
64
|
-
expect(dedupe([])).toEqual([]);
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
describe('groupBy()', () => {
|
|
69
|
-
test('groups by key', () => {
|
|
70
|
-
const items = [
|
|
71
|
-
{ type: 'a', value: 1 },
|
|
72
|
-
{ type: 'b', value: 2 },
|
|
73
|
-
{ type: 'a', value: 3 },
|
|
74
|
-
];
|
|
75
|
-
const groups = groupBy(items, (i) => i.type);
|
|
76
|
-
expect(groups).toEqual({
|
|
77
|
-
a: [
|
|
78
|
-
{ type: 'a', value: 1 },
|
|
79
|
-
{ type: 'a', value: 3 },
|
|
80
|
-
],
|
|
81
|
-
b: [{ type: 'b', value: 2 }],
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
test('returns empty object for empty array', () => {
|
|
86
|
-
expect(groupBy([], () => 'key')).toEqual({});
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
describe('sortBy()', () => {
|
|
91
|
-
test('sorts by numeric key ascending', () => {
|
|
92
|
-
const items = [{ n: 3 }, { n: 1 }, { n: 2 }];
|
|
93
|
-
expect(sortBy(items, (i) => i.n)).toEqual([{ n: 1 }, { n: 2 }, { n: 3 }]);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
test('sorts by string key alphabetically', () => {
|
|
97
|
-
const items = [{ name: 'charlie' }, { name: 'alice' }, { name: 'bob' }];
|
|
98
|
-
expect(sortBy(items, (i) => i.name)).toEqual([
|
|
99
|
-
{ name: 'alice' },
|
|
100
|
-
{ name: 'bob' },
|
|
101
|
-
{ name: 'charlie' },
|
|
102
|
-
]);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
test('does not mutate the original array', () => {
|
|
106
|
-
const original = [{ n: 3 }, { n: 1 }];
|
|
107
|
-
sortBy(original, (i) => i.n);
|
|
108
|
-
expect(original[0]?.n).toBe(3);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
test('returns empty array for empty input', () => {
|
|
112
|
-
expect(sortBy([], () => 0)).toEqual([]);
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
describe('isNonEmptyArray()', () => {
|
|
117
|
-
test('returns true for arrays with elements', () => {
|
|
118
|
-
expect(isNonEmptyArray([1])).toBe(true);
|
|
119
|
-
expect(isNonEmptyArray([1, 2, 3])).toBe(true);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
test('returns false for empty array', () => {
|
|
123
|
-
expect(isNonEmptyArray([])).toBe(false);
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
});
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { describe, test, expect } from 'bun:test';
|
|
2
|
-
|
|
3
|
-
import { createTrailContext } from '../context.js';
|
|
4
|
-
import type { TrailContext } from '../types.js';
|
|
5
|
-
|
|
6
|
-
const UUID_RE =
|
|
7
|
-
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
8
|
-
|
|
9
|
-
describe('createTrailContext', () => {
|
|
10
|
-
test('generates a requestId in UUID format', () => {
|
|
11
|
-
const ctx = createTrailContext();
|
|
12
|
-
expect(ctx.requestId).toMatch(UUID_RE);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
test('defaults cwd to process.cwd()', () => {
|
|
16
|
-
const ctx = createTrailContext();
|
|
17
|
-
expect(ctx.cwd).toBe(process.cwd());
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
test('defaults env to process.env', () => {
|
|
21
|
-
const ctx = createTrailContext();
|
|
22
|
-
expect(ctx.env).toBeTruthy();
|
|
23
|
-
expect(ctx.env).toBe(process.env);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
test('provides a non-aborted signal by default', () => {
|
|
27
|
-
const ctx = createTrailContext();
|
|
28
|
-
expect(ctx.signal).toBeInstanceOf(AbortSignal);
|
|
29
|
-
expect(ctx.signal.aborted).toBe(false);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
test('override values take precedence', () => {
|
|
33
|
-
const ac = new AbortController();
|
|
34
|
-
ac.abort();
|
|
35
|
-
|
|
36
|
-
const ctx = createTrailContext({
|
|
37
|
-
cwd: '/custom/dir',
|
|
38
|
-
env: { CUSTOM: 'yes' },
|
|
39
|
-
requestId: 'custom-id',
|
|
40
|
-
signal: ac.signal,
|
|
41
|
-
workspaceRoot: '/tmp',
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
expect(ctx.cwd).toBe('/custom/dir');
|
|
45
|
-
expect(ctx.env).toEqual({ CUSTOM: 'yes' });
|
|
46
|
-
expect(ctx.requestId).toBe('custom-id');
|
|
47
|
-
expect(ctx.signal.aborted).toBe(true);
|
|
48
|
-
expect(ctx.workspaceRoot).toBe('/tmp');
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
test('TrailContext is extensible with custom fields', () => {
|
|
52
|
-
const ctx: TrailContext = createTrailContext({
|
|
53
|
-
customField: 42,
|
|
54
|
-
nested: { key: 'value' },
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
expect(ctx['customField']).toBe(42);
|
|
58
|
-
expect(ctx['nested']).toEqual({ key: 'value' });
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
test('each call generates a unique requestId', () => {
|
|
62
|
-
const a = createTrailContext();
|
|
63
|
-
const b = createTrailContext();
|
|
64
|
-
expect(a.requestId).not.toBe(b.requestId);
|
|
65
|
-
});
|
|
66
|
-
});
|
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
import { describe, test, expect } from 'bun:test';
|
|
2
|
-
|
|
3
|
-
import { z } from 'zod';
|
|
4
|
-
|
|
5
|
-
import { deriveFields } from '../derive.js';
|
|
6
|
-
|
|
7
|
-
// ---------------------------------------------------------------------------
|
|
8
|
-
// Tests
|
|
9
|
-
// ---------------------------------------------------------------------------
|
|
10
|
-
|
|
11
|
-
describe('derive', () => {
|
|
12
|
-
describe('primitive types', () => {
|
|
13
|
-
test('z.string() derives string field', () => {
|
|
14
|
-
const schema = z.object({ name: z.string() });
|
|
15
|
-
const fields = deriveFields(schema);
|
|
16
|
-
expect(fields).toHaveLength(1);
|
|
17
|
-
expect(fields[0]).toMatchObject({
|
|
18
|
-
label: 'Name',
|
|
19
|
-
name: 'name',
|
|
20
|
-
required: true,
|
|
21
|
-
type: 'string',
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
test('z.number() derives number field', () => {
|
|
26
|
-
const schema = z.object({ count: z.number() });
|
|
27
|
-
const fields = deriveFields(schema);
|
|
28
|
-
expect(fields[0]).toMatchObject({
|
|
29
|
-
name: 'count',
|
|
30
|
-
required: true,
|
|
31
|
-
type: 'number',
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
test('z.boolean() derives boolean field', () => {
|
|
36
|
-
const schema = z.object({ verbose: z.boolean() });
|
|
37
|
-
const fields = deriveFields(schema);
|
|
38
|
-
expect(fields[0]).toMatchObject({
|
|
39
|
-
name: 'verbose',
|
|
40
|
-
required: true,
|
|
41
|
-
type: 'boolean',
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
describe('enum and multiselect', () => {
|
|
47
|
-
test('z.enum() derives enum field with options', () => {
|
|
48
|
-
const schema = z.object({ color: z.enum(['red', 'green', 'blue']) });
|
|
49
|
-
const fields = deriveFields(schema);
|
|
50
|
-
expect(fields[0]).toMatchObject({
|
|
51
|
-
name: 'color',
|
|
52
|
-
required: true,
|
|
53
|
-
type: 'enum',
|
|
54
|
-
});
|
|
55
|
-
expect(fields[0]?.options).toEqual([
|
|
56
|
-
{ value: 'red' },
|
|
57
|
-
{ value: 'green' },
|
|
58
|
-
{ value: 'blue' },
|
|
59
|
-
]);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
test('z.array(z.enum()) derives multiselect field', () => {
|
|
63
|
-
const schema = z.object({
|
|
64
|
-
tags: z.array(z.enum(['a', 'b', 'c'])),
|
|
65
|
-
});
|
|
66
|
-
const fields = deriveFields(schema);
|
|
67
|
-
expect(fields[0]).toMatchObject({
|
|
68
|
-
name: 'tags',
|
|
69
|
-
required: true,
|
|
70
|
-
type: 'multiselect',
|
|
71
|
-
});
|
|
72
|
-
expect(fields[0]?.options).toEqual([
|
|
73
|
-
{ value: 'a' },
|
|
74
|
-
{ value: 'b' },
|
|
75
|
-
{ value: 'c' },
|
|
76
|
-
]);
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
describe('array types', () => {
|
|
81
|
-
test('z.array(z.string()) derives string[] field', () => {
|
|
82
|
-
const schema = z.object({ names: z.array(z.string()) });
|
|
83
|
-
const fields = deriveFields(schema);
|
|
84
|
-
expect(fields[0]).toMatchObject({
|
|
85
|
-
name: 'names',
|
|
86
|
-
options: undefined,
|
|
87
|
-
required: true,
|
|
88
|
-
type: 'string[]',
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
test('z.array(z.number()) derives number[] field', () => {
|
|
93
|
-
const schema = z.object({ scores: z.array(z.number()) });
|
|
94
|
-
const fields = deriveFields(schema);
|
|
95
|
-
expect(fields[0]).toMatchObject({
|
|
96
|
-
name: 'scores',
|
|
97
|
-
options: undefined,
|
|
98
|
-
required: true,
|
|
99
|
-
type: 'number[]',
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
test('optional z.array(z.string()) marks not required', () => {
|
|
104
|
-
const schema = z.object({ tags: z.array(z.string()).optional() });
|
|
105
|
-
const fields = deriveFields(schema);
|
|
106
|
-
expect(fields[0]).toMatchObject({
|
|
107
|
-
name: 'tags',
|
|
108
|
-
required: false,
|
|
109
|
-
type: 'string[]',
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
test('z.array(z.string()) with default sets default value', () => {
|
|
114
|
-
const schema = z.object({
|
|
115
|
-
items: z.array(z.string()).default(['a', 'b']),
|
|
116
|
-
});
|
|
117
|
-
const fields = deriveFields(schema);
|
|
118
|
-
expect(fields[0]?.required).toBe(false);
|
|
119
|
-
expect(fields[0]?.type).toBe('string[]');
|
|
120
|
-
expect(fields[0]?.default).toEqual(['a', 'b']);
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
describe('modifiers', () => {
|
|
125
|
-
test('.describe() sets label', () => {
|
|
126
|
-
const schema = z.object({
|
|
127
|
-
name: z.string().describe('Your full name'),
|
|
128
|
-
});
|
|
129
|
-
const fields = deriveFields(schema);
|
|
130
|
-
expect(fields[0]?.label).toBe('Your full name');
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
test('.default() sets default and marks not required', () => {
|
|
134
|
-
const schema = z.object({
|
|
135
|
-
port: z.number().default(3000),
|
|
136
|
-
});
|
|
137
|
-
const fields = deriveFields(schema);
|
|
138
|
-
expect(fields[0]?.required).toBe(false);
|
|
139
|
-
expect(fields[0]?.default).toBe(3000);
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
test('.optional() marks not required', () => {
|
|
143
|
-
const schema = z.object({
|
|
144
|
-
nickname: z.string().optional(),
|
|
145
|
-
});
|
|
146
|
-
const fields = deriveFields(schema);
|
|
147
|
-
expect(fields[0]?.required).toBe(false);
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
describe('overrides', () => {
|
|
152
|
-
test('override label replaces derived label', () => {
|
|
153
|
-
const schema = z.object({
|
|
154
|
-
name: z.string().describe('Derived label'),
|
|
155
|
-
});
|
|
156
|
-
const fields = deriveFields(schema, {
|
|
157
|
-
name: { label: 'Override label' },
|
|
158
|
-
});
|
|
159
|
-
expect(fields[0]?.label).toBe('Override label');
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
test('override options enrich enum values with labels and hints', () => {
|
|
163
|
-
const schema = z.object({
|
|
164
|
-
color: z.enum(['red', 'green', 'blue']),
|
|
165
|
-
});
|
|
166
|
-
const fields = deriveFields(schema, {
|
|
167
|
-
color: {
|
|
168
|
-
options: [
|
|
169
|
-
{ hint: 'Hot color', label: 'Red', value: 'red' },
|
|
170
|
-
{ label: 'Green', value: 'green' },
|
|
171
|
-
],
|
|
172
|
-
},
|
|
173
|
-
});
|
|
174
|
-
expect(fields[0]?.options).toEqual([
|
|
175
|
-
{ hint: 'Hot color', label: 'Red', value: 'red' },
|
|
176
|
-
{ label: 'Green', value: 'green' },
|
|
177
|
-
{ value: 'blue' },
|
|
178
|
-
]);
|
|
179
|
-
});
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
describe('sorting and edge cases', () => {
|
|
183
|
-
test('returns fields sorted by name', () => {
|
|
184
|
-
const schema = z.object({
|
|
185
|
-
alpha: z.string(),
|
|
186
|
-
middle: z.string(),
|
|
187
|
-
zebra: z.string(),
|
|
188
|
-
});
|
|
189
|
-
const fields = deriveFields(schema);
|
|
190
|
-
expect(fields.map((f) => f.name)).toEqual(['alpha', 'middle', 'zebra']);
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
test('returns empty array for non-object schema', () => {
|
|
194
|
-
expect(deriveFields(z.string())).toEqual([]);
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
test('humanizes camelCase field names', () => {
|
|
198
|
-
const schema = z.object({ firstName: z.string() });
|
|
199
|
-
const fields = deriveFields(schema);
|
|
200
|
-
expect(fields[0]?.label).toBe('First Name');
|
|
201
|
-
});
|
|
202
|
-
});
|
|
203
|
-
});
|