@ontrails/core 1.0.0-beta.4 → 1.0.0-beta.6
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/.turbo/turbo-lint.log +1 -1
- package/CHANGELOG.md +20 -0
- package/README.md +9 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/type-utils.d.ts +13 -0
- package/dist/type-utils.d.ts.map +1 -0
- package/dist/type-utils.js +12 -0
- package/dist/type-utils.js.map +1 -0
- package/package.json +1 -1
- package/src/__tests__/type-utils.test.ts +70 -0
- package/src/index.ts +4 -0
- package/src/type-utils.ts +33 -0
- package/tsconfig.tsbuildinfo +1 -1
package/.turbo/turbo-lint.log
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @ontrails/core
|
|
2
2
|
|
|
3
|
+
## 1.0.0-beta.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Fix Codex review findings on type-utils and follow-declarations.
|
|
8
|
+
|
|
9
|
+
**core**: `inputOf()`/`outputOf()` now preserve the exact Zod schema subtype instead of widening to `z.ZodType`.
|
|
10
|
+
|
|
11
|
+
**warden**: `follow-declarations` rule now recognizes single-object trail overload, detects any context parameter name (not just `ctx`), matches destructured `follow()` calls, resolves const identifiers in `follow` arrays, and restricts run body extraction to top-level config properties.
|
|
12
|
+
|
|
13
|
+
## 1.0.0-beta.5
|
|
14
|
+
|
|
15
|
+
### Minor Changes
|
|
16
|
+
|
|
17
|
+
- Type utilities and follow-declarations warden rule.
|
|
18
|
+
|
|
19
|
+
**core**: Add `TrailInput<T>`, `TrailOutput<T>` utility types and `inputOf()`, `outputOf()` runtime schema accessors.
|
|
20
|
+
|
|
21
|
+
**warden**: Add `follow-declarations` rule — statically analyzes `ctx.follow()` calls against declared `follow: [...]` arrays. Errors on undeclared calls, warns on unused declarations.
|
|
22
|
+
|
|
3
23
|
## 1.0.0-beta.4
|
|
4
24
|
|
|
5
25
|
### Major Changes
|
package/README.md
CHANGED
|
@@ -46,6 +46,15 @@ const onboard = trail('entity.onboard', {
|
|
|
46
46
|
| `topo(name, ...modules)` | Collect trail modules into a queryable topology |
|
|
47
47
|
| `validateTopo(topo)` | Structural validation: follow targets exist, no cycles, examples parse, output schemas present |
|
|
48
48
|
|
|
49
|
+
### Type utilities
|
|
50
|
+
|
|
51
|
+
| Export | What it does |
|
|
52
|
+
| --- | --- |
|
|
53
|
+
| `TrailInput<T>` | Extract the input type from a `Trail` |
|
|
54
|
+
| `TrailOutput<T>` | Extract the output type from a `Trail` |
|
|
55
|
+
| `inputOf(trail)` | Get the input Zod schema from a trail instance |
|
|
56
|
+
| `outputOf(trail)` | Get the output Zod schema (or `undefined`) from a trail instance |
|
|
57
|
+
|
|
49
58
|
### Result
|
|
50
59
|
|
|
51
60
|
```typescript
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,8 @@ export type { Implementation, TrailContext, FollowFn, ProgressCallback, Progress
|
|
|
5
5
|
export { createTrailContext } from './context.js';
|
|
6
6
|
export { trail } from './trail.js';
|
|
7
7
|
export type { AnyTrail, Intent, Trail, TrailSpec, TrailExample, } from './trail.js';
|
|
8
|
+
export type { TrailInput, TrailOutput } from './type-utils.js';
|
|
9
|
+
export { inputOf, outputOf } from './type-utils.js';
|
|
8
10
|
export { event } from './event.js';
|
|
9
11
|
export type { AnyEvent, Event, EventSpec } from './event.js';
|
|
10
12
|
export { topo } from './topo.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAGrC,OAAO,EACL,WAAW,EACX,eAAe,EACf,cAAc,EACd,cAAc,EACd,aAAa,EACb,kBAAkB,EAClB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,EACR,UAAU,GACX,MAAM,kBAAkB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@ export { TrailsError, ValidationError, AmbiguousError, AssertionError, NotFoundE
|
|
|
6
6
|
export { createTrailContext } from './context.js';
|
|
7
7
|
// Trail
|
|
8
8
|
export { trail } from './trail.js';
|
|
9
|
+
export { inputOf, outputOf } from './type-utils.js';
|
|
9
10
|
// Event
|
|
10
11
|
export { event } from './event.js';
|
|
11
12
|
// Topo
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,SAAS;AACT,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,SAAS;AACT,OAAO,EACL,WAAW,EACX,eAAe,EACf,cAAc,EACd,cAAc,EACd,aAAa,EACb,kBAAkB,EAClB,aAAa,EACb,eAAe,EACf,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,aAAa,EACb,SAAS,EACT,cAAc,EACd,WAAW,EACX,aAAa,EACb,cAAc,EACd,YAAY,EACZ,WAAW,EACX,aAAa,GACd,MAAM,aAAa,CAAC;AAcrB,kBAAkB;AAClB,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAElD,QAAQ;AACR,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,SAAS;AACT,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,SAAS;AACT,OAAO,EACL,WAAW,EACX,eAAe,EACf,cAAc,EACd,cAAc,EACd,aAAa,EACb,kBAAkB,EAClB,aAAa,EACb,eAAe,EACf,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,aAAa,EACb,SAAS,EACT,cAAc,EACd,WAAW,EACX,aAAa,EACb,cAAc,EACd,YAAY,EACZ,WAAW,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,EACL,SAAS,EACT,gBAAgB,EAChB,aAAa,EACb,WAAW,EACX,WAAW,GACZ,MAAM,aAAa,CAAC;AAErB,cAAc;AACd,OAAO,EACL,KAAK,EACL,MAAM,EACN,OAAO,EACP,MAAM,EACN,eAAe,GAChB,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type utilities for extracting input/output types from trails.
|
|
3
|
+
*/
|
|
4
|
+
import type { AnyTrail, Trail } from './trail.js';
|
|
5
|
+
/** Extract the input type from a Trail. */
|
|
6
|
+
export type TrailInput<T extends AnyTrail> = T extends Trail<infer I, any> ? I : never;
|
|
7
|
+
/** Extract the output type from a Trail. */
|
|
8
|
+
export type TrailOutput<T extends AnyTrail> = T extends Trail<any, infer O> ? O : never;
|
|
9
|
+
/** Get the input Zod schema from a trail, preserving the specific schema type. */
|
|
10
|
+
export declare const inputOf: <T extends AnyTrail>(trail: T) => T["input"];
|
|
11
|
+
/** Get the output Zod schema from a trail, if defined, preserving the specific schema type. */
|
|
12
|
+
export declare const outputOf: <T extends AnyTrail>(trail: T) => T["output"];
|
|
13
|
+
//# sourceMappingURL=type-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-utils.d.ts","sourceRoot":"","sources":["../src/type-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAQlD,2CAA2C;AAC3C,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,QAAQ,IACvC,CAAC,SAAS,KAAK,CAAC,MAAM,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAE5C,4CAA4C;AAC5C,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,QAAQ,IACxC,CAAC,SAAS,KAAK,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAQ5C,kFAAkF;AAClF,eAAO,MAAM,OAAO,GAAI,CAAC,SAAS,QAAQ,EAAE,OAAO,CAAC,KAAG,CAAC,CAAC,OAAO,CACnD,CAAC;AAEd,+FAA+F;AAC/F,eAAO,MAAM,QAAQ,GAAI,CAAC,SAAS,QAAQ,EAAE,OAAO,CAAC,KAAG,CAAC,CAAC,QAAQ,CACpD,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type utilities for extracting input/output types from trails.
|
|
3
|
+
*/
|
|
4
|
+
/* oxlint-enable no-explicit-any */
|
|
5
|
+
// ---------------------------------------------------------------------------
|
|
6
|
+
// Runtime schema accessors
|
|
7
|
+
// ---------------------------------------------------------------------------
|
|
8
|
+
/** Get the input Zod schema from a trail, preserving the specific schema type. */
|
|
9
|
+
export const inputOf = (trail) => trail.input;
|
|
10
|
+
/** Get the output Zod schema from a trail, if defined, preserving the specific schema type. */
|
|
11
|
+
export const outputOf = (trail) => trail.output;
|
|
12
|
+
//# sourceMappingURL=type-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-utils.js","sourceRoot":"","sources":["../src/type-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAkBH,mCAAmC;AAEnC,8EAA8E;AAC9E,2BAA2B;AAC3B,8EAA8E;AAE9E,kFAAkF;AAClF,MAAM,CAAC,MAAM,OAAO,GAAG,CAAqB,KAAQ,EAAc,EAAE,CAClE,KAAK,CAAC,KAAK,CAAC;AAEd,+FAA+F;AAC/F,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAqB,KAAQ,EAAe,EAAE,CACpE,KAAK,CAAC,MAAM,CAAC"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test';
|
|
2
|
+
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
|
|
5
|
+
import { Result } from '../result';
|
|
6
|
+
import { trail } from '../trail';
|
|
7
|
+
import type { TrailInput, TrailOutput } from '../type-utils';
|
|
8
|
+
import { inputOf, outputOf } from '../type-utils';
|
|
9
|
+
|
|
10
|
+
const greetTrail = trail('greet', {
|
|
11
|
+
input: z.object({ name: z.string() }),
|
|
12
|
+
output: z.object({ message: z.string() }),
|
|
13
|
+
run: (input) => Result.ok({ message: `Hello, ${input.name}!` }),
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const noOutputTrail = trail('ping', {
|
|
17
|
+
input: z.object({}),
|
|
18
|
+
run: () => Result.ok(),
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe('type-utils', () => {
|
|
22
|
+
describe('inputOf', () => {
|
|
23
|
+
test('returns the Zod input schema and can parse valid input', () => {
|
|
24
|
+
const schema = inputOf(greetTrail);
|
|
25
|
+
const result = schema.safeParse({ name: 'Alice' });
|
|
26
|
+
expect(result.success).toBe(true);
|
|
27
|
+
expect(
|
|
28
|
+
(result as { success: true; data: { name: string } }).data
|
|
29
|
+
).toEqual({
|
|
30
|
+
name: 'Alice',
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('preserves specific schema type so .shape is accessible', () => {
|
|
35
|
+
const schema = inputOf(greetTrail);
|
|
36
|
+
// .shape is only available on z.ZodObject, not the broader z.ZodType
|
|
37
|
+
expect(schema.shape).toBeDefined();
|
|
38
|
+
expect(schema.shape.name).toBeDefined();
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
describe('outputOf', () => {
|
|
43
|
+
test('returns the Zod output schema when defined', () => {
|
|
44
|
+
const schema = outputOf(greetTrail);
|
|
45
|
+
expect(schema).toBeDefined();
|
|
46
|
+
// oxlint-disable-next-line no-non-null-assertion -- guarded by toBeDefined() above
|
|
47
|
+
const result = schema!.safeParse({ message: 'hello' });
|
|
48
|
+
expect(result.success).toBe(true);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test('returns undefined when no output schema', () => {
|
|
52
|
+
const schema = outputOf(noOutputTrail);
|
|
53
|
+
expect(schema).toBeUndefined();
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe('type-level checks', () => {
|
|
58
|
+
test('TrailInput matches expected shape', () => {
|
|
59
|
+
// If this compiles, the type is correct
|
|
60
|
+
const _input: TrailInput<typeof greetTrail> = { name: 'test' };
|
|
61
|
+
expect(_input.name).toBe('test');
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test('TrailOutput matches expected shape', () => {
|
|
65
|
+
// If this compiles, the type is correct
|
|
66
|
+
const _output: TrailOutput<typeof greetTrail> = { message: 'hello' };
|
|
67
|
+
expect(_output.message).toBe('hello');
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
});
|
package/src/index.ts
CHANGED
|
@@ -50,6 +50,10 @@ export type {
|
|
|
50
50
|
TrailExample,
|
|
51
51
|
} from './trail.js';
|
|
52
52
|
|
|
53
|
+
// Type utilities
|
|
54
|
+
export type { TrailInput, TrailOutput } from './type-utils.js';
|
|
55
|
+
export { inputOf, outputOf } from './type-utils.js';
|
|
56
|
+
|
|
53
57
|
// Event
|
|
54
58
|
export { event } from './event.js';
|
|
55
59
|
export type { AnyEvent, Event, EventSpec } from './event.js';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type utilities for extracting input/output types from trails.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { AnyTrail, Trail } from './trail.js';
|
|
6
|
+
|
|
7
|
+
// ---------------------------------------------------------------------------
|
|
8
|
+
// Utility types
|
|
9
|
+
// ---------------------------------------------------------------------------
|
|
10
|
+
|
|
11
|
+
/* oxlint-disable no-explicit-any -- `any` required for conditional type inference; `unknown` breaks inference */
|
|
12
|
+
|
|
13
|
+
/** Extract the input type from a Trail. */
|
|
14
|
+
export type TrailInput<T extends AnyTrail> =
|
|
15
|
+
T extends Trail<infer I, any> ? I : never;
|
|
16
|
+
|
|
17
|
+
/** Extract the output type from a Trail. */
|
|
18
|
+
export type TrailOutput<T extends AnyTrail> =
|
|
19
|
+
T extends Trail<any, infer O> ? O : never;
|
|
20
|
+
|
|
21
|
+
/* oxlint-enable no-explicit-any */
|
|
22
|
+
|
|
23
|
+
// ---------------------------------------------------------------------------
|
|
24
|
+
// Runtime schema accessors
|
|
25
|
+
// ---------------------------------------------------------------------------
|
|
26
|
+
|
|
27
|
+
/** Get the input Zod schema from a trail, preserving the specific schema type. */
|
|
28
|
+
export const inputOf = <T extends AnyTrail>(trail: T): T['input'] =>
|
|
29
|
+
trail.input;
|
|
30
|
+
|
|
31
|
+
/** Get the output Zod schema from a trail, if defined, preserving the specific schema type. */
|
|
32
|
+
export const outputOf = <T extends AnyTrail>(trail: T): T['output'] =>
|
|
33
|
+
trail.output;
|
package/tsconfig.tsbuildinfo
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["./src/adapters.ts","./src/blob-ref.ts","./src/branded.ts","./src/collections.ts","./src/context.ts","./src/derive.ts","./src/errors.ts","./src/event.ts","./src/fetch.ts","./src/guards.ts","./src/health.ts","./src/index.ts","./src/job.ts","./src/layer.ts","./src/path-security.ts","./src/resilience.ts","./src/result.ts","./src/serialization.ts","./src/topo.ts","./src/trail.ts","./src/types.ts","./src/validate-topo.ts","./src/validation.ts","./src/workspace.ts","./src/patterns/bulk.ts","./src/patterns/change.ts","./src/patterns/date-range.ts","./src/patterns/index.ts","./src/patterns/pagination.ts","./src/patterns/progress.ts","./src/patterns/sorting.ts","./src/patterns/status.ts","./src/patterns/timestamps.ts","./src/redaction/index.ts","./src/redaction/patterns.ts","./src/redaction/redactor.ts"],"version":"5.9.3"}
|
|
1
|
+
{"root":["./src/adapters.ts","./src/blob-ref.ts","./src/branded.ts","./src/collections.ts","./src/context.ts","./src/derive.ts","./src/errors.ts","./src/event.ts","./src/fetch.ts","./src/guards.ts","./src/health.ts","./src/index.ts","./src/job.ts","./src/layer.ts","./src/path-security.ts","./src/resilience.ts","./src/result.ts","./src/serialization.ts","./src/topo.ts","./src/trail.ts","./src/type-utils.ts","./src/types.ts","./src/validate-topo.ts","./src/validation.ts","./src/workspace.ts","./src/patterns/bulk.ts","./src/patterns/change.ts","./src/patterns/date-range.ts","./src/patterns/index.ts","./src/patterns/pagination.ts","./src/patterns/progress.ts","./src/patterns/sorting.ts","./src/patterns/status.ts","./src/patterns/timestamps.ts","./src/redaction/index.ts","./src/redaction/patterns.ts","./src/redaction/redactor.ts"],"version":"5.9.3"}
|