@ontrails/core 1.0.0-beta.13 → 1.0.0-beta.15
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 +17 -0
- package/README.md +19 -14
- package/dist/branded.d.ts +1 -1
- package/dist/branded.d.ts.map +1 -1
- package/dist/branded.js +1 -1
- package/dist/branded.js.map +1 -1
- package/dist/context.d.ts +13 -1
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +19 -3
- package/dist/context.js.map +1 -1
- package/dist/contour.d.ts +81 -0
- package/dist/contour.d.ts.map +1 -0
- package/dist/contour.js +176 -0
- package/dist/contour.js.map +1 -0
- package/dist/cross-schema.d.ts +18 -0
- package/dist/cross-schema.d.ts.map +1 -0
- package/dist/cross-schema.js +29 -0
- package/dist/cross-schema.js.map +1 -0
- package/dist/derive.d.ts +6 -0
- package/dist/derive.d.ts.map +1 -1
- package/dist/derive.js +29 -5
- package/dist/derive.js.map +1 -1
- package/dist/draft.d.ts +28 -0
- package/dist/draft.d.ts.map +1 -0
- package/dist/draft.js +157 -0
- package/dist/draft.js.map +1 -0
- package/dist/errors.d.ts +62 -4
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +44 -1
- package/dist/errors.js.map +1 -1
- package/dist/execute.d.ts +26 -9
- package/dist/execute.d.ts.map +1 -1
- package/dist/execute.js +441 -20
- package/dist/execute.js.map +1 -1
- package/dist/fire.d.ts +43 -0
- package/dist/fire.d.ts.map +1 -0
- package/dist/fire.js +185 -0
- package/dist/fire.js.map +1 -0
- package/dist/index.d.ts +33 -17
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +26 -12
- package/dist/index.js.map +1 -1
- package/dist/internal/cross-batch.d.ts +44 -0
- package/dist/internal/cross-batch.d.ts.map +1 -0
- package/dist/internal/cross-batch.js +58 -0
- package/dist/internal/cross-batch.js.map +1 -0
- package/dist/internal/fork-ctx.d.ts +41 -0
- package/dist/internal/fork-ctx.d.ts.map +1 -0
- package/dist/internal/fork-ctx.js +47 -0
- package/dist/internal/fork-ctx.js.map +1 -0
- package/dist/internal/signal-ref.d.ts +15 -0
- package/dist/internal/signal-ref.d.ts.map +1 -0
- package/dist/internal/signal-ref.js +41 -0
- package/dist/internal/signal-ref.js.map +1 -0
- package/dist/internal/topo-saves.d.ts +53 -0
- package/dist/internal/topo-saves.d.ts.map +1 -0
- package/dist/internal/topo-saves.js +449 -0
- package/dist/internal/topo-saves.js.map +1 -0
- package/dist/internal/topo-snapshots.d.ts +57 -0
- package/dist/internal/topo-snapshots.d.ts.map +1 -0
- package/dist/internal/topo-snapshots.js +372 -0
- package/dist/internal/topo-snapshots.js.map +1 -0
- package/dist/internal/topo-store-read.d.ts +70 -0
- package/dist/internal/topo-store-read.d.ts.map +1 -0
- package/dist/internal/topo-store-read.js +221 -0
- package/dist/internal/topo-store-read.js.map +1 -0
- package/dist/internal/topo-store.d.ts +26 -0
- package/dist/internal/topo-store.d.ts.map +1 -0
- package/dist/internal/topo-store.js +621 -0
- package/dist/internal/topo-store.js.map +1 -0
- package/dist/internal/tracing.d.ts +98 -0
- package/dist/internal/tracing.d.ts.map +1 -0
- package/dist/internal/tracing.js +102 -0
- package/dist/internal/tracing.js.map +1 -0
- package/dist/internal/trails-db.d.ts +16 -0
- package/dist/internal/trails-db.d.ts.map +1 -0
- package/dist/internal/trails-db.js +118 -0
- package/dist/internal/trails-db.js.map +1 -0
- package/dist/internal/zod-wrappers.d.ts +40 -0
- package/dist/internal/zod-wrappers.d.ts.map +1 -0
- package/dist/internal/zod-wrappers.js +59 -0
- package/dist/internal/zod-wrappers.js.map +1 -0
- package/dist/layer.d.ts +22 -5
- package/dist/layer.d.ts.map +1 -1
- package/dist/layer.js +20 -3
- package/dist/layer.js.map +1 -1
- package/dist/path-security.d.ts +1 -1
- package/dist/path-security.d.ts.map +1 -1
- package/dist/path-security.js +1 -1
- package/dist/path-security.js.map +1 -1
- package/dist/resilience.d.ts +1 -1
- package/dist/resilience.d.ts.map +1 -1
- package/dist/resilience.js +3 -3
- package/dist/resilience.js.map +1 -1
- package/dist/resource-config.d.ts +22 -0
- package/dist/resource-config.d.ts.map +1 -0
- package/dist/resource-config.js +210 -0
- package/dist/resource-config.js.map +1 -0
- package/dist/resource.d.ts +74 -0
- package/dist/resource.d.ts.map +1 -0
- package/dist/resource.js +61 -0
- package/dist/resource.js.map +1 -0
- package/dist/run.d.ts +4 -3
- package/dist/run.d.ts.map +1 -1
- package/dist/run.js +5 -4
- package/dist/run.js.map +1 -1
- package/dist/serialization.d.ts.map +1 -1
- package/dist/serialization.js +2 -1
- package/dist/serialization.js.map +1 -1
- package/dist/store/accessor-protocol.d.ts +51 -0
- package/dist/store/accessor-protocol.d.ts.map +1 -0
- package/dist/store/accessor-protocol.js +2 -0
- package/dist/store/accessor-protocol.js.map +1 -0
- package/dist/store/index.d.ts +2 -0
- package/dist/store/index.d.ts.map +1 -0
- package/dist/store/index.js +2 -0
- package/dist/store/index.js.map +1 -0
- package/dist/surface-filter.d.ts +13 -0
- package/dist/surface-filter.d.ts.map +1 -0
- package/dist/surface-filter.js +76 -0
- package/dist/surface-filter.js.map +1 -0
- package/dist/topo-store.d.ts +62 -0
- package/dist/topo-store.d.ts.map +1 -0
- package/dist/topo-store.js +319 -0
- package/dist/topo-store.js.map +1 -0
- package/dist/topo.d.ts +23 -9
- package/dist/topo.d.ts.map +1 -1
- package/dist/topo.js +175 -46
- package/dist/topo.js.map +1 -1
- package/dist/trail.d.ts +86 -19
- package/dist/trail.d.ts.map +1 -1
- package/dist/trail.js +59 -4
- package/dist/trail.js.map +1 -1
- package/dist/trails/derive-trail.d.ts +66 -0
- package/dist/trails/derive-trail.d.ts.map +1 -0
- package/dist/trails/derive-trail.js +378 -0
- package/dist/trails/derive-trail.js.map +1 -0
- package/dist/trails/index.d.ts +5 -0
- package/dist/trails/index.d.ts.map +1 -0
- package/dist/trails/index.js +3 -0
- package/dist/trails/index.js.map +1 -0
- package/dist/trails/ingest.d.ts +24 -0
- package/dist/trails/ingest.d.ts.map +1 -0
- package/dist/trails/ingest.js +63 -0
- package/dist/trails/ingest.js.map +1 -0
- package/dist/transport-error-map.d.ts +106 -0
- package/dist/transport-error-map.d.ts.map +1 -0
- package/dist/transport-error-map.js +24 -0
- package/dist/transport-error-map.js.map +1 -0
- package/dist/type-checks.test-d.d.ts +71 -0
- package/dist/type-checks.test-d.d.ts.map +1 -0
- package/dist/type-checks.test-d.js +12 -0
- package/dist/type-checks.test-d.js.map +1 -0
- package/dist/type-utils.d.ts +11 -2
- package/dist/type-utils.d.ts.map +1 -1
- package/dist/type-utils.js.map +1 -1
- package/dist/types.d.ts +113 -7
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/validate-established-topo.d.ts +76 -0
- package/dist/validate-established-topo.d.ts.map +1 -0
- package/dist/validate-established-topo.js +43 -0
- package/dist/validate-established-topo.js.map +1 -0
- package/dist/validate-topo.d.ts.map +1 -1
- package/dist/validate-topo.js +27 -8
- package/dist/validate-topo.js.map +1 -1
- package/dist/workspace.d.ts +1 -1
- package/dist/workspace.d.ts.map +1 -1
- package/dist/workspace.js +1 -1
- package/dist/workspace.js.map +1 -1
- package/package.json +10 -1
- package/src/__tests__/branded.test.ts +5 -5
- package/src/__tests__/context.test.ts +3 -3
- package/src/__tests__/contour.test.ts +263 -0
- package/src/__tests__/derive-trail.test.ts +668 -0
- package/src/__tests__/derive.test.ts +58 -1
- package/src/__tests__/errors.test.ts +118 -0
- package/src/__tests__/execute.test.ts +1179 -141
- package/src/__tests__/fire.test.ts +1056 -0
- package/src/__tests__/fork-ctx.test.ts +83 -0
- package/src/__tests__/ingest.test.ts +191 -0
- package/src/__tests__/{gate.test.ts → layer.test.ts} +21 -21
- package/src/__tests__/path-security.test.ts +7 -7
- package/src/__tests__/resilience.test.ts +8 -8
- package/src/__tests__/resource.test.ts +204 -0
- package/src/__tests__/run.test.ts +13 -13
- package/src/__tests__/service-config.test.ts +28 -32
- package/src/__tests__/surface-filter.test.ts +196 -0
- package/src/__tests__/topo-store-read.test.ts +256 -0
- package/src/__tests__/topo-store.test.ts +869 -0
- package/src/__tests__/topo.test.ts +350 -54
- package/src/__tests__/trail.test.ts +189 -24
- package/src/__tests__/trails-db.test.ts +198 -0
- package/src/__tests__/transport-error-map.test.ts +82 -0
- package/src/__tests__/type-utils.test.ts +29 -1
- package/src/__tests__/validate-topo.test.ts +305 -16
- package/src/__tests__/workspace.test.ts +6 -6
- package/src/__tests__/zod-wrappers.test.ts +62 -0
- package/src/branded.ts +1 -1
- package/src/context.ts +24 -4
- package/src/contour.ts +344 -0
- package/src/cross-schema.ts +36 -0
- package/src/derive.ts +39 -8
- package/src/draft.ts +338 -0
- package/src/errors.ts +62 -18
- package/src/execute.ts +840 -29
- package/src/fire.ts +295 -0
- package/src/index.ts +142 -26
- package/src/internal/cross-batch.ts +77 -0
- package/src/internal/fork-ctx.ts +69 -0
- package/src/internal/signal-ref.ts +87 -0
- package/src/internal/topo-snapshots.ts +517 -0
- package/src/internal/topo-store-read.ts +481 -0
- package/src/internal/topo-store.ts +1192 -0
- package/src/internal/tracing.ts +187 -0
- package/src/internal/trails-db.ts +187 -0
- package/src/internal/zod-wrappers.ts +78 -0
- package/src/layer.ts +50 -0
- package/src/path-security.ts +1 -1
- package/src/resilience.ts +3 -3
- package/src/{provision-config.ts → resource-config.ts} +109 -123
- package/src/resource.ts +155 -0
- package/src/run.ts +5 -4
- package/src/serialization.ts +2 -0
- package/src/store/accessor-protocol.ts +56 -0
- package/src/store/index.ts +4 -0
- package/src/surface-filter.ts +182 -0
- package/src/topo-store.ts +510 -0
- package/src/topo.ts +328 -57
- package/src/trail.ts +199 -31
- package/src/trails/derive-trail.ts +842 -0
- package/src/trails/index.ts +9 -0
- package/src/trails/ingest.ts +146 -0
- package/src/transport-error-map.ts +56 -0
- package/src/type-checks.test-d.ts +106 -0
- package/src/type-utils.ts +17 -2
- package/src/types.ts +148 -11
- package/src/validate-established-topo.ts +63 -0
- package/src/validate-topo.ts +37 -9
- package/src/workspace.ts +1 -1
- package/tsconfig.tests.json +10 -0
- package/tsconfig.tsbuildinfo +1 -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/dispatch.d.ts +0 -27
- package/dist/dispatch.d.ts.map +0 -1
- package/dist/dispatch.js +0 -34
- package/dist/dispatch.js.map +0 -1
- package/dist/event.d.ts +0 -8
- package/dist/event.d.ts.map +0 -1
- package/dist/event.js +0 -7
- package/dist/event.js.map +0 -1
- package/dist/gate.d.ts +0 -17
- package/dist/gate.d.ts.map +0 -1
- package/dist/gate.js +0 -21
- package/dist/gate.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/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/provision-config.d.ts +0 -22
- package/dist/provision-config.d.ts.map +0 -1
- package/dist/provision-config.js +0 -210
- package/dist/provision-config.js.map +0 -1
- package/dist/provision.d.ts +0 -71
- package/dist/provision.d.ts.map +0 -1
- package/dist/provision.js +0 -56
- package/dist/provision.js.map +0 -1
- package/dist/service-config.d.ts +0 -22
- package/dist/service-config.d.ts.map +0 -1
- package/dist/service-config.js +0 -210
- package/dist/service-config.js.map +0 -1
- package/dist/service.d.ts +0 -71
- package/dist/service.d.ts.map +0 -1
- package/dist/service.js +0 -56
- package/dist/service.js.map +0 -1
- package/src/__tests__/service.test.ts +0 -197
- package/src/event.ts +0 -15
- package/src/gate.ts +0 -44
- package/src/provision.ts +0 -148
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structural accessor protocol used by `deriveTrail()` to synthesize default
|
|
3
|
+
* blazes for standard CRUD operations without depending on `@ontrails/store`.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* This type is intentionally minimal and structural. `@ontrails/store`'s
|
|
7
|
+
* `StoreAccessor` / `StoreTableAccessor` interfaces satisfy this protocol
|
|
8
|
+
* through a compile-time extends check (see `packages/store/src/types.ts`).
|
|
9
|
+
* Keeping the protocol in core avoids a core → store dependency while still
|
|
10
|
+
* allowing the derivation helper to call accessors by convention.
|
|
11
|
+
*
|
|
12
|
+
* Required methods (`get`, `list`, `upsert`, `remove`) match the
|
|
13
|
+
* connector-agnostic write contract every bound store must expose. Optional
|
|
14
|
+
* methods (`insert`, `update`) are declared by tabular connectors that
|
|
15
|
+
* distinguish create-only and patch-only operations from the generalized
|
|
16
|
+
* `upsert` contract.
|
|
17
|
+
*/
|
|
18
|
+
export interface StoreAccessorProtocol<
|
|
19
|
+
TInput,
|
|
20
|
+
TEntity,
|
|
21
|
+
TId,
|
|
22
|
+
TFilters = unknown,
|
|
23
|
+
> {
|
|
24
|
+
/** Retrieve a single entity by identity. Returns `null` when not found. */
|
|
25
|
+
get(id: TId): Promise<TEntity | null>;
|
|
26
|
+
/** List entities, optionally filtered. Returns `[]` when no rows match. */
|
|
27
|
+
list(filters?: TFilters): Promise<readonly TEntity[]>;
|
|
28
|
+
/** Create-or-replace one entity using the connector-agnostic contract. */
|
|
29
|
+
upsert(input: TInput): Promise<TEntity>;
|
|
30
|
+
/**
|
|
31
|
+
* Remove an entity by identity. Returns `{ deleted: true }` when the row
|
|
32
|
+
* was found and removed, `{ deleted: false }` when no matching row
|
|
33
|
+
* existed (not an error).
|
|
34
|
+
*/
|
|
35
|
+
remove(id: TId): Promise<{ readonly deleted: boolean }>;
|
|
36
|
+
/**
|
|
37
|
+
* Optional insert — available on tabular connectors that distinguish
|
|
38
|
+
* create from update. When absent, synthesized blazes fall back to
|
|
39
|
+
* `upsert`.
|
|
40
|
+
*/
|
|
41
|
+
insert?(input: TInput): Promise<TEntity>;
|
|
42
|
+
/**
|
|
43
|
+
* Optional patch-by-identity — available on tabular connectors. Returns
|
|
44
|
+
* `null` when no row with the given identity exists. When absent,
|
|
45
|
+
* synthesized update blazes fall back to `get` + merge + `upsert`.
|
|
46
|
+
*/
|
|
47
|
+
update?(id: TId, patch: Partial<TInput>): Promise<TEntity | null>;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Record shape returned by a resource's `from(ctx)` call, keyed by accessor
|
|
52
|
+
* name. Used by `deriveTrail()` to resolve an accessor by contour name.
|
|
53
|
+
*/
|
|
54
|
+
export type StoreAccessorRecord = Readonly<
|
|
55
|
+
Record<string, StoreAccessorProtocol<unknown, unknown, unknown, unknown>>
|
|
56
|
+
>;
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import type { Intent, Trail } from './trail.js';
|
|
2
|
+
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
// Public types
|
|
5
|
+
// ---------------------------------------------------------------------------
|
|
6
|
+
|
|
7
|
+
export interface SurfaceFilterOptions {
|
|
8
|
+
/** Glob patterns that keep only matching trail IDs when provided. */
|
|
9
|
+
readonly include?: readonly string[] | undefined;
|
|
10
|
+
/** Glob patterns that remove matching trail IDs. */
|
|
11
|
+
readonly exclude?: readonly string[] | undefined;
|
|
12
|
+
/** Allowed intents for exposed trailheads. Empty arrays act as no filter. */
|
|
13
|
+
readonly intent?: readonly Intent[] | undefined;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// ---------------------------------------------------------------------------
|
|
17
|
+
// Glob matching
|
|
18
|
+
// ---------------------------------------------------------------------------
|
|
19
|
+
|
|
20
|
+
const trailIdSegments = (trailId: string): readonly string[] =>
|
|
21
|
+
trailId.split('.');
|
|
22
|
+
|
|
23
|
+
const patternSegments = (pattern: string): readonly string[] =>
|
|
24
|
+
pattern.split('.');
|
|
25
|
+
|
|
26
|
+
type SegmentMatcher = (
|
|
27
|
+
trail: readonly string[],
|
|
28
|
+
pattern: readonly string[],
|
|
29
|
+
trailIndex: number,
|
|
30
|
+
patternIndex: number
|
|
31
|
+
) => boolean;
|
|
32
|
+
|
|
33
|
+
const matchesDoubleStar = (
|
|
34
|
+
trail: readonly string[],
|
|
35
|
+
pattern: readonly string[],
|
|
36
|
+
trailIndex: number,
|
|
37
|
+
patternIndex: number,
|
|
38
|
+
matchSegments: SegmentMatcher
|
|
39
|
+
): boolean =>
|
|
40
|
+
patternIndex === pattern.length - 1 ||
|
|
41
|
+
Array.from(
|
|
42
|
+
{ length: trail.length - trailIndex + 1 },
|
|
43
|
+
(_, offset) => trailIndex + offset
|
|
44
|
+
).some((index) => matchSegments(trail, pattern, index, patternIndex + 1));
|
|
45
|
+
|
|
46
|
+
const matchesSingleSegment = (
|
|
47
|
+
trail: readonly string[],
|
|
48
|
+
pattern: readonly string[],
|
|
49
|
+
trailIndex: number,
|
|
50
|
+
patternIndex: number,
|
|
51
|
+
current: string,
|
|
52
|
+
matchSegments: SegmentMatcher
|
|
53
|
+
): boolean =>
|
|
54
|
+
trailIndex < trail.length &&
|
|
55
|
+
(current === '*' || current === trail[trailIndex]) &&
|
|
56
|
+
matchSegments(trail, pattern, trailIndex + 1, patternIndex + 1);
|
|
57
|
+
|
|
58
|
+
const matchesFrom = function matchesFrom(
|
|
59
|
+
trail: readonly string[],
|
|
60
|
+
pattern: readonly string[],
|
|
61
|
+
trailIndex: number,
|
|
62
|
+
patternIndex: number
|
|
63
|
+
): boolean {
|
|
64
|
+
if (patternIndex >= pattern.length) {
|
|
65
|
+
return trailIndex >= trail.length;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const current = pattern[patternIndex];
|
|
69
|
+
if (current === undefined) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return current === '**'
|
|
74
|
+
? matchesDoubleStar(trail, pattern, trailIndex, patternIndex, matchesFrom)
|
|
75
|
+
: matchesSingleSegment(
|
|
76
|
+
trail,
|
|
77
|
+
pattern,
|
|
78
|
+
trailIndex,
|
|
79
|
+
patternIndex,
|
|
80
|
+
current,
|
|
81
|
+
matchesFrom
|
|
82
|
+
);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export const matchesTrailPattern = (
|
|
86
|
+
trailId: string,
|
|
87
|
+
pattern: string
|
|
88
|
+
): boolean => {
|
|
89
|
+
if (pattern === trailId) {
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
return matchesFrom(trailIdSegments(trailId), patternSegments(pattern), 0, 0);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
// ---------------------------------------------------------------------------
|
|
96
|
+
// Trailhead filtering
|
|
97
|
+
// ---------------------------------------------------------------------------
|
|
98
|
+
|
|
99
|
+
const matchesAnyPattern = (
|
|
100
|
+
trailId: string,
|
|
101
|
+
patterns: readonly string[] | undefined
|
|
102
|
+
): boolean =>
|
|
103
|
+
patterns !== undefined &&
|
|
104
|
+
patterns.some((pattern) => matchesTrailPattern(trailId, pattern));
|
|
105
|
+
|
|
106
|
+
const isExplicitInternalInclude = (
|
|
107
|
+
trailId: string,
|
|
108
|
+
include: readonly string[] | undefined
|
|
109
|
+
): boolean => include !== undefined && include.includes(trailId);
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Resolve the effective visibility for a trail.
|
|
113
|
+
*
|
|
114
|
+
* Returns `'internal'` when either the explicit `visibility` field is
|
|
115
|
+
* `'internal'` or the legacy `meta.internal === true` convention is set.
|
|
116
|
+
* Honoring the legacy flag keeps trails authored before the visibility
|
|
117
|
+
* field was introduced (e.g. `meta: { internal: true }`) off trailheads.
|
|
118
|
+
*
|
|
119
|
+
* The runtime always fills in `visibility: 'public'` when the spec did not
|
|
120
|
+
* declare it, so we cannot distinguish explicit `'public'` from the default.
|
|
121
|
+
* This means a trail that sets both `meta.internal = true` and
|
|
122
|
+
* `visibility: 'public'` will still be treated as internal — that
|
|
123
|
+
* combination has never been a documented override and, if the author
|
|
124
|
+
* really means "public", they should remove the legacy flag.
|
|
125
|
+
*/
|
|
126
|
+
const effectiveVisibility = (
|
|
127
|
+
trail: Trail<unknown, unknown, unknown>
|
|
128
|
+
): 'public' | 'internal' => {
|
|
129
|
+
if (trail.visibility === 'internal') {
|
|
130
|
+
return 'internal';
|
|
131
|
+
}
|
|
132
|
+
return trail.meta?.['internal'] === true ? 'internal' : 'public';
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
const isVisibleToTrailheads = (
|
|
136
|
+
trail: Trail<unknown, unknown, unknown>,
|
|
137
|
+
include: readonly string[] | undefined
|
|
138
|
+
): boolean =>
|
|
139
|
+
effectiveVisibility(trail) !== 'internal' ||
|
|
140
|
+
isExplicitInternalInclude(trail.id, include);
|
|
141
|
+
|
|
142
|
+
const passesIncludeFilter = (
|
|
143
|
+
trailId: string,
|
|
144
|
+
include: readonly string[] | undefined
|
|
145
|
+
): boolean =>
|
|
146
|
+
include === undefined ||
|
|
147
|
+
include.length === 0 ||
|
|
148
|
+
matchesAnyPattern(trailId, include);
|
|
149
|
+
|
|
150
|
+
const passesIntentFilter = (
|
|
151
|
+
trail: Trail<unknown, unknown, unknown>,
|
|
152
|
+
intent: readonly Intent[] | undefined
|
|
153
|
+
): boolean =>
|
|
154
|
+
intent === undefined || intent.length === 0 || intent.includes(trail.intent);
|
|
155
|
+
|
|
156
|
+
export const shouldIncludeTrailForSurface = (
|
|
157
|
+
trail: Trail<unknown, unknown, unknown>,
|
|
158
|
+
options: SurfaceFilterOptions = {}
|
|
159
|
+
): boolean => {
|
|
160
|
+
if (trail.on.length > 0) {
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const { exclude, include, intent } = options;
|
|
165
|
+
if (!isVisibleToTrailheads(trail, include)) {
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (matchesAnyPattern(trail.id, exclude)) {
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return (
|
|
174
|
+
passesIncludeFilter(trail.id, include) && passesIntentFilter(trail, intent)
|
|
175
|
+
);
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
export const filterSurfaceTrails = (
|
|
179
|
+
trails: readonly Trail<unknown, unknown, unknown>[],
|
|
180
|
+
options: SurfaceFilterOptions = {}
|
|
181
|
+
): Trail<unknown, unknown, unknown>[] =>
|
|
182
|
+
trails.filter((trail) => shouldIncludeTrailForSurface(trail, options));
|