@ontrails/core 1.0.0-beta.0 → 1.0.0-beta.10

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 (84) hide show
  1. package/.turbo/turbo-lint.log +1 -1
  2. package/CHANGELOG.md +109 -0
  3. package/README.md +101 -131
  4. package/dist/derive.d.ts +1 -1
  5. package/dist/derive.d.ts.map +1 -1
  6. package/dist/derive.js +4 -1
  7. package/dist/derive.js.map +1 -1
  8. package/dist/dispatch.d.ts +27 -0
  9. package/dist/dispatch.d.ts.map +1 -0
  10. package/dist/dispatch.js +34 -0
  11. package/dist/dispatch.js.map +1 -0
  12. package/dist/event.d.ts +2 -2
  13. package/dist/event.d.ts.map +1 -1
  14. package/dist/event.js +1 -1
  15. package/dist/event.js.map +1 -1
  16. package/dist/execute.d.ts +30 -0
  17. package/dist/execute.d.ts.map +1 -0
  18. package/dist/execute.js +64 -0
  19. package/dist/execute.js.map +1 -0
  20. package/dist/index.d.ts +10 -6
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +7 -2
  23. package/dist/index.js.map +1 -1
  24. package/dist/patterns/status.d.ts +1 -1
  25. package/dist/result.d.ts +11 -11
  26. package/dist/result.d.ts.map +1 -1
  27. package/dist/result.js +15 -4
  28. package/dist/result.js.map +1 -1
  29. package/dist/serialization.d.ts.map +1 -1
  30. package/dist/serialization.js +45 -7
  31. package/dist/serialization.js.map +1 -1
  32. package/dist/topo.d.ts +4 -4
  33. package/dist/topo.d.ts.map +1 -1
  34. package/dist/topo.js +12 -16
  35. package/dist/topo.js.map +1 -1
  36. package/dist/trail.d.ts +16 -10
  37. package/dist/trail.d.ts.map +1 -1
  38. package/dist/trail.js +4 -2
  39. package/dist/trail.js.map +1 -1
  40. package/dist/type-utils.d.ts +24 -0
  41. package/dist/type-utils.d.ts.map +1 -0
  42. package/dist/type-utils.js +12 -0
  43. package/dist/type-utils.js.map +1 -0
  44. package/dist/types.d.ts +1 -2
  45. package/dist/types.d.ts.map +1 -1
  46. package/dist/validate-topo.d.ts +2 -2
  47. package/dist/validate-topo.d.ts.map +1 -1
  48. package/dist/validate-topo.js +59 -9
  49. package/dist/validate-topo.js.map +1 -1
  50. package/package.json +2 -2
  51. package/src/__tests__/context.test.ts +4 -5
  52. package/src/__tests__/derive.test.ts +44 -0
  53. package/src/__tests__/dispatch.test.ts +154 -0
  54. package/src/__tests__/event.test.ts +5 -5
  55. package/src/__tests__/execute.test.ts +208 -0
  56. package/src/__tests__/layer.test.ts +11 -111
  57. package/src/__tests__/serialization.test.ts +166 -1
  58. package/src/__tests__/topo.test.ts +101 -79
  59. package/src/__tests__/trail.test.ts +73 -35
  60. package/src/__tests__/type-utils.test.ts +90 -0
  61. package/src/__tests__/validate-topo.test.ts +97 -20
  62. package/src/derive.ts +12 -2
  63. package/src/dispatch.ts +54 -0
  64. package/src/event.ts +3 -3
  65. package/src/execute.ts +96 -0
  66. package/src/index.ts +22 -18
  67. package/src/result.ts +29 -15
  68. package/src/serialization.ts +56 -11
  69. package/src/topo.ts +18 -23
  70. package/src/trail.ts +24 -13
  71. package/src/type-utils.ts +45 -0
  72. package/src/types.ts +1 -3
  73. package/src/validate-topo.ts +70 -10
  74. package/tsconfig.tsbuildinfo +1 -1
  75. package/dist/hike.d.ts +0 -36
  76. package/dist/hike.d.ts.map +0 -1
  77. package/dist/hike.js +0 -20
  78. package/dist/hike.js.map +0 -1
  79. package/src/__tests__/hike.test.ts +0 -117
  80. package/src/__tests__/job.test.ts +0 -98
  81. package/src/adapters.ts +0 -68
  82. package/src/health.ts +0 -23
  83. package/src/hike.ts +0 -77
  84. package/src/job.ts +0 -20
package/src/adapters.ts DELETED
@@ -1,68 +0,0 @@
1
- import type { Result } from './result.js';
2
-
3
- // ---------------------------------------------------------------------------
4
- // Shared option types
5
- // ---------------------------------------------------------------------------
6
-
7
- /** Options for search queries */
8
- export interface SearchOptions {
9
- readonly limit?: number | undefined;
10
- readonly offset?: number | undefined;
11
- readonly filters?: Readonly<Record<string, unknown>> | undefined;
12
- }
13
-
14
- /** A single search hit */
15
- export interface SearchResult {
16
- readonly id: string;
17
- readonly score: number;
18
- readonly document: Readonly<Record<string, unknown>>;
19
- }
20
-
21
- /** Options for storage writes */
22
- export interface StorageOptions {
23
- /** Time-to-live in milliseconds */
24
- readonly ttl?: number | undefined;
25
- }
26
-
27
- // ---------------------------------------------------------------------------
28
- // Adapter port interfaces
29
- // ---------------------------------------------------------------------------
30
-
31
- /** Full-text / vector index adapter */
32
- export interface IndexAdapter {
33
- index(
34
- id: string,
35
- document: Readonly<Record<string, unknown>>
36
- ): Promise<Result<void, Error>>;
37
-
38
- search(
39
- query: string,
40
- options?: SearchOptions
41
- ): Promise<Result<readonly SearchResult[], Error>>;
42
-
43
- remove(id: string): Promise<Result<void, Error>>;
44
- }
45
-
46
- /** Key-value storage adapter */
47
- export interface StorageAdapter {
48
- get(key: string): Promise<Result<unknown, Error>>;
49
- set(
50
- key: string,
51
- value: unknown,
52
- options?: StorageOptions
53
- ): Promise<Result<void, Error>>;
54
- delete(key: string): Promise<Result<void, Error>>;
55
- has(key: string): Promise<Result<boolean, Error>>;
56
- }
57
-
58
- /** Cache adapter with typed get/set and bulk clear */
59
- export interface CacheAdapter {
60
- get<T>(key: string): Promise<Result<T | undefined, Error>>;
61
- set<T>(
62
- key: string,
63
- value: T,
64
- options?: StorageOptions
65
- ): Promise<Result<void, Error>>;
66
- delete(key: string): Promise<Result<void, Error>>;
67
- clear(): Promise<Result<void, Error>>;
68
- }
package/src/health.ts DELETED
@@ -1,23 +0,0 @@
1
- // ---------------------------------------------------------------------------
2
- // Health check types
3
- // ---------------------------------------------------------------------------
4
-
5
- /** Aggregate health status */
6
- export type HealthStatus = 'healthy' | 'degraded' | 'unhealthy';
7
-
8
- /** Individual component check result */
9
- export interface HealthCheck {
10
- readonly status: HealthStatus;
11
- readonly message?: string | undefined;
12
- /** Latency in milliseconds */
13
- readonly latency?: number | undefined;
14
- }
15
-
16
- /** Full health report returned by a health endpoint */
17
- export interface HealthResult {
18
- readonly status: HealthStatus;
19
- readonly checks: Readonly<Record<string, HealthCheck>>;
20
- readonly version?: string | undefined;
21
- /** Uptime in seconds */
22
- readonly uptime?: number | undefined;
23
- }
package/src/hike.ts DELETED
@@ -1,77 +0,0 @@
1
- /**
2
- * Hike — a composition that follows trails.
3
- */
4
-
5
- import type { Trail, TrailSpec } from './trail.js';
6
- import type { TrailContext } from './types.js';
7
-
8
- // ---------------------------------------------------------------------------
9
- // Spec (input to the factory)
10
- // ---------------------------------------------------------------------------
11
-
12
- export interface HikeSpec<I, O> extends TrailSpec<I, O> {
13
- readonly follows: readonly string[];
14
- }
15
-
16
- // ---------------------------------------------------------------------------
17
- // Shape (output of the factory)
18
- // ---------------------------------------------------------------------------
19
-
20
- export interface Hike<I, O> extends Omit<Trail<I, O>, 'kind'> {
21
- readonly kind: 'hike';
22
- readonly follows: readonly string[];
23
- }
24
-
25
- // ---------------------------------------------------------------------------
26
- // Factory
27
- // ---------------------------------------------------------------------------
28
-
29
- /**
30
- * Create a hike definition.
31
- *
32
- * A hike is a composition that declares which trails it follows.
33
- * Returns a frozen object with `kind: "hike"` and all spec fields.
34
- *
35
- * @example
36
- * ```typescript
37
- * // ID as first argument
38
- * const onboard = hike("entity.onboard", {
39
- * follows: ["entity.add", "entity.relate"],
40
- * input: z.object({ name: z.string() }),
41
- * implementation: (input, ctx) => Result.ok(...),
42
- * });
43
- *
44
- * // Full spec object (programmatic)
45
- * const onboard = hike({ id: "entity.onboard", follows: [...], ... });
46
- * ```
47
- */
48
- export function hike<I, O>(id: string, spec: HikeSpec<I, O>): Hike<I, O>;
49
- export function hike<I, O>(
50
- spec: HikeSpec<I, O> & { readonly id: string }
51
- ): Hike<I, O>;
52
- export function hike<I, O>(
53
- idOrSpec: string | (HikeSpec<I, O> & { readonly id: string }),
54
- maybeSpec?: HikeSpec<I, O>
55
- ): Hike<I, O> {
56
- const resolved =
57
- typeof idOrSpec === 'string'
58
- ? { id: idOrSpec, spec: maybeSpec }
59
- : { id: idOrSpec.id, spec: idOrSpec };
60
-
61
- if (!resolved.spec) {
62
- throw new TypeError('hike() requires a spec when an id is provided');
63
- }
64
-
65
- const { follows, implementation, ...rest } = resolved.spec;
66
- return Object.freeze({
67
- ...rest,
68
- follows: Object.freeze([...follows]),
69
- id: resolved.id,
70
- implementation: async (input: I, ctx: TrailContext) =>
71
- await implementation(input, ctx),
72
- kind: 'hike' as const,
73
- });
74
- }
75
-
76
- // oxlint-disable-next-line no-explicit-any -- existential type; see AnyTrail
77
- export type AnyHike = Hike<any, any>;
package/src/job.ts DELETED
@@ -1,20 +0,0 @@
1
- import { z } from 'zod';
2
-
3
- import { progressFields } from './patterns/progress.js';
4
- import { statusFields } from './patterns/status.js';
5
-
6
- /**
7
- * Proof: job-style output schema composes from existing pattern helpers.
8
- * No dedicated `kind: "job"` needed — regular trails with status+progress output work.
9
- */
10
- export const jobOutputSchema = z.object({
11
- ...progressFields().shape,
12
- ...statusFields().shape,
13
- completedAt: z.string().optional(),
14
- error: z.string().optional(),
15
- jobId: z.string(),
16
- result: z.unknown().optional(),
17
- startedAt: z.string().optional(),
18
- });
19
-
20
- export type JobOutput = z.infer<typeof jobOutputSchema>;