@ontrails/core 1.0.0-beta.3 → 1.0.0-beta.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +323 -8
- package/README.md +114 -33
- package/package.json +11 -1
- package/src/activation-provenance.ts +111 -0
- package/src/activation-source-compatibility.ts +430 -0
- package/src/activation-source-projection.ts +221 -0
- package/src/activation-source.ts +91 -0
- package/src/blob-ref.ts +51 -0
- package/src/branded.ts +1 -1
- package/src/compose-batch.ts +69 -0
- package/src/compose-schema.ts +36 -0
- package/src/context.ts +44 -10
- package/src/contour.ts +346 -0
- package/src/derive.ts +250 -19
- package/src/detours.ts +8 -0
- package/src/diagnostics.ts +21 -0
- package/src/draft.ts +350 -0
- package/src/error-projection.ts +51 -0
- package/src/errors.ts +335 -48
- package/src/execute.ts +1577 -0
- package/src/fire.ts +1169 -0
- package/src/glob.ts +81 -0
- package/src/index.ts +526 -35
- package/src/internal/fork-ctx.ts +69 -0
- package/src/layer-projection.ts +193 -0
- package/src/layer.ts +43 -6
- package/src/observe.ts +361 -0
- package/src/path-scope.ts +66 -0
- package/src/path-security.ts +1 -1
- package/src/permits.ts +12 -0
- package/src/redaction/patterns.ts +6 -3
- package/src/resilience.ts +11 -11
- package/src/resource-config.ts +792 -0
- package/src/resource.ts +194 -0
- package/src/result.ts +18 -0
- package/src/run.ts +76 -0
- package/src/schedule-runtime.ts +689 -0
- package/src/schedule.ts +326 -0
- package/src/serialization.ts +92 -55
- package/src/signal-diagnostics.ts +633 -0
- package/src/signal-ref.ts +87 -0
- package/src/signal.ts +104 -0
- package/src/store/accessor-protocol.ts +56 -0
- package/src/store/index.ts +4 -0
- package/src/structured-examples.ts +248 -0
- package/src/surface-derivation.ts +91 -0
- package/src/surface-filter.ts +101 -0
- package/src/surface-versioning.ts +42 -0
- package/src/topo.ts +769 -67
- package/src/tracing.ts +345 -0
- package/src/trail-id-glob.ts +15 -0
- package/src/trail.ts +1168 -30
- package/src/trails/derive-trail.ts +842 -0
- package/src/trails/index.ts +9 -0
- package/src/trails/ingest.ts +139 -0
- package/src/trails-db.ts +206 -0
- package/src/transport-error-map.ts +174 -0
- package/src/type-utils.ts +87 -0
- package/src/types.ts +254 -12
- package/src/validate-established-topo.ts +69 -0
- package/src/validate-topo.ts +414 -56
- package/src/validation.ts +152 -4
- package/src/version-marker.ts +716 -0
- package/src/version-resolution.ts +308 -0
- package/src/version-runtime.ts +120 -0
- package/src/webhook.ts +278 -0
- package/src/workspace.ts +162 -1
- package/src/zod-wrappers.ts +72 -0
- package/.turbo/turbo-build.log +0 -1
- package/.turbo/turbo-lint.log +0 -3
- package/.turbo/turbo-typecheck.log +0 -1
- package/dist/adapters.d.ts +0 -39
- package/dist/adapters.d.ts.map +0 -1
- package/dist/adapters.js +0 -2
- package/dist/adapters.js.map +0 -1
- package/dist/blob-ref.d.ts +0 -20
- package/dist/blob-ref.d.ts.map +0 -1
- package/dist/blob-ref.js +0 -22
- package/dist/blob-ref.js.map +0 -1
- package/dist/branded.d.ts +0 -36
- package/dist/branded.d.ts.map +0 -1
- package/dist/branded.js +0 -89
- package/dist/branded.js.map +0 -1
- package/dist/collections.d.ts +0 -31
- package/dist/collections.d.ts.map +0 -1
- package/dist/collections.js +0 -60
- package/dist/collections.js.map +0 -1
- package/dist/context.d.ts +0 -10
- package/dist/context.d.ts.map +0 -1
- package/dist/context.js +0 -15
- package/dist/context.js.map +0 -1
- package/dist/derive.d.ts +0 -33
- package/dist/derive.d.ts.map +0 -1
- package/dist/derive.js +0 -125
- package/dist/derive.js.map +0 -1
- package/dist/errors.d.ts +0 -83
- package/dist/errors.d.ts.map +0 -1
- package/dist/errors.js +0 -142
- package/dist/errors.js.map +0 -1
- package/dist/event.d.ts +0 -45
- package/dist/event.d.ts.map +0 -1
- package/dist/event.js +0 -17
- package/dist/event.js.map +0 -1
- package/dist/fetch.d.ts +0 -15
- package/dist/fetch.d.ts.map +0 -1
- package/dist/fetch.js +0 -102
- package/dist/fetch.js.map +0 -1
- package/dist/guards.d.ts +0 -17
- package/dist/guards.d.ts.map +0 -1
- package/dist/guards.js +0 -25
- package/dist/guards.js.map +0 -1
- package/dist/health.d.ts +0 -18
- package/dist/health.d.ts.map +0 -1
- package/dist/health.js +0 -5
- package/dist/health.js.map +0 -1
- package/dist/hike.d.ts +0 -36
- package/dist/hike.d.ts.map +0 -1
- package/dist/hike.js +0 -20
- package/dist/hike.js.map +0 -1
- package/dist/index.d.ts +0 -36
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -40
- package/dist/index.js.map +0 -1
- package/dist/job.d.ts +0 -24
- package/dist/job.d.ts.map +0 -1
- package/dist/job.js +0 -17
- package/dist/job.js.map +0 -1
- package/dist/layer.d.ts +0 -17
- package/dist/layer.d.ts.map +0 -1
- package/dist/layer.js +0 -21
- package/dist/layer.js.map +0 -1
- package/dist/path-security.d.ts +0 -28
- package/dist/path-security.d.ts.map +0 -1
- package/dist/path-security.js +0 -63
- package/dist/path-security.js.map +0 -1
- package/dist/patterns/bulk.d.ts +0 -15
- package/dist/patterns/bulk.d.ts.map +0 -1
- package/dist/patterns/bulk.js +0 -14
- package/dist/patterns/bulk.js.map +0 -1
- package/dist/patterns/change.d.ts +0 -10
- package/dist/patterns/change.d.ts.map +0 -1
- package/dist/patterns/change.js +0 -10
- package/dist/patterns/change.js.map +0 -1
- package/dist/patterns/date-range.d.ts +0 -10
- package/dist/patterns/date-range.d.ts.map +0 -1
- package/dist/patterns/date-range.js +0 -10
- package/dist/patterns/date-range.js.map +0 -1
- package/dist/patterns/index.d.ts +0 -9
- package/dist/patterns/index.d.ts.map +0 -1
- package/dist/patterns/index.js +0 -9
- package/dist/patterns/index.js.map +0 -1
- package/dist/patterns/pagination.d.ts +0 -18
- package/dist/patterns/pagination.d.ts.map +0 -1
- package/dist/patterns/pagination.js +0 -18
- package/dist/patterns/pagination.js.map +0 -1
- package/dist/patterns/progress.d.ts +0 -11
- package/dist/patterns/progress.d.ts.map +0 -1
- package/dist/patterns/progress.js +0 -11
- package/dist/patterns/progress.js.map +0 -1
- package/dist/patterns/sorting.d.ts +0 -13
- package/dist/patterns/sorting.d.ts.map +0 -1
- package/dist/patterns/sorting.js +0 -10
- package/dist/patterns/sorting.js.map +0 -1
- package/dist/patterns/status.d.ts +0 -15
- package/dist/patterns/status.d.ts.map +0 -1
- package/dist/patterns/status.js +0 -9
- package/dist/patterns/status.js.map +0 -1
- package/dist/patterns/timestamps.d.ts +0 -10
- package/dist/patterns/timestamps.d.ts.map +0 -1
- package/dist/patterns/timestamps.js +0 -10
- package/dist/patterns/timestamps.js.map +0 -1
- package/dist/redaction/index.d.ts +0 -4
- package/dist/redaction/index.d.ts.map +0 -1
- package/dist/redaction/index.js +0 -3
- package/dist/redaction/index.js.map +0 -1
- package/dist/redaction/patterns.d.ts +0 -9
- package/dist/redaction/patterns.d.ts.map +0 -1
- package/dist/redaction/patterns.js +0 -39
- package/dist/redaction/patterns.js.map +0 -1
- package/dist/redaction/redactor.d.ts +0 -27
- package/dist/redaction/redactor.d.ts.map +0 -1
- package/dist/redaction/redactor.js +0 -89
- package/dist/redaction/redactor.js.map +0 -1
- package/dist/resilience.d.ts +0 -34
- package/dist/resilience.d.ts.map +0 -1
- package/dist/resilience.js +0 -164
- package/dist/resilience.js.map +0 -1
- package/dist/result.d.ts +0 -57
- package/dist/result.d.ts.map +0 -1
- package/dist/result.js +0 -156
- package/dist/result.js.map +0 -1
- package/dist/serialization.d.ts +0 -27
- package/dist/serialization.d.ts.map +0 -1
- package/dist/serialization.js +0 -153
- package/dist/serialization.js.map +0 -1
- package/dist/topo.d.ts +0 -18
- package/dist/topo.d.ts.map +0 -1
- package/dist/topo.js +0 -80
- package/dist/topo.js.map +0 -1
- package/dist/trail.d.ts +0 -83
- package/dist/trail.d.ts.map +0 -1
- package/dist/trail.js +0 -16
- package/dist/trail.js.map +0 -1
- package/dist/types.d.ts +0 -46
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
- package/dist/validate-topo.d.ts +0 -24
- package/dist/validate-topo.d.ts.map +0 -1
- package/dist/validate-topo.js +0 -156
- package/dist/validate-topo.js.map +0 -1
- package/dist/validation.d.ts +0 -27
- package/dist/validation.d.ts.map +0 -1
- package/dist/validation.js +0 -134
- package/dist/validation.js.map +0 -1
- package/dist/workspace.d.ts +0 -25
- package/dist/workspace.d.ts.map +0 -1
- package/dist/workspace.js +0 -57
- package/dist/workspace.js.map +0 -1
- package/src/__tests__/blob-ref.test.ts +0 -103
- package/src/__tests__/branded.test.ts +0 -148
- package/src/__tests__/collections.test.ts +0 -126
- package/src/__tests__/context.test.ts +0 -66
- package/src/__tests__/derive.test.ts +0 -203
- package/src/__tests__/errors.test.ts +0 -309
- package/src/__tests__/event.test.ts +0 -82
- package/src/__tests__/fetch.test.ts +0 -217
- package/src/__tests__/guards.test.ts +0 -102
- package/src/__tests__/hike.test.ts +0 -117
- package/src/__tests__/job.test.ts +0 -98
- package/src/__tests__/layer.test.ts +0 -224
- package/src/__tests__/path-security.test.ts +0 -114
- package/src/__tests__/patterns.test.ts +0 -273
- package/src/__tests__/redaction.test.ts +0 -244
- package/src/__tests__/resilience.test.ts +0 -246
- package/src/__tests__/result.test.ts +0 -155
- package/src/__tests__/serialization.test.ts +0 -401
- package/src/__tests__/topo.test.ts +0 -220
- package/src/__tests__/trail.test.ts +0 -179
- package/src/__tests__/validate-topo.test.ts +0 -280
- package/src/__tests__/validation.test.ts +0 -283
- package/src/__tests__/workspace.test.ts +0 -183
- package/src/adapters.ts +0 -68
- package/src/event.ts +0 -77
- package/src/health.ts +0 -23
- package/src/hike.ts +0 -77
- package/src/job.ts +0 -20
- package/tsconfig.json +0 -9
- package/tsconfig.tsbuildinfo +0 -1
package/src/workspace.ts
CHANGED
|
@@ -5,11 +5,46 @@
|
|
|
5
5
|
* helpers for working with paths relative to a workspace.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
import { existsSync, readFileSync, readdirSync, realpathSync } from 'node:fs';
|
|
8
9
|
import { resolve, relative, dirname, join, isAbsolute } from 'node:path';
|
|
9
10
|
|
|
10
11
|
import { NotFoundError } from './errors.js';
|
|
11
12
|
import { Result } from './result.js';
|
|
12
13
|
|
|
14
|
+
export interface WorkspaceRootManifest {
|
|
15
|
+
readonly workspaces?: unknown;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface WorkspacePackage<
|
|
19
|
+
Manifest extends object = Record<string, unknown>,
|
|
20
|
+
> {
|
|
21
|
+
readonly manifest: Manifest;
|
|
22
|
+
readonly packageJsonPath: string;
|
|
23
|
+
readonly packageRoot: string;
|
|
24
|
+
readonly workspacePath: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const isRecord = (value: unknown): value is Readonly<Record<string, unknown>> =>
|
|
28
|
+
typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
29
|
+
|
|
30
|
+
const normalizePath = (path: string): string => path.replaceAll('\\', '/');
|
|
31
|
+
|
|
32
|
+
const normalizeRealPath = (path: string): string => {
|
|
33
|
+
try {
|
|
34
|
+
return normalizePath(realpathSync(path));
|
|
35
|
+
} catch {
|
|
36
|
+
return normalizePath(resolve(path));
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const readJsonSync = <T>(path: string): T | undefined => {
|
|
41
|
+
try {
|
|
42
|
+
return JSON.parse(readFileSync(path, 'utf8')) as T;
|
|
43
|
+
} catch {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
13
48
|
/** Check if a directory has a package.json with a `workspaces` field. */
|
|
14
49
|
const hasWorkspacesField = async (dir: string): Promise<boolean> => {
|
|
15
50
|
const pkgPath = join(dir, 'package.json');
|
|
@@ -25,6 +60,132 @@ const hasWorkspacesField = async (dir: string): Promise<boolean> => {
|
|
|
25
60
|
}
|
|
26
61
|
};
|
|
27
62
|
|
|
63
|
+
/**
|
|
64
|
+
* List workspace patterns from a root package manifest.
|
|
65
|
+
*
|
|
66
|
+
* Supports npm/Bun's array form and Yarn-style `{ packages: [] }` form.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* listWorkspacePatterns({ workspaces: ['packages/*'] });
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export const listWorkspacePatterns = (
|
|
74
|
+
manifest: WorkspaceRootManifest | undefined
|
|
75
|
+
): readonly string[] => {
|
|
76
|
+
const { workspaces } = manifest ?? {};
|
|
77
|
+
if (Array.isArray(workspaces)) {
|
|
78
|
+
return workspaces.filter(
|
|
79
|
+
(pattern): pattern is string => typeof pattern === 'string'
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const packages = isRecord(workspaces) ? workspaces['packages'] : undefined;
|
|
84
|
+
return Array.isArray(packages)
|
|
85
|
+
? packages.filter(
|
|
86
|
+
(pattern): pattern is string => typeof pattern === 'string'
|
|
87
|
+
)
|
|
88
|
+
: [];
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const workspaceDirsForPattern = (
|
|
92
|
+
rootDir: string,
|
|
93
|
+
pattern: string
|
|
94
|
+
): readonly string[] => {
|
|
95
|
+
if (!pattern.endsWith('/*')) {
|
|
96
|
+
const workspaceDir = join(rootDir, pattern);
|
|
97
|
+
return existsSync(join(workspaceDir, 'package.json')) ? [workspaceDir] : [];
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const groupDir = join(rootDir, pattern.slice(0, -2));
|
|
101
|
+
if (!existsSync(groupDir)) {
|
|
102
|
+
return [];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return readdirSync(groupDir, { withFileTypes: true })
|
|
106
|
+
.filter((entry) => entry.isDirectory())
|
|
107
|
+
.map((entry) => join(groupDir, entry.name))
|
|
108
|
+
.filter((workspaceDir) => existsSync(join(workspaceDir, 'package.json')))
|
|
109
|
+
.toSorted();
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* List package directories matched by workspace patterns.
|
|
114
|
+
*
|
|
115
|
+
* Only directories containing `package.json` are returned.
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```ts
|
|
119
|
+
* listWorkspacePackageDirs('/repo', ['packages/*']);
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
export const listWorkspacePackageDirs = (
|
|
123
|
+
rootDir: string,
|
|
124
|
+
patterns: readonly string[]
|
|
125
|
+
): readonly string[] =>
|
|
126
|
+
patterns.flatMap((pattern) => workspaceDirsForPattern(rootDir, pattern));
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* List workspace package manifests from a workspace root.
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```ts
|
|
133
|
+
* const packages = listWorkspacePackages('/repo');
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
export const listWorkspacePackages = <
|
|
137
|
+
Manifest extends { readonly name?: unknown } = { readonly name?: unknown },
|
|
138
|
+
>(
|
|
139
|
+
rootDir: string
|
|
140
|
+
): readonly WorkspacePackage<Manifest>[] => {
|
|
141
|
+
const normalizedRoot = normalizeRealPath(rootDir);
|
|
142
|
+
const rootManifest = readJsonSync<WorkspaceRootManifest>(
|
|
143
|
+
join(normalizedRoot, 'package.json')
|
|
144
|
+
);
|
|
145
|
+
const packages: WorkspacePackage<Manifest>[] = [];
|
|
146
|
+
|
|
147
|
+
for (const workspaceDir of listWorkspacePackageDirs(
|
|
148
|
+
normalizedRoot,
|
|
149
|
+
listWorkspacePatterns(rootManifest)
|
|
150
|
+
)) {
|
|
151
|
+
const packageJsonPath = join(workspaceDir, 'package.json');
|
|
152
|
+
const manifest = readJsonSync<Manifest>(packageJsonPath);
|
|
153
|
+
if (!manifest || typeof manifest.name !== 'string') {
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const packageRoot = normalizeRealPath(dirname(packageJsonPath));
|
|
158
|
+
packages.push({
|
|
159
|
+
manifest,
|
|
160
|
+
packageJsonPath: normalizeRealPath(packageJsonPath),
|
|
161
|
+
packageRoot,
|
|
162
|
+
workspacePath: normalizePath(relative(normalizedRoot, packageRoot)),
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return packages.toSorted((left, right) =>
|
|
167
|
+
left.workspacePath.localeCompare(right.workspacePath)
|
|
168
|
+
);
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Find a workspace package by its package name.
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```ts
|
|
176
|
+
* const workspace = findWorkspacePackage('/repo', '@ontrails/core');
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
export const findWorkspacePackage = <
|
|
180
|
+
Manifest extends { readonly name?: unknown } = { readonly name?: unknown },
|
|
181
|
+
>(
|
|
182
|
+
rootDir: string,
|
|
183
|
+
packageName: string
|
|
184
|
+
): WorkspacePackage<Manifest> | undefined =>
|
|
185
|
+
listWorkspacePackages<Manifest>(rootDir).find(
|
|
186
|
+
(workspacePackage) => workspacePackage.manifest.name === packageName
|
|
187
|
+
);
|
|
188
|
+
|
|
28
189
|
/**
|
|
29
190
|
* Walks up from `startDir` (defaults to `process.cwd()`) looking for a
|
|
30
191
|
* `package.json` that contains a `"workspaces"` field.
|
|
@@ -71,7 +232,7 @@ export const isInsideWorkspace = (
|
|
|
71
232
|
/**
|
|
72
233
|
* Returns the relative path from `workspaceRoot` to `filePath`.
|
|
73
234
|
*/
|
|
74
|
-
export const
|
|
235
|
+
export const deriveRelativePath = (
|
|
75
236
|
filePath: string,
|
|
76
237
|
workspaceRoot: string
|
|
77
238
|
): string => relative(resolve(workspaceRoot), resolve(filePath));
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared Zod wrapper helpers.
|
|
3
|
+
*
|
|
4
|
+
* These helpers walk the wrapper layers of a Zod schema (default, optional,
|
|
5
|
+
* nullable) and rebuild the schema without any default wrappers so that
|
|
6
|
+
* downstream `.partial()` calls do not silently re-materialize defaults during
|
|
7
|
+
* validation. Both `@ontrails/core/trails/derive-trail.ts` and
|
|
8
|
+
* `@ontrails/store/src/store.ts` previously shipped near-identical copies of
|
|
9
|
+
* this walk — extracting them here keeps the wrapper semantics authored in one
|
|
10
|
+
* place so the two call sites cannot drift.
|
|
11
|
+
*
|
|
12
|
+
* Canonical behavior: `optional` wrappers are intentionally dropped. Every
|
|
13
|
+
* current call site applies `.partial()` to the stripped schema, which
|
|
14
|
+
* re-introduces `optional` across the whole shape. Preserving `optional` here
|
|
15
|
+
* would be redundant at best and would produce an `OptionalOptional<T>` shape
|
|
16
|
+
* in edge cases at worst. `nullable` wrappers are preserved because nullability
|
|
17
|
+
* is a semantic constraint that `.partial()` does not reintroduce.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import type { z } from 'zod';
|
|
21
|
+
|
|
22
|
+
const isWrapperType = (
|
|
23
|
+
type: string
|
|
24
|
+
): type is 'default' | 'nullable' | 'optional' =>
|
|
25
|
+
type === 'default' || type === 'nullable' || type === 'optional';
|
|
26
|
+
|
|
27
|
+
const readInnerType = (schema: z.ZodType): z.ZodType =>
|
|
28
|
+
(schema.def as unknown as { innerType: z.ZodType }).innerType;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Strip `default` wrappers from a Zod type so that partial update schemas do
|
|
32
|
+
* not silently re-materialize defaults. Walks through all wrapper layers
|
|
33
|
+
* (`default`, `optional`, `nullable`), drops defaults, drops `optional` (the
|
|
34
|
+
* downstream `.partial()` reintroduces it across the whole shape), and
|
|
35
|
+
* preserves `nullable` so explicit nullability survives.
|
|
36
|
+
*/
|
|
37
|
+
export const stripDefaultWrappers = (schema: z.ZodType): z.ZodType => {
|
|
38
|
+
let current = schema;
|
|
39
|
+
let isNullable = false;
|
|
40
|
+
|
|
41
|
+
while (isWrapperType(current.def.type)) {
|
|
42
|
+
if (current.def.type === 'nullable') {
|
|
43
|
+
isNullable = true;
|
|
44
|
+
}
|
|
45
|
+
current = readInnerType(current);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return isNullable ? current.nullable() : current;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
type AnyObjectSchema = z.ZodObject<Record<string, z.ZodType>>;
|
|
52
|
+
|
|
53
|
+
const asObjectSchema = (schema: z.ZodType): AnyObjectSchema =>
|
|
54
|
+
schema as unknown as AnyObjectSchema;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Apply {@link stripDefaultWrappers} to every field in a Zod object shape and
|
|
58
|
+
* return the resulting shape record. Callers typically feed the result to
|
|
59
|
+
* `.extend()` + `.partial()`.
|
|
60
|
+
*/
|
|
61
|
+
export const stripDefaultsFromShape = (
|
|
62
|
+
schema: z.ZodType
|
|
63
|
+
): Record<string, z.ZodType> => {
|
|
64
|
+
const stripped: Record<string, z.ZodType> = {};
|
|
65
|
+
const objectSchema = asObjectSchema(schema);
|
|
66
|
+
|
|
67
|
+
for (const [field, value] of Object.entries(objectSchema.shape)) {
|
|
68
|
+
stripped[field] = stripDefaultWrappers(value);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return stripped;
|
|
72
|
+
};
|
package/.turbo/turbo-build.log
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
$ tsc -b
|
package/.turbo/turbo-lint.log
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
$ tsc --noEmit
|
package/dist/adapters.d.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import type { Result } from './result.js';
|
|
2
|
-
/** Options for search queries */
|
|
3
|
-
export interface SearchOptions {
|
|
4
|
-
readonly limit?: number | undefined;
|
|
5
|
-
readonly offset?: number | undefined;
|
|
6
|
-
readonly filters?: Readonly<Record<string, unknown>> | undefined;
|
|
7
|
-
}
|
|
8
|
-
/** A single search hit */
|
|
9
|
-
export interface SearchResult {
|
|
10
|
-
readonly id: string;
|
|
11
|
-
readonly score: number;
|
|
12
|
-
readonly document: Readonly<Record<string, unknown>>;
|
|
13
|
-
}
|
|
14
|
-
/** Options for storage writes */
|
|
15
|
-
export interface StorageOptions {
|
|
16
|
-
/** Time-to-live in milliseconds */
|
|
17
|
-
readonly ttl?: number | undefined;
|
|
18
|
-
}
|
|
19
|
-
/** Full-text / vector index adapter */
|
|
20
|
-
export interface IndexAdapter {
|
|
21
|
-
index(id: string, document: Readonly<Record<string, unknown>>): Promise<Result<void, Error>>;
|
|
22
|
-
search(query: string, options?: SearchOptions): Promise<Result<readonly SearchResult[], Error>>;
|
|
23
|
-
remove(id: string): Promise<Result<void, Error>>;
|
|
24
|
-
}
|
|
25
|
-
/** Key-value storage adapter */
|
|
26
|
-
export interface StorageAdapter {
|
|
27
|
-
get(key: string): Promise<Result<unknown, Error>>;
|
|
28
|
-
set(key: string, value: unknown, options?: StorageOptions): Promise<Result<void, Error>>;
|
|
29
|
-
delete(key: string): Promise<Result<void, Error>>;
|
|
30
|
-
has(key: string): Promise<Result<boolean, Error>>;
|
|
31
|
-
}
|
|
32
|
-
/** Cache adapter with typed get/set and bulk clear */
|
|
33
|
-
export interface CacheAdapter {
|
|
34
|
-
get<T>(key: string): Promise<Result<T | undefined, Error>>;
|
|
35
|
-
set<T>(key: string, value: T, options?: StorageOptions): Promise<Result<void, Error>>;
|
|
36
|
-
delete(key: string): Promise<Result<void, Error>>;
|
|
37
|
-
clear(): Promise<Result<void, Error>>;
|
|
38
|
-
}
|
|
39
|
-
//# sourceMappingURL=adapters.d.ts.map
|
package/dist/adapters.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"adapters.d.ts","sourceRoot":"","sources":["../src/adapters.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAM1C,iCAAiC;AACjC,MAAM,WAAW,aAAa;IAC5B,QAAQ,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E,OAAO,EACd,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;IAChC,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;IAClD,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC;CACnD;AAED,sDAAsD;AACtD,MAAM,WAAW,YAAY;IAC3B,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC;IAC3D,GAAG,CAAC,CAAC,EACH,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,CAAC,EACR,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;IAChC,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;IAClD,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;CACvC"}
|
package/dist/adapters.js
DELETED
package/dist/adapters.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"adapters.js","sourceRoot":"","sources":["../src/adapters.ts"],"names":[],"mappings":""}
|
package/dist/blob-ref.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* BlobRef — a frozen reference to binary data for @ontrails/core.
|
|
3
|
-
*/
|
|
4
|
-
/** Immutable reference to a blob of binary data. */
|
|
5
|
-
export interface BlobRef {
|
|
6
|
-
readonly name: string;
|
|
7
|
-
readonly mimeType: string;
|
|
8
|
-
readonly size: number;
|
|
9
|
-
readonly data: Uint8Array | ReadableStream<Uint8Array>;
|
|
10
|
-
}
|
|
11
|
-
/** Creates a frozen BlobRef. */
|
|
12
|
-
export declare const createBlobRef: (options: {
|
|
13
|
-
name: string;
|
|
14
|
-
mimeType: string;
|
|
15
|
-
size: number;
|
|
16
|
-
data: Uint8Array | ReadableStream<Uint8Array>;
|
|
17
|
-
}) => BlobRef;
|
|
18
|
-
/** Type guard for BlobRef-shaped values. */
|
|
19
|
-
export declare const isBlobRef: (value: unknown) => value is BlobRef;
|
|
20
|
-
//# sourceMappingURL=blob-ref.d.ts.map
|
package/dist/blob-ref.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"blob-ref.d.ts","sourceRoot":"","sources":["../src/blob-ref.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,oDAAoD;AACpD,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,UAAU,GAAG,cAAc,CAAC,UAAU,CAAC,CAAC;CACxD;AAED,gCAAgC;AAChC,eAAO,MAAM,aAAa,GAAI,SAAS;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,UAAU,GAAG,cAAc,CAAC,UAAU,CAAC,CAAC;CAC/C,KAAG,OAMA,CAAC;AAEL,4CAA4C;AAC5C,eAAO,MAAM,SAAS,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,OAWnD,CAAC"}
|
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 hashId: (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,MAAM,GAAI,OAAO,MAAM,KAAG,MAYtC,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 hashId = (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,s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AC,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;AAC7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AI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,CAAC,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC;QACpB,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAEF,qEAAqE;AACrE,MAAM,CAAC,MAAM,MAAM,GAAG,CACpB,KAAmB,EACnB,GAAiC,EAC5B,EAAE,CACP,CAAC,GAAG,KAAK,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;IAC3B,MAAM,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;IAClB,MAAM,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;IAClB,IAAI,OAAO,EAAE,KAAK,QAAQ,IAAI,OAAO,EAAE,KAAK,QAAQ,EAAE,CAAC;QACrD,OAAO,EAAE,GAAG,EAAE,CAAC;IACjB,CAAC;IACD,OAAO,MAAM,CAAC,EAAE,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;AAC9C,CAAC,CAAC,CAAC"}
|
package/dist/context.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { TrailContext } from './types.js';
|
|
2
|
-
/**
|
|
3
|
-
* Create a TrailContext with sensible defaults.
|
|
4
|
-
*
|
|
5
|
-
* - `requestId` defaults to `Bun.randomUUIDv7()` (sortable v7 UUID)
|
|
6
|
-
* - `signal` defaults to a fresh, non-aborted `AbortSignal`
|
|
7
|
-
* - All other fields come from `overrides`
|
|
8
|
-
*/
|
|
9
|
-
export declare const createTrailContext: (overrides?: Partial<TrailContext>) => TrailContext;
|
|
10
|
-
//# 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":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,GAC7B,YAAY,OAAO,CAAC,YAAY,CAAC,KAChC,YAMD,CAAC"}
|
package/dist/context.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Create a TrailContext with sensible defaults.
|
|
3
|
-
*
|
|
4
|
-
* - `requestId` defaults to `Bun.randomUUIDv7()` (sortable v7 UUID)
|
|
5
|
-
* - `signal` defaults to a fresh, non-aborted `AbortSignal`
|
|
6
|
-
* - All other fields come from `overrides`
|
|
7
|
-
*/
|
|
8
|
-
export const createTrailContext = (overrides) => ({
|
|
9
|
-
cwd: process.cwd(),
|
|
10
|
-
env: process.env,
|
|
11
|
-
requestId: Bun.randomUUIDv7(),
|
|
12
|
-
signal: new AbortController().signal,
|
|
13
|
-
...overrides,
|
|
14
|
-
});
|
|
15
|
-
//# 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":"AAEA;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,SAAiC,EACnB,EAAE,CAAC,CAAC;IAClB,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE;IAClB,GAAG,EAAE,OAAO,CAAC,GAAyC;IACtD,SAAS,EAAE,GAAG,CAAC,YAAY,EAAE;IAC7B,MAAM,EAAE,IAAI,eAAe,EAAE,CAAC,MAAM;IACpC,GAAG,SAAS;CACb,CAAC,CAAC"}
|