@ontrails/core 1.0.0-beta.15 → 1.0.0-beta.16
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 +63 -0
- package/README.md +61 -16
- package/package.json +9 -8
- 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/context.ts +4 -0
- package/src/{internal/cross-batch.ts → cross-batch.ts} +3 -11
- package/src/detours.ts +8 -0
- package/src/draft.ts +4 -0
- package/src/error-projection.ts +51 -0
- package/src/errors.ts +192 -39
- package/src/execute.ts +443 -44
- package/src/fire.ts +965 -91
- package/src/index.ts +285 -38
- package/src/layer-projection.ts +192 -0
- package/src/layer.ts +32 -1
- package/src/observe.ts +361 -0
- package/src/permits.ts +12 -0
- package/src/redaction/patterns.ts +6 -3
- package/src/resilience.ts +8 -8
- package/src/resource-config.ts +477 -44
- package/src/resource.ts +21 -1
- package/src/result.ts +18 -0
- package/src/run.ts +2 -2
- package/src/schedule-runtime.ts +689 -0
- package/src/schedule.ts +324 -0
- package/src/serialization.ts +90 -57
- package/src/signal-diagnostics.ts +633 -0
- package/src/{internal/signal-ref.ts → signal-ref.ts} +1 -1
- package/src/signal.ts +37 -0
- package/src/store/accessor-protocol.ts +5 -5
- package/src/structured-examples.ts +245 -0
- package/src/surface-derivation.ts +91 -0
- package/src/surface-filter.ts +7 -13
- package/src/topo.ts +386 -6
- package/src/tracing.ts +345 -0
- package/src/trail.ts +168 -22
- package/src/trails/derive-trail.ts +1 -1
- package/src/trails/ingest.ts +7 -15
- package/src/{internal/trails-db.ts → trails-db.ts} +42 -21
- package/src/transport-error-map.ts +146 -28
- package/src/types.ts +82 -28
- package/src/validate-established-topo.ts +6 -0
- package/src/validate-topo.ts +212 -5
- package/src/validation.ts +58 -1
- package/src/webhook.ts +276 -0
- package/src/{internal/zod-wrappers.ts → zod-wrappers.ts} +0 -6
- package/.turbo/turbo-build.log +0 -1
- package/.turbo/turbo-lint.log +0 -3
- package/.turbo/turbo-typecheck.log +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 -22
- package/dist/context.d.ts.map +0 -1
- package/dist/context.js +0 -37
- package/dist/context.js.map +0 -1
- package/dist/contour.d.ts +0 -81
- package/dist/contour.d.ts.map +0 -1
- package/dist/contour.js +0 -176
- package/dist/contour.js.map +0 -1
- package/dist/cross-schema.d.ts +0 -18
- package/dist/cross-schema.d.ts.map +0 -1
- package/dist/cross-schema.js +0 -29
- package/dist/cross-schema.js.map +0 -1
- package/dist/derive.d.ts +0 -44
- package/dist/derive.d.ts.map +0 -1
- package/dist/derive.js +0 -149
- package/dist/derive.js.map +0 -1
- package/dist/draft.d.ts +0 -28
- package/dist/draft.d.ts.map +0 -1
- package/dist/draft.js +0 -157
- package/dist/draft.js.map +0 -1
- package/dist/errors.d.ts +0 -141
- package/dist/errors.d.ts.map +0 -1
- package/dist/errors.js +0 -185
- package/dist/errors.js.map +0 -1
- package/dist/execute.d.ts +0 -52
- package/dist/execute.d.ts.map +0 -1
- package/dist/execute.js +0 -511
- package/dist/execute.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/fire.d.ts +0 -43
- package/dist/fire.d.ts.map +0 -1
- package/dist/fire.js +0 -185
- package/dist/fire.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/index.d.ts +0 -59
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -61
- package/dist/index.js.map +0 -1
- package/dist/internal/cross-batch.d.ts +0 -44
- package/dist/internal/cross-batch.d.ts.map +0 -1
- package/dist/internal/cross-batch.js +0 -58
- package/dist/internal/cross-batch.js.map +0 -1
- package/dist/internal/fork-ctx.d.ts +0 -41
- package/dist/internal/fork-ctx.d.ts.map +0 -1
- package/dist/internal/fork-ctx.js +0 -47
- package/dist/internal/fork-ctx.js.map +0 -1
- package/dist/internal/signal-ref.d.ts +0 -15
- package/dist/internal/signal-ref.d.ts.map +0 -1
- package/dist/internal/signal-ref.js +0 -41
- package/dist/internal/signal-ref.js.map +0 -1
- package/dist/internal/topo-saves.d.ts +0 -53
- package/dist/internal/topo-saves.d.ts.map +0 -1
- package/dist/internal/topo-saves.js +0 -449
- package/dist/internal/topo-saves.js.map +0 -1
- package/dist/internal/topo-snapshots.d.ts +0 -57
- package/dist/internal/topo-snapshots.d.ts.map +0 -1
- package/dist/internal/topo-snapshots.js +0 -372
- package/dist/internal/topo-snapshots.js.map +0 -1
- package/dist/internal/topo-store-read.d.ts +0 -70
- package/dist/internal/topo-store-read.d.ts.map +0 -1
- package/dist/internal/topo-store-read.js +0 -221
- package/dist/internal/topo-store-read.js.map +0 -1
- package/dist/internal/topo-store.d.ts +0 -26
- package/dist/internal/topo-store.d.ts.map +0 -1
- package/dist/internal/topo-store.js +0 -621
- package/dist/internal/topo-store.js.map +0 -1
- package/dist/internal/tracing.d.ts +0 -98
- package/dist/internal/tracing.d.ts.map +0 -1
- package/dist/internal/tracing.js +0 -102
- package/dist/internal/tracing.js.map +0 -1
- package/dist/internal/trails-db.d.ts +0 -16
- package/dist/internal/trails-db.d.ts.map +0 -1
- package/dist/internal/trails-db.js +0 -118
- package/dist/internal/trails-db.js.map +0 -1
- package/dist/internal/zod-wrappers.d.ts +0 -40
- package/dist/internal/zod-wrappers.d.ts.map +0 -1
- package/dist/internal/zod-wrappers.js +0 -59
- package/dist/internal/zod-wrappers.js.map +0 -1
- package/dist/layer.d.ts +0 -23
- 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/resource-config.d.ts +0 -22
- package/dist/resource-config.d.ts.map +0 -1
- package/dist/resource-config.js +0 -210
- package/dist/resource-config.js.map +0 -1
- package/dist/resource.d.ts +0 -74
- package/dist/resource.d.ts.map +0 -1
- package/dist/resource.js +0 -61
- package/dist/resource.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/run.d.ts +0 -28
- package/dist/run.d.ts.map +0 -1
- package/dist/run.js +0 -35
- package/dist/run.js.map +0 -1
- package/dist/serialization.d.ts +0 -27
- package/dist/serialization.d.ts.map +0 -1
- package/dist/serialization.js +0 -154
- package/dist/serialization.js.map +0 -1
- package/dist/signal.d.ts +0 -33
- package/dist/signal.d.ts.map +0 -1
- package/dist/signal.js +0 -17
- package/dist/signal.js.map +0 -1
- package/dist/store/accessor-protocol.d.ts +0 -51
- package/dist/store/accessor-protocol.d.ts.map +0 -1
- package/dist/store/accessor-protocol.js +0 -2
- package/dist/store/accessor-protocol.js.map +0 -1
- package/dist/store/index.d.ts +0 -2
- package/dist/store/index.d.ts.map +0 -1
- package/dist/store/index.js +0 -2
- package/dist/store/index.js.map +0 -1
- package/dist/surface-filter.d.ts +0 -13
- package/dist/surface-filter.d.ts.map +0 -1
- package/dist/surface-filter.js +0 -76
- package/dist/surface-filter.js.map +0 -1
- package/dist/topo-store.d.ts +0 -62
- package/dist/topo-store.d.ts.map +0 -1
- package/dist/topo-store.js +0 -319
- package/dist/topo-store.js.map +0 -1
- package/dist/topo.d.ts +0 -39
- package/dist/topo.d.ts.map +0 -1
- package/dist/topo.js +0 -241
- package/dist/topo.js.map +0 -1
- package/dist/trail.d.ts +0 -163
- package/dist/trail.d.ts.map +0 -1
- package/dist/trail.js +0 -75
- package/dist/trail.js.map +0 -1
- package/dist/trails/derive-trail.d.ts +0 -66
- package/dist/trails/derive-trail.d.ts.map +0 -1
- package/dist/trails/derive-trail.js +0 -378
- package/dist/trails/derive-trail.js.map +0 -1
- package/dist/trails/index.d.ts +0 -5
- package/dist/trails/index.d.ts.map +0 -1
- package/dist/trails/index.js +0 -3
- package/dist/trails/index.js.map +0 -1
- package/dist/trails/ingest.d.ts +0 -24
- package/dist/trails/ingest.d.ts.map +0 -1
- package/dist/trails/ingest.js +0 -63
- package/dist/trails/ingest.js.map +0 -1
- package/dist/transport-error-map.d.ts +0 -106
- package/dist/transport-error-map.d.ts.map +0 -1
- package/dist/transport-error-map.js +0 -24
- package/dist/transport-error-map.js.map +0 -1
- package/dist/type-checks.test-d.d.ts +0 -71
- package/dist/type-checks.test-d.d.ts.map +0 -1
- package/dist/type-checks.test-d.js +0 -12
- package/dist/type-checks.test-d.js.map +0 -1
- package/dist/type-utils.d.ts +0 -33
- package/dist/type-utils.d.ts.map +0 -1
- package/dist/type-utils.js +0 -12
- package/dist/type-utils.js.map +0 -1
- package/dist/types.d.ts +0 -177
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -3
- package/dist/types.js.map +0 -1
- package/dist/validate-established-topo.d.ts +0 -76
- package/dist/validate-established-topo.d.ts.map +0 -1
- package/dist/validate-established-topo.js +0 -43
- package/dist/validate-established-topo.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 -193
- 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 -165
- 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 -77
- package/src/__tests__/contour.test.ts +0 -263
- package/src/__tests__/derive-trail.test.ts +0 -668
- package/src/__tests__/derive.test.ts +0 -260
- package/src/__tests__/errors.test.ts +0 -427
- package/src/__tests__/execute.test.ts +0 -1563
- package/src/__tests__/fetch.test.ts +0 -217
- package/src/__tests__/fire.test.ts +0 -1056
- package/src/__tests__/fork-ctx.test.ts +0 -83
- package/src/__tests__/guards.test.ts +0 -102
- package/src/__tests__/ingest.test.ts +0 -191
- package/src/__tests__/layer.test.ts +0 -125
- 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__/resource.test.ts +0 -204
- package/src/__tests__/result.test.ts +0 -155
- package/src/__tests__/run.test.ts +0 -181
- package/src/__tests__/serialization.test.ts +0 -401
- package/src/__tests__/service-config.test.ts +0 -224
- package/src/__tests__/signal.test.ts +0 -82
- package/src/__tests__/surface-filter.test.ts +0 -196
- package/src/__tests__/topo-store-read.test.ts +0 -256
- package/src/__tests__/topo-store.test.ts +0 -869
- package/src/__tests__/topo.test.ts +0 -573
- package/src/__tests__/trail-permit.test.ts +0 -60
- package/src/__tests__/trail.test.ts +0 -426
- package/src/__tests__/trails-db.test.ts +0 -198
- package/src/__tests__/transport-error-map.test.ts +0 -82
- package/src/__tests__/type-utils.test.ts +0 -118
- package/src/__tests__/validate-topo.test.ts +0 -611
- package/src/__tests__/validation.test.ts +0 -336
- package/src/__tests__/workspace.test.ts +0 -183
- package/src/__tests__/zod-wrappers.test.ts +0 -62
- package/src/internal/topo-snapshots.ts +0 -517
- package/src/internal/topo-store-read.ts +0 -481
- package/src/internal/topo-store.ts +0 -1192
- package/src/internal/tracing.ts +0 -187
- package/src/topo-store.ts +0 -510
- package/src/type-checks.test-d.ts +0 -106
- package/tsconfig.json +0 -9
- package/tsconfig.tests.json +0 -10
- package/tsconfig.tsbuildinfo +0 -1
package/dist/blob-ref.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* BlobRef — a frozen reference to binary data for @ontrails/core.
|
|
3
|
-
*/
|
|
4
|
-
/** Creates a frozen BlobRef. */
|
|
5
|
-
export const createBlobRef = (options) => Object.freeze({
|
|
6
|
-
data: options.data,
|
|
7
|
-
mimeType: options.mimeType,
|
|
8
|
-
name: options.name,
|
|
9
|
-
size: options.size,
|
|
10
|
-
});
|
|
11
|
-
/** Type guard for BlobRef-shaped values. */
|
|
12
|
-
export const isBlobRef = (value) => {
|
|
13
|
-
if (typeof value !== 'object' || value === null) {
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
const obj = value;
|
|
17
|
-
return (typeof obj['name'] === 'string' &&
|
|
18
|
-
typeof obj['mimeType'] === 'string' &&
|
|
19
|
-
typeof obj['size'] === 'number' &&
|
|
20
|
-
(obj['data'] instanceof Uint8Array || obj['data'] instanceof ReadableStream));
|
|
21
|
-
};
|
|
22
|
-
//# sourceMappingURL=blob-ref.js.map
|
package/dist/blob-ref.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"blob-ref.js","sourceRoot":"","sources":["../src/blob-ref.ts"],"names":[],"mappings":"AAAA;;GAEG;AAUH,gCAAgC;AAChC,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,OAK7B,EAAW,EAAE,CACZ,MAAM,CAAC,MAAM,CAAC;IACZ,IAAI,EAAE,OAAO,CAAC,IAAI;IAClB,QAAQ,EAAE,OAAO,CAAC,QAAQ;IAC1B,IAAI,EAAE,OAAO,CAAC,IAAI;IAClB,IAAI,EAAE,OAAO,CAAC,IAAI;CACnB,CAAC,CAAC;AAEL,4CAA4C;AAC5C,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,KAAc,EAAoB,EAAE;IAC5D,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QAChD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,GAAG,GAAG,KAAgC,CAAC;IAC7C,OAAO,CACL,OAAO,GAAG,CAAC,MAAM,CAAC,KAAK,QAAQ;QAC/B,OAAO,GAAG,CAAC,UAAU,CAAC,KAAK,QAAQ;QACnC,OAAO,GAAG,CAAC,MAAM,CAAC,KAAK,QAAQ;QAC/B,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,UAAU,IAAI,GAAG,CAAC,MAAM,CAAC,YAAY,cAAc,CAAC,CAC7E,CAAC;AACJ,CAAC,CAAC"}
|
package/dist/branded.d.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Branded types and validated constructors for @ontrails/core.
|
|
3
|
-
*
|
|
4
|
-
* Branded types enforce domain constraints at the type level while remaining
|
|
5
|
-
* plain primitives at runtime. Factory functions return Result so callers
|
|
6
|
-
* handle validation failures explicitly.
|
|
7
|
-
*/
|
|
8
|
-
import { ValidationError } from './errors.js';
|
|
9
|
-
import type { Result } from './result.js';
|
|
10
|
-
/** Attach a phantom tag to a base type. */
|
|
11
|
-
export type Branded<T, Tag extends string> = T & {
|
|
12
|
-
readonly __brand: Tag;
|
|
13
|
-
};
|
|
14
|
-
/** Brand a value. No validation — use factory functions for safe construction. */
|
|
15
|
-
export declare const brand: <T, Tag extends string>(_tag: Tag, value: T) => Branded<T, Tag>;
|
|
16
|
-
/** Strip the brand and recover the underlying value. */
|
|
17
|
-
export declare const unbrand: <T>(value: Branded<T, string>) => T;
|
|
18
|
-
export type UUID = Branded<string, 'UUID'>;
|
|
19
|
-
export type Email = Branded<string, 'Email'>;
|
|
20
|
-
export type NonEmptyString = Branded<string, 'NonEmptyString'>;
|
|
21
|
-
export type PositiveInt = Branded<number, 'PositiveInt'>;
|
|
22
|
-
export declare const uuid: (value: string) => Result<UUID, ValidationError>;
|
|
23
|
-
export declare const email: (value: string) => Result<Email, ValidationError>;
|
|
24
|
-
export declare const nonEmptyString: (value: string) => Result<NonEmptyString, ValidationError>;
|
|
25
|
-
export declare const positiveInt: (value: number) => Result<PositiveInt, ValidationError>;
|
|
26
|
-
/**
|
|
27
|
-
* Generate a random alphanumeric ID.
|
|
28
|
-
* Runtime-agnostic: uses `crypto.getRandomValues`.
|
|
29
|
-
*/
|
|
30
|
-
export declare const shortId: (length?: number) => string;
|
|
31
|
-
/**
|
|
32
|
-
* Produce a deterministic hex hash from an input string.
|
|
33
|
-
* Uses a simple FNV-1a 32-bit hash — good enough for non-cryptographic IDs.
|
|
34
|
-
*/
|
|
35
|
-
export declare const deriveIdHash: (input: string) => string;
|
|
36
|
-
//# sourceMappingURL=branded.d.ts.map
|
package/dist/branded.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"branded.d.ts","sourceRoot":"","sources":["../src/branded.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAO1C,2CAA2C;AAC3C,MAAM,MAAM,OAAO,CAAC,CAAC,EAAE,GAAG,SAAS,MAAM,IAAI,CAAC,GAAG;IAAE,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAA;CAAE,CAAC;AAE3E,kFAAkF;AAClF,eAAO,MAAM,KAAK,GAAI,CAAC,EAAE,GAAG,SAAS,MAAM,EACzC,MAAM,GAAG,EACT,OAAO,CAAC,KACP,OAAO,CAAC,CAAC,EAAE,GAAG,CAA6B,CAAC;AAE/C,wDAAwD;AACxD,eAAO,MAAM,OAAO,GAAI,CAAC,EAAE,OAAO,OAAO,CAAC,CAAC,EAAE,MAAM,CAAC,KAAG,CAAe,CAAC;AAMvE,MAAM,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAC3C,MAAM,MAAM,KAAK,GAAG,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAC7C,MAAM,MAAM,cAAc,GAAG,OAAO,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;AAC/D,MAAM,MAAM,WAAW,GAAG,OAAO,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;AAezD,eAAO,MAAM,IAAI,GAAI,OAAO,MAAM,KAAG,MAAM,CAAC,IAAI,EAAE,eAAe,CAShE,CAAC;AAEF,eAAO,MAAM,KAAK,GAAI,OAAO,MAAM,KAAG,MAAM,CAAC,KAAK,EAAE,eAAe,CASlE,CAAC;AAEF,eAAO,MAAM,cAAc,GACzB,OAAO,MAAM,KACZ,MAAM,CAAC,cAAc,EAAE,eAAe,CAKxC,CAAC;AAEF,eAAO,MAAM,WAAW,GACtB,OAAO,MAAM,KACZ,MAAM,CAAC,WAAW,EAAE,eAAe,CASrC,CAAC;AASF;;;GAGG;AACH,eAAO,MAAM,OAAO,GAAI,eAAU,KAAG,MAWpC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,YAAY,GAAI,OAAO,MAAM,KAAG,MAY5C,CAAC"}
|
package/dist/branded.js
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Branded types and validated constructors for @ontrails/core.
|
|
3
|
-
*
|
|
4
|
-
* Branded types enforce domain constraints at the type level while remaining
|
|
5
|
-
* plain primitives at runtime. Factory functions return Result so callers
|
|
6
|
-
* handle validation failures explicitly.
|
|
7
|
-
*/
|
|
8
|
-
import { ValidationError } from './errors.js';
|
|
9
|
-
import { Result as R } from './result.js';
|
|
10
|
-
/** Brand a value. No validation — use factory functions for safe construction. */
|
|
11
|
-
export const brand = (_tag, value) => value;
|
|
12
|
-
/** Strip the brand and recover the underlying value. */
|
|
13
|
-
export const unbrand = (value) => value;
|
|
14
|
-
// ---------------------------------------------------------------------------
|
|
15
|
-
// Validation patterns
|
|
16
|
-
// ---------------------------------------------------------------------------
|
|
17
|
-
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-7][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
18
|
-
const EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
19
|
-
// ---------------------------------------------------------------------------
|
|
20
|
-
// Factory functions — each returns Result<BrandedType, ValidationError>
|
|
21
|
-
// ---------------------------------------------------------------------------
|
|
22
|
-
export const uuid = (value) => {
|
|
23
|
-
if (!UUID_RE.test(value)) {
|
|
24
|
-
return R.err(new ValidationError(`Invalid UUID: "${value}"`, {
|
|
25
|
-
context: { value },
|
|
26
|
-
}));
|
|
27
|
-
}
|
|
28
|
-
return R.ok(value);
|
|
29
|
-
};
|
|
30
|
-
export const email = (value) => {
|
|
31
|
-
if (!EMAIL_RE.test(value)) {
|
|
32
|
-
return R.err(new ValidationError(`Invalid email: "${value}"`, {
|
|
33
|
-
context: { value },
|
|
34
|
-
}));
|
|
35
|
-
}
|
|
36
|
-
return R.ok(value);
|
|
37
|
-
};
|
|
38
|
-
export const nonEmptyString = (value) => {
|
|
39
|
-
if (value.length === 0) {
|
|
40
|
-
return R.err(new ValidationError('String must not be empty'));
|
|
41
|
-
}
|
|
42
|
-
return R.ok(value);
|
|
43
|
-
};
|
|
44
|
-
export const positiveInt = (value) => {
|
|
45
|
-
if (!Number.isInteger(value) || value <= 0) {
|
|
46
|
-
return R.err(new ValidationError(`Expected positive integer, got ${value}`, {
|
|
47
|
-
context: { value },
|
|
48
|
-
}));
|
|
49
|
-
}
|
|
50
|
-
return R.ok(value);
|
|
51
|
-
};
|
|
52
|
-
// ---------------------------------------------------------------------------
|
|
53
|
-
// ID utilities
|
|
54
|
-
// ---------------------------------------------------------------------------
|
|
55
|
-
const ALPHANUMERIC = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
56
|
-
/**
|
|
57
|
-
* Generate a random alphanumeric ID.
|
|
58
|
-
* Runtime-agnostic: uses `crypto.getRandomValues`.
|
|
59
|
-
*/
|
|
60
|
-
export const shortId = (length = 8) => {
|
|
61
|
-
const bytes = new Uint8Array(length);
|
|
62
|
-
crypto.getRandomValues(bytes);
|
|
63
|
-
let id = '';
|
|
64
|
-
for (let i = 0; i < length; i += 1) {
|
|
65
|
-
const byte = bytes[i];
|
|
66
|
-
if (byte !== undefined) {
|
|
67
|
-
id += ALPHANUMERIC[byte % ALPHANUMERIC.length];
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return id;
|
|
71
|
-
};
|
|
72
|
-
/**
|
|
73
|
-
* Produce a deterministic hex hash from an input string.
|
|
74
|
-
* Uses a simple FNV-1a 32-bit hash — good enough for non-cryptographic IDs.
|
|
75
|
-
*/
|
|
76
|
-
export const deriveIdHash = (input) => {
|
|
77
|
-
// FNV offset basis
|
|
78
|
-
let hash = 2_166_136_261;
|
|
79
|
-
for (let i = 0; i < input.length; i += 1) {
|
|
80
|
-
// oxlint-disable-next-line no-bitwise -- FNV-1a hash requires XOR
|
|
81
|
-
hash ^= input.codePointAt(i) ?? 0;
|
|
82
|
-
// FNV prime
|
|
83
|
-
hash = Math.imul(hash, 0x01_00_01_93);
|
|
84
|
-
}
|
|
85
|
-
// Convert to unsigned 32-bit then hex
|
|
86
|
-
// oxlint-disable-next-line no-bitwise, prefer-math-trunc -- unsigned right shift needed for u32 conversion (Math.trunc differs semantically)
|
|
87
|
-
return (hash >>> 0).toString(16).padStart(8, '0');
|
|
88
|
-
};
|
|
89
|
-
//# sourceMappingURL=branded.js.map
|
package/dist/branded.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"branded.js","sourceRoot":"","sources":["../src/branded.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,EAAE,MAAM,IAAI,CAAC,EAAE,MAAM,aAAa,CAAC;AAS1C,kFAAkF;AAClF,MAAM,CAAC,MAAM,KAAK,GAAG,CACnB,IAAS,EACT,KAAQ,EACS,EAAE,CAAC,KAAwB,CAAC;AAE/C,wDAAwD;AACxD,MAAM,CAAC,MAAM,OAAO,GAAG,CAAI,KAAyB,EAAK,EAAE,CAAC,KAAU,CAAC;AAWvE,8EAA8E;AAC9E,sBAAsB;AACtB,8EAA8E;AAE9E,MAAM,OAAO,GACX,4EAA4E,CAAC;AAE/E,MAAM,QAAQ,GAAG,4BAA4B,CAAC;AAE9C,8EAA8E;AAC9E,wEAAwE;AACxE,8EAA8E;AAE9E,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,KAAa,EAAiC,EAAE;IACnE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,CAAC,CAAC,GAAG,CACV,IAAI,eAAe,CAAC,kBAAkB,KAAK,GAAG,EAAE;YAC9C,OAAO,EAAE,EAAE,KAAK,EAAE;SACnB,CAAC,CACH,CAAC;IACJ,CAAC;IACD,OAAO,CAAC,CAAC,EAAE,CAAC,KAAa,CAAC,CAAC;AAC7B,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,KAAa,EAAkC,EAAE;IACrE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1B,OAAO,CAAC,CAAC,GAAG,CACV,IAAI,eAAe,CAAC,mBAAmB,KAAK,GAA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,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACtB,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACvB,EAAE,IAAI,YAAY,CAAC,IAAI,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;QACjD,CAAC;IACH,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAAa,EAAU,EAAE;IACpD,mBAAmB;IACnB,IAAI,IAAI,GAAG,aAAa,CAAC;IACzB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QACzC,kEAAkE;QAClE,IAAI,IAAI,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QAClC,YAAY;QACZ,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;IACxC,CAAC;IACD,sCAAsC;IACtC,6IAA6I;IAC7I,OAAO,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;AACpD,CAAC,CAAC"}
|
package/dist/collections.d.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Collection utilities and type helpers for @ontrails/core.
|
|
3
|
-
*/
|
|
4
|
-
/** Recursively make every property optional. */
|
|
5
|
-
export type DeepPartial<T> = {
|
|
6
|
-
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
|
|
7
|
-
};
|
|
8
|
-
/** Flatten an intersection into a single object type for better IDE display. */
|
|
9
|
-
export type Prettify<T> = {
|
|
10
|
-
[K in keyof T]: T[K];
|
|
11
|
-
} & {};
|
|
12
|
-
/** Require at least one property from T. */
|
|
13
|
-
export type AtLeastOne<T> = {
|
|
14
|
-
[K in keyof T]-?: Pick<T, K> & Partial<Omit<T, K>>;
|
|
15
|
-
}[keyof T];
|
|
16
|
-
/** A tuple with at least one element. */
|
|
17
|
-
export type NonEmptyArray<T> = [T, ...T[]];
|
|
18
|
-
/** Narrows a readonly array to a NonEmptyArray. */
|
|
19
|
-
export declare const isNonEmptyArray: <T>(array: readonly T[]) => array is NonEmptyArray<T>;
|
|
20
|
-
/** Split an array into chunks of at most `size` elements. */
|
|
21
|
-
export declare const chunk: <T>(array: readonly T[], size: number) => T[][];
|
|
22
|
-
/**
|
|
23
|
-
* Remove duplicate items. When `key` is provided, uniqueness is determined
|
|
24
|
-
* by the return value of the key function; otherwise strict equality is used.
|
|
25
|
-
*/
|
|
26
|
-
export declare const dedupe: <T>(array: readonly T[], key?: (item: T) => unknown) => T[];
|
|
27
|
-
/** Group items by a string key. */
|
|
28
|
-
export declare const groupBy: <T>(array: readonly T[], key: (item: T) => string) => Record<string, T[]>;
|
|
29
|
-
/** Return a new sorted array based on a key function (ascending). */
|
|
30
|
-
export declare const sortBy: <T>(array: readonly T[], key: (item: T) => string | number) => T[];
|
|
31
|
-
//# sourceMappingURL=collections.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"collections.d.ts","sourceRoot":"","sources":["../src/collections.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,gDAAgD;AAChD,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;KAC1B,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAChE,CAAC;AAEF,gFAAgF;AAEhF,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,GAAG,EAAE,CAAC;AAExD,4CAA4C;AAC5C,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI;KACzB,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;CACnD,CAAC,MAAM,CAAC,CAAC,CAAC;AAEX,yCAAyC;AACzC,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;AAM3C,mDAAmD;AACnD,eAAO,MAAM,eAAe,GAAI,CAAC,EAC/B,OAAO,SAAS,CAAC,EAAE,KAClB,KAAK,IAAI,aAAa,CAAC,CAAC,CAAqB,CAAC;AAMjD,6DAA6D;AAC7D,eAAO,MAAM,KAAK,GAAI,CAAC,EAAE,OAAO,SAAS,CAAC,EAAE,EAAE,MAAM,MAAM,KAAG,CAAC,EAAE,EAS/D,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,MAAM,GAAI,CAAC,EACtB,OAAO,SAAS,CAAC,EAAE,EACnB,MAAM,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,KACzB,CAAC,EAcH,CAAC;AAEF,mCAAmC;AACnC,eAAO,MAAM,OAAO,GAAI,CAAC,EACvB,OAAO,SAAS,CAAC,EAAE,EACnB,KAAK,CAAC,IAAI,EAAE,CAAC,KAAK,MAAM,KACvB,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,CAOpB,CAAC;AAEF,qEAAqE;AACrE,eAAO,MAAM,MAAM,GAAI,CAAC,EACtB,OAAO,SAAS,CAAC,EAAE,EACnB,KAAK,CAAC,IAAI,EAAE,CAAC,KAAK,MAAM,GAAG,MAAM,KAChC,CAAC,EAQA,CAAC"}
|
package/dist/collections.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Collection utilities and type helpers for @ontrails/core.
|
|
3
|
-
*/
|
|
4
|
-
// ---------------------------------------------------------------------------
|
|
5
|
-
// Guards
|
|
6
|
-
// ---------------------------------------------------------------------------
|
|
7
|
-
/** Narrows a readonly array to a NonEmptyArray. */
|
|
8
|
-
export const isNonEmptyArray = (array) => array.length > 0;
|
|
9
|
-
// ---------------------------------------------------------------------------
|
|
10
|
-
// Collection functions
|
|
11
|
-
// ---------------------------------------------------------------------------
|
|
12
|
-
/** Split an array into chunks of at most `size` elements. */
|
|
13
|
-
export const chunk = (array, size) => {
|
|
14
|
-
if (size < 1) {
|
|
15
|
-
throw new RangeError('chunk size must be >= 1');
|
|
16
|
-
}
|
|
17
|
-
const result = [];
|
|
18
|
-
for (let i = 0; i < array.length; i += size) {
|
|
19
|
-
result.push(array.slice(i, i + size));
|
|
20
|
-
}
|
|
21
|
-
return result;
|
|
22
|
-
};
|
|
23
|
-
/**
|
|
24
|
-
* Remove duplicate items. When `key` is provided, uniqueness is determined
|
|
25
|
-
* by the return value of the key function; otherwise strict equality is used.
|
|
26
|
-
*/
|
|
27
|
-
export const dedupe = (array, key) => {
|
|
28
|
-
if (!key) {
|
|
29
|
-
return [...new Set(array)];
|
|
30
|
-
}
|
|
31
|
-
const seen = new Set();
|
|
32
|
-
const result = [];
|
|
33
|
-
for (const item of array) {
|
|
34
|
-
const k = key(item);
|
|
35
|
-
if (!seen.has(k)) {
|
|
36
|
-
seen.add(k);
|
|
37
|
-
result.push(item);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return result;
|
|
41
|
-
};
|
|
42
|
-
/** Group items by a string key. */
|
|
43
|
-
export const groupBy = (array, key) => {
|
|
44
|
-
const groups = {};
|
|
45
|
-
for (const item of array) {
|
|
46
|
-
const k = key(item);
|
|
47
|
-
(groups[k] ??= []).push(item);
|
|
48
|
-
}
|
|
49
|
-
return groups;
|
|
50
|
-
};
|
|
51
|
-
/** Return a new sorted array based on a key function (ascending). */
|
|
52
|
-
export const sortBy = (array, key) => [...array].toSorted((a, b) => {
|
|
53
|
-
const ka = key(a);
|
|
54
|
-
const kb = key(b);
|
|
55
|
-
if (typeof ka === 'number' && typeof kb === 'number') {
|
|
56
|
-
return ka - kb;
|
|
57
|
-
}
|
|
58
|
-
return String(ka).localeCompare(String(kb));
|
|
59
|
-
});
|
|
60
|
-
//# sourceMappingURL=collections.js.map
|
package/dist/collections.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"collections.js","sourceRoot":"","sources":["../src/collections.ts"],"names":[],"mappings":"AAAA;;GAEG;AAuBH,8EAA8E;AAC9E,SAAS;AACT,8EAA8E;AAE9E,mDAAmD;AACnD,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,KAAmB,EACQ,EAAE,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;AAEjD,8EAA8E;AAC9E,uBAAuB;AACvB,8EAA8E;AAE9E,6DAA6D;AAC7D,MAAM,CAAC,MAAM,KAAK,GAAG,CAAI,KAAmB,EAAE,IAAY,EAAS,EAAE;IACnE,IAAI,IAAI,GAAG,CAAC,EAAE,CAAC;QACb,MAAM,IAAI,UAAU,CAAC,yBAAyB,CAAC,CAAC;IAClD,CAAC;IACD,MAAM,MAAM,GAAU,EAAE,CAAC;IACzB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC;QAC5C,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;IACxC,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,CACpB,KAAmB,EACnB,GAA0B,EACrB,EAAE;IACP,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;IAC7B,CAAC;IACD,MAAM,IAAI,GAAG,IAAI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,EAAE,CAAC,CAAC,CAAC;AAC9C,CAAC,CAAC,CAAC"}
|
package/dist/context.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { TrailContext, TrailContextInit, TraceFn } from './types.js';
|
|
2
|
-
/**
|
|
3
|
-
* Default passthrough `trace` used when a context is built outside
|
|
4
|
-
* `executeTrail`. `executeTrail` replaces this with a real sink-writing
|
|
5
|
-
* implementation. The passthrough runs `fn` without recording anything so
|
|
6
|
-
* direct `createTrailContext()` callers (tests, ad-hoc compositions) don't
|
|
7
|
-
* crash when invoking `ctx.trace(...)`.
|
|
8
|
-
*
|
|
9
|
-
* Declared `async` so both synchronous throws and async rejections from `fn`
|
|
10
|
-
* propagate as a rejected promise to the caller — matching the real
|
|
11
|
-
* sink-writing implementation's error semantics.
|
|
12
|
-
*/
|
|
13
|
-
export declare const passthroughTrace: TraceFn;
|
|
14
|
-
/**
|
|
15
|
-
* Create a TrailContext with sensible defaults.
|
|
16
|
-
*
|
|
17
|
-
* - `requestId` defaults to `Bun.randomUUIDv7()` (sortable v7 UUID)
|
|
18
|
-
* - `abortSignal` defaults to a fresh, non-aborted `AbortSignal`
|
|
19
|
-
* - All other fields come from `overrides`
|
|
20
|
-
*/
|
|
21
|
-
export declare const createTrailContext: (overrides?: Partial<TrailContextInit>) => TrailContext;
|
|
22
|
-
//# sourceMappingURL=context.d.ts.map
|
package/dist/context.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAM1E;;;;;;;;;;GAUG;AACH,eAAO,MAAM,gBAAgB,EAAE,OAGJ,CAAC;AAE5B;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,GAC7B,YAAY,OAAO,CAAC,gBAAgB,CAAC,KACpC,YAeF,CAAC"}
|
package/dist/context.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { createResourceLookup } from './resource.js';
|
|
2
|
-
/**
|
|
3
|
-
* Default passthrough `trace` used when a context is built outside
|
|
4
|
-
* `executeTrail`. `executeTrail` replaces this with a real sink-writing
|
|
5
|
-
* implementation. The passthrough runs `fn` without recording anything so
|
|
6
|
-
* direct `createTrailContext()` callers (tests, ad-hoc compositions) don't
|
|
7
|
-
* crash when invoking `ctx.trace(...)`.
|
|
8
|
-
*
|
|
9
|
-
* Declared `async` so both synchronous throws and async rejections from `fn`
|
|
10
|
-
* propagate as a rejected promise to the caller — matching the real
|
|
11
|
-
* sink-writing implementation's error semantics.
|
|
12
|
-
*/
|
|
13
|
-
export const passthroughTrace = async (_label, fn) => await fn();
|
|
14
|
-
/**
|
|
15
|
-
* Create a TrailContext with sensible defaults.
|
|
16
|
-
*
|
|
17
|
-
* - `requestId` defaults to `Bun.randomUUIDv7()` (sortable v7 UUID)
|
|
18
|
-
* - `abortSignal` defaults to a fresh, non-aborted `AbortSignal`
|
|
19
|
-
* - All other fields come from `overrides`
|
|
20
|
-
*/
|
|
21
|
-
export const createTrailContext = (overrides) => {
|
|
22
|
-
const ctx = {
|
|
23
|
-
abortSignal: new AbortController().signal,
|
|
24
|
-
cwd: process.cwd(),
|
|
25
|
-
env: process.env,
|
|
26
|
-
requestId: Bun.randomUUIDv7(),
|
|
27
|
-
trace: passthroughTrace,
|
|
28
|
-
...overrides,
|
|
29
|
-
};
|
|
30
|
-
const lookup = overrides?.resource ?? createResourceLookup(() => ctx);
|
|
31
|
-
ctx.resource = lookup;
|
|
32
|
-
if (ctx.trace === undefined) {
|
|
33
|
-
ctx.trace = passthroughTrace;
|
|
34
|
-
}
|
|
35
|
-
return ctx;
|
|
36
|
-
};
|
|
37
|
-
//# sourceMappingURL=context.js.map
|
package/dist/context.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAOrD;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAY,KAAK,EAC5C,MAAc,EACd,EAAwB,EACZ,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC;AAE5B;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,SAAqC,EACvB,EAAE;IAChB,MAAM,GAAG,GAAG;QACV,WAAW,EAAE,IAAI,eAAe,EAAE,CAAC,MAAM;QACzC,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE;QAClB,GAAG,EAAE,OAAO,CAAC,GAAyC;QACtD,SAAS,EAAE,GAAG,CAAC,YAAY,EAAE;QAC7B,KAAK,EAAE,gBAAgB;QACvB,GAAG,SAAS;KACU,CAAC;IACzB,MAAM,MAAM,GAAG,SAAS,EAAE,QAAQ,IAAI,oBAAoB,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC;IACtE,GAAG,CAAC,QAAQ,GAAG,MAAM,CAAC;IACtB,IAAI,GAAG,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;QAC5B,GAAG,CAAC,KAAK,GAAG,gBAAgB,CAAC;IAC/B,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC,CAAC"}
|
package/dist/contour.d.ts
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import type { Branded } from './branded.js';
|
|
3
|
-
/**
|
|
4
|
-
* Runtime options for a contour declaration.
|
|
5
|
-
*/
|
|
6
|
-
export interface ContourOptions<TShape extends z.ZodRawShape, TIdentity extends keyof TShape & string> {
|
|
7
|
-
/** Field name that acts as the contour's primary identity. */
|
|
8
|
-
readonly identity: TIdentity;
|
|
9
|
-
/** Example instances validated against the contour schema at declaration time. */
|
|
10
|
-
readonly examples?: readonly z.output<z.ZodObject<TShape>>[] | undefined;
|
|
11
|
-
}
|
|
12
|
-
/** Type-level brand name applied to a contour's identity schema. */
|
|
13
|
-
export type ContourIdBrand<TName extends string> = `${Capitalize<TName>}Id`;
|
|
14
|
-
type BrandedSchema<TSchema extends z.core.$ZodType, TBrand extends string> = TSchema & z.ZodType<Branded<z.output<TSchema>, TBrand>>;
|
|
15
|
-
/** Output value of a branded contour identity schema. */
|
|
16
|
-
export type ContourIdValue<TSchema extends z.core.$ZodType, TName extends string> = Branded<z.output<TSchema>, ContourIdBrand<TName>>;
|
|
17
|
-
/** Runtime metadata attached to schemas returned from `contour.id()`. */
|
|
18
|
-
export interface ContourIdMetadata<TName extends string = string, TIdentity extends string = string> {
|
|
19
|
-
readonly contour: TName;
|
|
20
|
-
readonly identity: TIdentity;
|
|
21
|
-
}
|
|
22
|
-
/** A structural contour reference declared by another contour field schema. */
|
|
23
|
-
export interface ContourReference<TName extends string = string, TIdentity extends string = string> extends ContourIdMetadata<TName, TIdentity> {
|
|
24
|
-
readonly field: string;
|
|
25
|
-
}
|
|
26
|
-
/** Symbol used to tag branded contour reference schemas at runtime. */
|
|
27
|
-
export declare const CONTOUR_ID_METADATA: unique symbol;
|
|
28
|
-
/**
|
|
29
|
-
* A contour identity schema branded for one contour and tagged with runtime
|
|
30
|
-
* metadata so the topo layer can recognize declared references later on.
|
|
31
|
-
*/
|
|
32
|
-
export type ContourIdSchema<TSchema extends z.core.$ZodType = z.core.$ZodType, TName extends string = string, TIdentity extends string = string> = BrandedSchema<TSchema, ContourIdBrand<TName>> & {
|
|
33
|
-
/** @deprecated Use `getContourIdMetadata()` — metadata lives in a WeakMap, not on the schema. */
|
|
34
|
-
readonly [CONTOUR_ID_METADATA]?: ContourIdMetadata<TName, TIdentity>;
|
|
35
|
-
};
|
|
36
|
-
/**
|
|
37
|
-
* A first-class domain object with schema, identity metadata, and examples.
|
|
38
|
-
*
|
|
39
|
-
* A contour behaves like the `ZodObject` it wraps, so standard Zod composition
|
|
40
|
-
* helpers such as `.pick()`, `.extend()`, and `.array()` continue to work.
|
|
41
|
-
*/
|
|
42
|
-
export type Contour<TName extends string = string, TShape extends z.ZodRawShape = z.ZodRawShape, TIdentity extends keyof TShape & string = keyof TShape & string> = z.ZodObject<TShape> & {
|
|
43
|
-
readonly kind: 'contour';
|
|
44
|
-
readonly name: TName;
|
|
45
|
-
readonly identity: TIdentity;
|
|
46
|
-
readonly identitySchema: TShape[TIdentity];
|
|
47
|
-
readonly id: () => ContourIdSchema<TShape[TIdentity], TName, TIdentity>;
|
|
48
|
-
readonly examples?: readonly z.output<z.ZodObject<TShape>>[] | undefined;
|
|
49
|
-
};
|
|
50
|
-
/**
|
|
51
|
-
* Read contour-reference metadata from a schema returned by `contour.id()`.
|
|
52
|
-
*
|
|
53
|
-
* When the schema is wrapped by Zod combinators (`.optional()`, `.nullable()`,
|
|
54
|
-
* `.default()`, `.nullish()`, etc.) the `CONTOUR_ID_METADATA` symbol lives on
|
|
55
|
-
* the inner schema, not on the wrapper. The unwrap handles arbitrarily nested
|
|
56
|
-
* wrapper levels.
|
|
57
|
-
*/
|
|
58
|
-
export declare const getContourIdMetadata: (schema: unknown) => ContourIdMetadata | undefined;
|
|
59
|
-
/** Inspect a contour schema for fields that reference other contours via `.id()`. */
|
|
60
|
-
export declare const getContourReferences: (contour: AnyContour) => readonly ContourReference[];
|
|
61
|
-
/**
|
|
62
|
-
* Create a contour definition from a raw Zod object shape.
|
|
63
|
-
*
|
|
64
|
-
* @example
|
|
65
|
-
* ```typescript
|
|
66
|
-
* const user = contour(
|
|
67
|
-
* 'user',
|
|
68
|
-
* {
|
|
69
|
-
* id: z.string().uuid(),
|
|
70
|
-
* email: z.string().email(),
|
|
71
|
-
* name: z.string(),
|
|
72
|
-
* },
|
|
73
|
-
* { identity: 'id' }
|
|
74
|
-
* );
|
|
75
|
-
* ```
|
|
76
|
-
*/
|
|
77
|
-
export declare const contour: <TName extends string, TShape extends z.ZodRawShape, TIdentity extends keyof TShape & string>(name: TName, shape: TShape, options: ContourOptions<TShape, TIdentity>) => Contour<TName, TShape, TIdentity>;
|
|
78
|
-
/** Existential type for heterogeneous contour collections. */
|
|
79
|
-
export type AnyContour = Contour<string, z.ZodRawShape, string>;
|
|
80
|
-
export {};
|
|
81
|
-
//# sourceMappingURL=contour.d.ts.map
|
package/dist/contour.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"contour.d.ts","sourceRoot":"","sources":["../src/contour.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C;;GAEG;AACH,MAAM,WAAW,cAAc,CAC7B,MAAM,SAAS,CAAC,CAAC,WAAW,EAC5B,SAAS,SAAS,MAAM,MAAM,GAAG,MAAM;IAEvC,8DAA8D;IAC9D,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC;IAC7B,kFAAkF;IAClF,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,SAAS,CAAC;CAC1E;AAED,oEAAoE;AACpE,MAAM,MAAM,cAAc,CAAC,KAAK,SAAS,MAAM,IAAI,GAAG,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC;AAE5E,KAAK,aAAa,CAChB,OAAO,SAAS,CAAC,CAAC,IAAI,CAAC,QAAQ,EAC/B,MAAM,SAAS,MAAM,IACnB,OAAO,GAAG,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;AAM5D,yDAAyD;AACzD,MAAM,MAAM,cAAc,CACxB,OAAO,SAAS,CAAC,CAAC,IAAI,CAAC,QAAQ,EAC/B,KAAK,SAAS,MAAM,IAClB,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,cAAc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AAE,KAAK,CAAC;IACrB,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC;IAC7B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC;IAC3C,QAAQ,CAAC,EAAE,EAAE,MAAM,eAAe,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC;IACxE,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,SAAS,CAAC;CAC1E,CAAC;AA+JF;;;;;;;GAOG;AACH,eAAO,MAAM,oBAAoB,GAC/B,QAAQ,OAAO,KACd,iBAAiB,GAAG,SAC2B,CAAC;AAEnD,qFAAqF;AACrF,eAAO,MAAM,oBAAoB,GAC/B,SAAS,UAAU,KAClB,SAAS,gBAAgB,EAiBvB,CAAC;AAEN;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,OAAO,GAClB,KAAK,SAAS,MAAM,EACpB,MAAM,SAAS,CAAC,CAAC,WAAW,EAC5B,SAAS,SAAS,MAAM,MAAM,GAAG,MAAM,EAEvC,MAAM,KAAK,EACX,OAAO,MAAM,EACb,SAAS,cAAc,CAAC,MAAM,EAAE,SAAS,CAAC,KACzC,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,CA2BlC,CAAC;AAEF,8DAA8D;AAC9D,MAAM,MAAM,UAAU,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC"}
|
package/dist/contour.js
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
/** Symbol used to tag branded contour reference schemas at runtime. */
|
|
3
|
-
export const CONTOUR_ID_METADATA = Symbol.for('@ontrails/core/contour-id');
|
|
4
|
-
/**
|
|
5
|
-
* Module-level WeakMap storing contour identity metadata keyed by schema object.
|
|
6
|
-
*
|
|
7
|
-
* First-write-wins: when multiple contours share the same underlying schema
|
|
8
|
-
* (e.g. `contour('admin', { id: user.shape.id }, ...)`), the first contour to
|
|
9
|
-
* brand the schema claims it. Subsequent calls skip the write to prevent
|
|
10
|
-
* silent metadata corruption.
|
|
11
|
-
*/
|
|
12
|
-
const contourIdMetadata = new WeakMap();
|
|
13
|
-
const formatExampleIssues = (issues) => issues
|
|
14
|
-
.map((issue) => {
|
|
15
|
-
const path = issue.path.length > 0 ? issue.path.join('.') : '<root>';
|
|
16
|
-
return `${path}: ${issue.message}`;
|
|
17
|
-
})
|
|
18
|
-
.join('; ');
|
|
19
|
-
const assertIdentityField = (name, shape, identity) => {
|
|
20
|
-
if (!Object.hasOwn(shape, identity)) {
|
|
21
|
-
throw new TypeError(`contour("${name}") identity "${identity}" must match a declared field`);
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
const assertExamples = (name, schema, examples) => {
|
|
25
|
-
for (const [index, example] of examples.entries()) {
|
|
26
|
-
const parsed = schema.safeParse(example);
|
|
27
|
-
if (!parsed.success) {
|
|
28
|
-
throw new TypeError(`contour("${name}") example ${index} is invalid: ${formatExampleIssues(parsed.error.issues)}`);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
const validateExamples = (name, schema, examples) => {
|
|
33
|
-
if (examples) {
|
|
34
|
-
assertExamples(name, schema, examples);
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
const brandIdentitySchema = (contour, identity, schema) => {
|
|
38
|
-
const branded = schema.brand();
|
|
39
|
-
// First-write-wins: if another contour already claimed this schema object
|
|
40
|
-
// (possible when Zod v4 brand() returns `this`), preserve the original
|
|
41
|
-
// metadata rather than silently overwriting it.
|
|
42
|
-
if (!contourIdMetadata.has(branded)) {
|
|
43
|
-
contourIdMetadata.set(branded, {
|
|
44
|
-
contour,
|
|
45
|
-
identity,
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
return branded;
|
|
49
|
-
};
|
|
50
|
-
const attachContourMetadata = (schema, metadata) => {
|
|
51
|
-
Object.defineProperties(schema, {
|
|
52
|
-
examples: {
|
|
53
|
-
enumerable: true,
|
|
54
|
-
value: metadata.examples,
|
|
55
|
-
writable: false,
|
|
56
|
-
},
|
|
57
|
-
id: {
|
|
58
|
-
enumerable: true,
|
|
59
|
-
value: () => metadata.idSchema,
|
|
60
|
-
writable: false,
|
|
61
|
-
},
|
|
62
|
-
identity: {
|
|
63
|
-
enumerable: true,
|
|
64
|
-
value: metadata.identity,
|
|
65
|
-
writable: false,
|
|
66
|
-
},
|
|
67
|
-
identitySchema: {
|
|
68
|
-
enumerable: true,
|
|
69
|
-
value: metadata.identitySchema,
|
|
70
|
-
writable: false,
|
|
71
|
-
},
|
|
72
|
-
kind: {
|
|
73
|
-
enumerable: true,
|
|
74
|
-
value: 'contour',
|
|
75
|
-
writable: false,
|
|
76
|
-
},
|
|
77
|
-
name: {
|
|
78
|
-
enumerable: true,
|
|
79
|
-
value: metadata.name,
|
|
80
|
-
writable: false,
|
|
81
|
-
},
|
|
82
|
-
});
|
|
83
|
-
};
|
|
84
|
-
/** Read contour identity metadata from the module-level WeakMap, if present. */
|
|
85
|
-
const readMetadata = (schema) => typeof schema === 'object' && schema !== null
|
|
86
|
-
? contourIdMetadata.get(schema)
|
|
87
|
-
: undefined;
|
|
88
|
-
/** Resolve the inner schema from a Zod wrapper (ZodOptional, ZodNullable, etc.). */
|
|
89
|
-
const unwrapInner = (schema) => {
|
|
90
|
-
const def = schema._def;
|
|
91
|
-
return (def?.['innerType'] ?? def?.['schema']);
|
|
92
|
-
};
|
|
93
|
-
/**
|
|
94
|
-
* Walk through Zod wrapper layers searching for `CONTOUR_ID_METADATA`.
|
|
95
|
-
*
|
|
96
|
-
* `.nullish()` produces `ZodOptional<ZodNullable<T>>` — two wrapper levels —
|
|
97
|
-
* so a single-step unwrap is insufficient. This iterates until it finds the
|
|
98
|
-
* metadata or exhausts all wrapper layers.
|
|
99
|
-
*/
|
|
100
|
-
const unwrapToMetadata = (schema) => {
|
|
101
|
-
let current = schema;
|
|
102
|
-
while (typeof current === 'object' && current !== null) {
|
|
103
|
-
const inner = unwrapInner(current);
|
|
104
|
-
if (typeof inner !== 'object' || inner === null) {
|
|
105
|
-
return undefined;
|
|
106
|
-
}
|
|
107
|
-
const metadata = readMetadata(inner);
|
|
108
|
-
if (metadata !== undefined) {
|
|
109
|
-
return metadata;
|
|
110
|
-
}
|
|
111
|
-
current = inner;
|
|
112
|
-
}
|
|
113
|
-
return undefined;
|
|
114
|
-
};
|
|
115
|
-
/**
|
|
116
|
-
* Read contour-reference metadata from a schema returned by `contour.id()`.
|
|
117
|
-
*
|
|
118
|
-
* When the schema is wrapped by Zod combinators (`.optional()`, `.nullable()`,
|
|
119
|
-
* `.default()`, `.nullish()`, etc.) the `CONTOUR_ID_METADATA` symbol lives on
|
|
120
|
-
* the inner schema, not on the wrapper. The unwrap handles arbitrarily nested
|
|
121
|
-
* wrapper levels.
|
|
122
|
-
*/
|
|
123
|
-
export const getContourIdMetadata = (schema) => readMetadata(schema) ?? unwrapToMetadata(schema);
|
|
124
|
-
/** Inspect a contour schema for fields that reference other contours via `.id()`. */
|
|
125
|
-
export const getContourReferences = (contour) => Object.entries(contour.shape)
|
|
126
|
-
.flatMap(([field, schema]) => {
|
|
127
|
-
if (field === contour.identity) {
|
|
128
|
-
return [];
|
|
129
|
-
}
|
|
130
|
-
const metadata = getContourIdMetadata(schema);
|
|
131
|
-
if (metadata === undefined) {
|
|
132
|
-
return [];
|
|
133
|
-
}
|
|
134
|
-
return [{ field, ...metadata }];
|
|
135
|
-
})
|
|
136
|
-
.toSorted((left, right) => left.field === right.field
|
|
137
|
-
? left.contour.localeCompare(right.contour)
|
|
138
|
-
: left.field.localeCompare(right.field));
|
|
139
|
-
/**
|
|
140
|
-
* Create a contour definition from a raw Zod object shape.
|
|
141
|
-
*
|
|
142
|
-
* @example
|
|
143
|
-
* ```typescript
|
|
144
|
-
* const user = contour(
|
|
145
|
-
* 'user',
|
|
146
|
-
* {
|
|
147
|
-
* id: z.string().uuid(),
|
|
148
|
-
* email: z.string().email(),
|
|
149
|
-
* name: z.string(),
|
|
150
|
-
* },
|
|
151
|
-
* { identity: 'id' }
|
|
152
|
-
* );
|
|
153
|
-
* ```
|
|
154
|
-
*/
|
|
155
|
-
export const contour = (name, shape, options) => {
|
|
156
|
-
assertIdentityField(name, shape, options.identity);
|
|
157
|
-
const schema = z.object(shape);
|
|
158
|
-
validateExamples(name, schema, options.examples);
|
|
159
|
-
const identitySchema = shape[options.identity];
|
|
160
|
-
if (!identitySchema) {
|
|
161
|
-
throw new TypeError(`contour("${name}") identity "${options.identity}" must resolve to a schema`);
|
|
162
|
-
}
|
|
163
|
-
const idSchema = brandIdentitySchema(name, options.identity, identitySchema);
|
|
164
|
-
const examples = options.examples
|
|
165
|
-
? Object.freeze([...options.examples])
|
|
166
|
-
: undefined;
|
|
167
|
-
attachContourMetadata(schema, {
|
|
168
|
-
examples,
|
|
169
|
-
idSchema,
|
|
170
|
-
identity: options.identity,
|
|
171
|
-
identitySchema,
|
|
172
|
-
name,
|
|
173
|
-
});
|
|
174
|
-
return schema;
|
|
175
|
-
};
|
|
176
|
-
//# sourceMappingURL=contour.js.map
|
package/dist/contour.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"contour.js","sourceRoot":"","sources":["../src/contour.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAoDxB,uEAAuE;AACvE,MAAM,CAAC,MAAM,mBAAmB,GAAG,MAAM,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC;AAE3E;;;;;;;GAOG;AACH,MAAM,iBAAiB,GAAG,IAAI,OAAO,EAA6B,CAAC;AAkCnE,MAAM,mBAAmB,GAAG,CAAC,MAAmC,EAAU,EAAE,CAC1E,MAAM;KACH,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;IAC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C,QAAQ,EAAE,cAAc,CAAC,CAAC;IAC7E,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ;QAC/B,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;QACtC,CAAC,CAAC,SAAS,CAAC;IAEd,qBAAqB,CAAC,MAAM,EAAE;QAC5B,QAAQ;QACR,QAAQ;QACR,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,cAAc;QACd,IAAI;KACL,CAAC,CAAC;IAEH,OAAO,MAA2C,CAAC;AACrD,CAAC,CAAC"}
|
package/dist/cross-schema.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Cross-invocation schema merging for trails with `crossInput`.
|
|
3
|
-
*
|
|
4
|
-
* When a trail declares `crossInput`, callers via `ctx.cross()` pass both
|
|
5
|
-
* public input and composition-only fields. The merged schema validates the
|
|
6
|
-
* combined shape so `executeTrail` doesn't reject the extra fields.
|
|
7
|
-
*/
|
|
8
|
-
import { z } from 'zod';
|
|
9
|
-
import type { AnyTrail } from './trail.js';
|
|
10
|
-
/**
|
|
11
|
-
* Build the validation schema for a cross-invoked trail.
|
|
12
|
-
*
|
|
13
|
-
* When the target trail declares `crossInput`, returns the intersection of
|
|
14
|
-
* `trail.input` and `trail.crossInput`. Returns `undefined` when no
|
|
15
|
-
* `crossInput` is declared, signaling that normal input validation suffices.
|
|
16
|
-
*/
|
|
17
|
-
export declare const buildCrossValidationSchema: (trailDef: AnyTrail) => z.ZodType | undefined;
|
|
18
|
-
//# sourceMappingURL=cross-schema.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cross-schema.d.ts","sourceRoot":"","sources":["../src/cross-schema.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C;;;;;;GAMG;AACH,eAAO,MAAM,0BAA0B,GACrC,UAAU,QAAQ,KACjB,CAAC,CAAC,OAAO,GAAG,SAcd,CAAC"}
|