@ontrails/core 1.0.0-beta.11 → 1.0.0-beta.12
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 +13 -0
- package/dist/execute.d.ts +2 -0
- package/dist/execute.d.ts.map +1 -1
- package/dist/execute.js +2 -126
- package/dist/execute.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/service-config.d.ts +22 -0
- package/dist/service-config.d.ts.map +1 -0
- package/dist/service-config.js +208 -0
- package/dist/service-config.js.map +1 -0
- package/dist/service.d.ts +12 -6
- package/dist/service.d.ts.map +1 -1
- package/dist/service.js.map +1 -1
- package/dist/trail.d.ts +3 -1
- package/dist/trail.d.ts.map +1 -1
- package/dist/trail.js.map +1 -1
- package/dist/types.d.ts +18 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +2 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/service-config.test.ts +224 -0
- package/src/__tests__/trail-permit.test.ts +60 -0
- package/src/execute.ts +12 -207
- package/src/index.ts +3 -0
- package/src/service-config.ts +354 -0
- package/src/service.ts +13 -7
- package/src/trail.ts +7 -1
- package/src/types.ts +21 -1
- package/tsconfig.tsbuildinfo +1 -1
package/.turbo/turbo-lint.log
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @ontrails/core
|
|
2
2
|
|
|
3
|
+
## 1.0.0-beta.12
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Complete trifecta for config, permits, and crumbs (formerly tracks)
|
|
8
|
+
|
|
9
|
+
- **config**: Add `configService`, `config.layer`, `config.trail`, and `config.workspace` trails with full `defineConfig`, `resolve`, `describe`, `explain`, `doctor`, and code generation support
|
|
10
|
+
- **permits**: Add `authService` and `auth.verify` trail for runtime authorization checks
|
|
11
|
+
- **crumbs**: Rename tracks to crumbs; add `crumbsService` and `crumbs.status` trail for structured event tracking
|
|
12
|
+
- **cli**: Fix build flag handling and improve bootstrap scaffolding
|
|
13
|
+
- **testing**: Expand test context helpers and example-based testing utilities
|
|
14
|
+
- **core/mcp/http**: Internal alignment for service and composition updates
|
|
15
|
+
|
|
3
16
|
## 1.0.0-beta.11
|
|
4
17
|
|
|
5
18
|
### Minor Changes
|
package/dist/execute.d.ts
CHANGED
|
@@ -22,6 +22,8 @@ export interface ExecuteTrailOptions {
|
|
|
22
22
|
readonly createContext?: (() => TrailContextInit | Promise<TrailContextInit>) | undefined;
|
|
23
23
|
/** Explicit service instance overrides keyed by service ID. */
|
|
24
24
|
readonly services?: ServiceOverrideMap | undefined;
|
|
25
|
+
/** Config values for services that declare a `config` schema, keyed by service ID. */
|
|
26
|
+
readonly configValues?: Readonly<Record<string, Record<string, unknown>>> | undefined;
|
|
25
27
|
}
|
|
26
28
|
/**
|
|
27
29
|
* Execute a trail through the standard validate-context-layers-run pipeline.
|
package/dist/execute.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../src/execute.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../src/execute.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,KAAK,EAAgB,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAKjE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAarC,gCAAgC;AAChC,MAAM,WAAW,mBAAmB;IAClC,mEAAmE;IACnE,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,GAAG,SAAS,CAAC;IACrD,0EAA0E;IAC1E,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC;IAC1C,mDAAmD;IACnD,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,KAAK,EAAE,GAAG,SAAS,CAAC;IAC/C,kFAAkF;IAClF,QAAQ,CAAC,aAAa,CAAC,EACnB,CAAC,MAAM,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC,GACpD,SAAS,CAAC;IACd,+DAA+D;IAC/D,QAAQ,CAAC,QAAQ,CAAC,EAAE,kBAAkB,GAAG,SAAS,CAAC;IACnD,sFAAsF;IACtF,QAAQ,CAAC,YAAY,CAAC,EAClB,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,GACjD,SAAS,CAAC;CACf;AAsED;;;;;GAKG;AACH,eAAO,MAAM,YAAY,GACvB,OAAO,QAAQ,EACf,UAAU,OAAO,EACjB,UAAU,mBAAmB,KAC5B,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,CAsBhC,CAAC"}
|
package/dist/execute.js
CHANGED
|
@@ -10,6 +10,7 @@ import { createTrailContext } from './context.js';
|
|
|
10
10
|
import { InternalError } from './errors.js';
|
|
11
11
|
import { Result } from './result.js';
|
|
12
12
|
import { createServiceLookup } from './service.js';
|
|
13
|
+
import { resolveServices } from './service-config.js';
|
|
13
14
|
import { validateInput } from './validation.js';
|
|
14
15
|
// ---------------------------------------------------------------------------
|
|
15
16
|
// Context resolution
|
|
@@ -45,134 +46,9 @@ const resolveContext = async (options) => {
|
|
|
45
46
|
}
|
|
46
47
|
return resolved;
|
|
47
48
|
};
|
|
48
|
-
const singletonServices = new WeakMap();
|
|
49
|
-
/** In-flight service creation promises, keyed by service × context. */
|
|
50
|
-
const pendingCreations = new WeakMap();
|
|
51
|
-
const hasOwnServiceOverride = (overrides, id) => overrides !== undefined && Object.hasOwn(overrides, id);
|
|
52
|
-
const toServiceContext = (ctx) => ({
|
|
53
|
-
cwd: ctx.cwd,
|
|
54
|
-
env: ctx.env,
|
|
55
|
-
workspaceRoot: ctx.workspaceRoot,
|
|
56
|
-
});
|
|
57
|
-
const toServiceContextKey = (ctx) => JSON.stringify({
|
|
58
|
-
cwd: ctx.cwd,
|
|
59
|
-
env: Object.entries(ctx.env ?? {}).toSorted(([left], [right]) => left.localeCompare(right)),
|
|
60
|
-
workspaceRoot: ctx.workspaceRoot,
|
|
61
|
-
});
|
|
62
|
-
const toInternalServiceError = (id, error) => {
|
|
63
|
-
const cause = error instanceof Error ? error : undefined;
|
|
64
|
-
const message = cause?.message ?? String(error);
|
|
65
|
-
return new InternalError(`Service "${id}" failed to resolve: ${message}`, {
|
|
66
|
-
...(cause ? { cause } : {}),
|
|
67
|
-
context: { serviceId: id },
|
|
68
|
-
});
|
|
69
|
-
};
|
|
70
|
-
const getCachedSingletonService = (declaredService, serviceContext) => {
|
|
71
|
-
const scopedCache = singletonServices.get(declaredService);
|
|
72
|
-
if (scopedCache === undefined) {
|
|
73
|
-
return { found: false, value: undefined };
|
|
74
|
-
}
|
|
75
|
-
const key = toServiceContextKey(serviceContext);
|
|
76
|
-
if (!scopedCache.has(key)) {
|
|
77
|
-
return { found: false, value: undefined };
|
|
78
|
-
}
|
|
79
|
-
return {
|
|
80
|
-
found: true,
|
|
81
|
-
value: scopedCache.get(key),
|
|
82
|
-
};
|
|
83
|
-
};
|
|
84
|
-
const getProvidedService = (ctx, overrides, declaredService, serviceContext) => {
|
|
85
|
-
const { id } = declaredService;
|
|
86
|
-
if (hasOwnServiceOverride(overrides, id)) {
|
|
87
|
-
return Result.ok(overrides[id]);
|
|
88
|
-
}
|
|
89
|
-
if (Object.hasOwn(ctx.extensions ?? {}, id)) {
|
|
90
|
-
return Result.ok(ctx.extensions?.[id]);
|
|
91
|
-
}
|
|
92
|
-
const cached = getCachedSingletonService(declaredService, serviceContext);
|
|
93
|
-
if (cached.found) {
|
|
94
|
-
return Result.ok(cached.value);
|
|
95
|
-
}
|
|
96
|
-
return undefined;
|
|
97
|
-
};
|
|
98
|
-
const getSingletonServiceCache = (declaredService) => {
|
|
99
|
-
const existing = singletonServices.get(declaredService);
|
|
100
|
-
if (existing !== undefined) {
|
|
101
|
-
return existing;
|
|
102
|
-
}
|
|
103
|
-
const created = new Map();
|
|
104
|
-
singletonServices.set(declaredService, created);
|
|
105
|
-
return created;
|
|
106
|
-
};
|
|
107
|
-
const doCreateServiceInstance = async (declaredService, serviceContext) => {
|
|
108
|
-
try {
|
|
109
|
-
const created = await declaredService.create(serviceContext);
|
|
110
|
-
if (created.isErr()) {
|
|
111
|
-
return Result.err(created.error);
|
|
112
|
-
}
|
|
113
|
-
const instance = created.unwrap();
|
|
114
|
-
getSingletonServiceCache(declaredService).set(toServiceContextKey(serviceContext), instance);
|
|
115
|
-
return Result.ok(instance);
|
|
116
|
-
}
|
|
117
|
-
catch (error) {
|
|
118
|
-
return Result.err(toInternalServiceError(declaredService.id, error));
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
const trackPendingCreation = (declaredService, key, promise) => {
|
|
122
|
-
const pending = pendingCreations.get(declaredService);
|
|
123
|
-
if (pending) {
|
|
124
|
-
pending.set(key, promise);
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
pendingCreations.set(declaredService, new Map([[key, promise]]));
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
|
-
/**
|
|
131
|
-
* Deduplicates concurrent creation of the same service singleton.
|
|
132
|
-
* If a creation is already in flight for this service × context key,
|
|
133
|
-
* returns the existing promise instead of spawning a second factory call.
|
|
134
|
-
*/
|
|
135
|
-
const createServiceInstance = async (declaredService, serviceContext) => {
|
|
136
|
-
const key = toServiceContextKey(serviceContext);
|
|
137
|
-
const inflight = pendingCreations.get(declaredService)?.get(key);
|
|
138
|
-
if (inflight) {
|
|
139
|
-
return inflight;
|
|
140
|
-
}
|
|
141
|
-
const promise = doCreateServiceInstance(declaredService, serviceContext);
|
|
142
|
-
trackPendingCreation(declaredService, key, promise);
|
|
143
|
-
try {
|
|
144
|
-
return await promise;
|
|
145
|
-
}
|
|
146
|
-
finally {
|
|
147
|
-
pendingCreations.get(declaredService)?.delete(key);
|
|
148
|
-
}
|
|
149
|
-
};
|
|
150
|
-
const resolveServiceInstance = async (declaredService, ctx, serviceContext, overrides) => getProvidedService(ctx, overrides, declaredService, serviceContext) ??
|
|
151
|
-
(await createServiceInstance(declaredService, serviceContext));
|
|
152
|
-
const withResolvedServices = (ctx, resolvedServices) => {
|
|
153
|
-
const extensions = { ...ctx.extensions, ...resolvedServices };
|
|
154
|
-
const resolvedCtx = { ...ctx, extensions };
|
|
155
|
-
resolvedCtx.service = createServiceLookup(() => resolvedCtx);
|
|
156
|
-
return resolvedCtx;
|
|
157
|
-
};
|
|
158
|
-
const resolveServices = async (trail, ctx, overrides) => {
|
|
159
|
-
if (trail.services.length === 0) {
|
|
160
|
-
return Result.ok(ctx);
|
|
161
|
-
}
|
|
162
|
-
const resolvedServices = {};
|
|
163
|
-
const serviceContext = toServiceContext(ctx);
|
|
164
|
-
for (const declaredService of trail.services) {
|
|
165
|
-
const resolved = await resolveServiceInstance(declaredService, ctx, serviceContext, overrides);
|
|
166
|
-
if (resolved.isErr()) {
|
|
167
|
-
return resolved;
|
|
168
|
-
}
|
|
169
|
-
resolvedServices[declaredService.id] = resolved.unwrap();
|
|
170
|
-
}
|
|
171
|
-
return Result.ok(withResolvedServices(ctx, resolvedServices));
|
|
172
|
-
};
|
|
173
49
|
const prepareContext = async (trail, options) => {
|
|
174
50
|
const baseCtx = await resolveContext(options);
|
|
175
|
-
return await resolveServices(trail, baseCtx, options?.services);
|
|
51
|
+
return await resolveServices(trail, baseCtx, options?.services, options?.configValues);
|
|
176
52
|
};
|
|
177
53
|
const runTrail = async (trail, input, ctx, layers) => {
|
|
178
54
|
const impl = composeLayers([...layers], trail, trail.run);
|
package/dist/execute.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execute.js","sourceRoot":"","sources":["../src/execute.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"execute.js","sourceRoot":"","sources":["../src/execute.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAOH,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AA8BhD,8EAA8E;AAC9E,qBAAqB;AACrB,8EAA8E;AAE9E;;;;;;;GAOG;AACH,MAAM,cAAc,GAAG,KAAK,EAC1B,OAA6B,EACN,EAAE;IACzB,MAAM,IAAI,GAAG,OAAO,EAAE,aAAa;QACjC,CAAC,CAAC,MAAM,OAAO,CAAC,aAAa,EAAE;QAC/B,CAAC,CAAC,kBAAkB,EAAE,CAAC;IACzB,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;IAC5D,MAAM,aAAa,GAAG,OAAO,EAAE,GAAG;QAChC,CAAC,CAAC;YACE,GAAG,IAAI;YACP,GAAG,OAAO,CAAC,GAAG;YACd,U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,KAAe,EACf,QAAiB,EACjB,OAA6B,EACI,EAAE;IACnC,IAAI,CAAC;QACH,MAAM,SAAS,GAAG,aAAa,CAAC,KAAK,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QACvD,IAAI,SAAS,CAAC,KAAK,EAAE,EAAE,CAAC;YACtB,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,MAAM,WAAW,GAAG,MAAM,cAAc,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QACzD,IAAI,WAAW,CAAC,KAAK,EAAE,EAAE,CAAC;YACxB,OAAO,WAAW,CAAC;QACrB,CAAC;QAED,OAAO,MAAM,QAAQ,CACnB,KAAK,EACL,SAAS,CAAC,KAAK,EACf,WAAW,CAAC,KAAK,EACjB,OAAO,EAAE,MAAM,IAAI,EAAE,CACtB,CAAC;IACJ,CAAC;IAAC,OAAO,KAAc,EAAE,CAAC;QACxB,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACvE,OAAO,MAAM,CAAC,GAAG,CAAC,IAAI,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC;IAChD,CAAC;AACH,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export { Result } from './result.js';
|
|
2
2
|
export { TrailsError, ValidationError, AmbiguousError, AssertionError, NotFoundError, AlreadyExistsError, ConflictError, PermissionError, TimeoutError, RateLimitError, NetworkError, InternalError, AuthError, CancelledError, exitCodeMap, statusCodeMap, jsonRpcCodeMap, retryableMap, isRetryable, isTrailsError, } from './errors.js';
|
|
3
3
|
export type { ErrorCategory } from './errors.js';
|
|
4
|
-
export type { Implementation, TrailContext, TrailContextInit, FollowFn, ProgressCallback, ProgressEvent, Logger, ServiceLookup, } from './types.js';
|
|
4
|
+
export type { Implementation, TrailContext, TrailContextInit, FollowFn, BasePermit, PermitRequirement, ProgressCallback, ProgressEvent, Logger, ServiceLookup, } from './types.js';
|
|
5
|
+
export { SURFACE_KEY } from './types.js';
|
|
5
6
|
export { createTrailContext } from './context.js';
|
|
6
7
|
export { createServiceLookup, findDuplicateServiceId, isService, service, } from './service.js';
|
|
7
8
|
export type { AnyService, Service, ServiceContext, ServiceOverrideMap, ServiceSpec, } from './service.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAGrC,OAAO,EACL,WAAW,EACX,eAAe,EACf,cAAc,EACd,cAAc,EACd,aAAa,EACb,kBAAkB,EAClB,aAAa,EACb,eAAe,EACf,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,aAAa,EACb,SAAS,EACT,cAAc,EACd,WAAW,EACX,aAAa,EACb,cAAc,EACd,YAAY,EACZ,WAAW,EACX,aAAa,GACd,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAGjD,YAAY,EACV,cAAc,EACd,YAAY,EACZ,gBAAgB,EAChB,QAAQ,EACR,gBAAgB,EAChB,aAAa,EACb,MAAM,EACN,aAAa,GACd,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAGrC,OAAO,EACL,WAAW,EACX,eAAe,EACf,cAAc,EACd,cAAc,EACd,aAAa,EACb,kBAAkB,EAClB,aAAa,EACb,eAAe,EACf,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,aAAa,EACb,SAAS,EACT,cAAc,EACd,WAAW,EACX,aAAa,EACb,cAAc,EACd,YAAY,EACZ,WAAW,EACX,aAAa,GACd,MAAM,aAAa,CAAC;AACrB,YAAY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AChB,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EACV,aAAa,EACb,WAAW,EACX,QAAQ,EACR,UAAU,GACX,MAAM,kBAAkB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
export { Result } from './result.js';
|
|
3
3
|
// Errors
|
|
4
4
|
export { TrailsError, ValidationError, AmbiguousError, AssertionError, NotFoundError, AlreadyExistsError, ConflictError, PermissionError, TimeoutError, RateLimitError, NetworkError, InternalError, AuthError, CancelledError, exitCodeMap, statusCodeMap, jsonRpcCodeMap, retryableMap, isRetryable, isTrailsError, } from './errors.js';
|
|
5
|
+
export { SURFACE_KEY } from './types.js';
|
|
5
6
|
// Context factory
|
|
6
7
|
export { createTrailContext } from './context.js';
|
|
7
8
|
// Service
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,SAAS;AACT,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,SAAS;AACT,OAAO,EACL,WAAW,EACX,eAAe,EACf,cAAc,EACd,cAAc,EACd,aAAa,EACb,kBAAkB,EAClB,aAAa,EACb,eAAe,EACf,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,aAAa,EACb,SAAS,EACT,cAAc,EACd,WAAW,EACX,aAAa,EACb,cAAc,EACd,YAAY,EACZ,WAAW,EACX,aAAa,GACd,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,SAAS;AACT,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,SAAS;AACT,OAAO,EACL,WAAW,EACX,eAAe,EACf,cAAc,EACd,cAAc,EACd,aAAa,EACb,kBAAkB,EAClB,aAAa,EACb,eAAe,EACf,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,aAAa,EACb,SAAS,E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c,EACd,WAAW,EACX,OAAO,EACP,MAAM,GACP,MAAM,cAAc,CAAC;AAStB,gBAAgB;AAChB,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE7E,YAAY;AACZ,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,GAChB,MAAM,gBAAgB,CAAC;AAExB,OAAO;AACP,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAGzD,SAAS;AACT,OAAO,EACL,SAAS,EACT,gBAAgB,EAChB,aAAa,EACb,WAAW,EACX,WAAW,GACZ,MAAM,aAAa,CAAC;AAErB,cAAc;AACd,OAAO,EACL,KAAK,EACL,MAAM,EACN,OAAO,EACP,MAAM,EACN,eAAe,GAChB,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Service resolution pipeline.
|
|
3
|
+
*
|
|
4
|
+
* Extracted from execute.ts to keep both modules under the 400 LOC ceiling.
|
|
5
|
+
* Handles config validation, singleton caching, concurrent-creation dedup,
|
|
6
|
+
* and the full resolve-or-create flow for declared services.
|
|
7
|
+
*/
|
|
8
|
+
import type { ServiceOverrideMap } from './service.js';
|
|
9
|
+
import type { AnyTrail } from './trail.js';
|
|
10
|
+
import type { TrailContext } from './types.js';
|
|
11
|
+
import { Result } from './result.js';
|
|
12
|
+
type ConfigValues = Readonly<Record<string, Record<string, unknown>>>;
|
|
13
|
+
/**
|
|
14
|
+
* Resolve all declared services for a trail.
|
|
15
|
+
*
|
|
16
|
+
* Validates per-service config, checks overrides and caches, and creates
|
|
17
|
+
* new instances as needed. Returns an enriched context with all service
|
|
18
|
+
* instances injected into extensions.
|
|
19
|
+
*/
|
|
20
|
+
export declare const resolveServices: (trail: AnyTrail, ctx: TrailContext, overrides?: ServiceOverrideMap, configValues?: ConfigValues) => Promise<Result<TrailContext, Error>>;
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=service-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service-config.d.ts","sourceRoot":"","sources":["../src/service-config.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAGV,kBAAkB,EACnB,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAG/C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAOrC,KAAK,YAAY,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;AAwStE;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,GAC1B,OAAO,QAAQ,EACf,KAAK,YAAY,EACjB,YAAY,kBAAkB,EAC9B,eAAe,YAAY,KAC1B,OAAO,CAAC,MAAM,CAAC,YAAY,EAAE,KAAK,CAAC,CAqBrC,CAAC"}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Service resolution pipeline.
|
|
3
|
+
*
|
|
4
|
+
* Extracted from execute.ts to keep both modules under the 400 LOC ceiling.
|
|
5
|
+
* Handles config validation, singleton caching, concurrent-creation dedup,
|
|
6
|
+
* and the full resolve-or-create flow for declared services.
|
|
7
|
+
*/
|
|
8
|
+
import { InternalError, ValidationError } from './errors.js';
|
|
9
|
+
import { Result } from './result.js';
|
|
10
|
+
import { createServiceLookup } from './service.js';
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
// Singleton caches
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
const singletonServices = new WeakMap();
|
|
15
|
+
/** In-flight service creation promises, keyed by service x context. */
|
|
16
|
+
const pendingCreations = new WeakMap();
|
|
17
|
+
// ---------------------------------------------------------------------------
|
|
18
|
+
// Context helpers
|
|
19
|
+
// ---------------------------------------------------------------------------
|
|
20
|
+
const toServiceContext = (ctx, config) => ({
|
|
21
|
+
config,
|
|
22
|
+
cwd: ctx.cwd,
|
|
23
|
+
env: ctx.env,
|
|
24
|
+
workspaceRoot: ctx.workspaceRoot,
|
|
25
|
+
});
|
|
26
|
+
const toServiceContextKey = (ctx) => JSON.stringify({
|
|
27
|
+
config: ctx.config,
|
|
28
|
+
cwd: ctx.cwd,
|
|
29
|
+
env: Object.entries(ctx.env ?? {}).toSorted(([left], [right]) => left.localeCompare(right)),
|
|
30
|
+
workspaceRoot: ctx.workspaceRoot,
|
|
31
|
+
});
|
|
32
|
+
// ---------------------------------------------------------------------------
|
|
33
|
+
// Config validation
|
|
34
|
+
// ---------------------------------------------------------------------------
|
|
35
|
+
/** Validate and resolve a service's config from the provided configValues map. */
|
|
36
|
+
const resolveServiceConfig = (declaredService, configValues) => {
|
|
37
|
+
if (declaredService.config === undefined) {
|
|
38
|
+
return Result.ok();
|
|
39
|
+
}
|
|
40
|
+
const raw = configValues?.[declaredService.id];
|
|
41
|
+
if (raw === undefined) {
|
|
42
|
+
return Result.err(new ValidationError(`Service "${declaredService.id}" declares a config schema but no config was provided`));
|
|
43
|
+
}
|
|
44
|
+
const parsed = declaredService.config.safeParse(raw);
|
|
45
|
+
if (!parsed.success) {
|
|
46
|
+
return Result.err(new ValidationError(`Service "${declaredService.id}" config validation failed: ${parsed.error.message}`));
|
|
47
|
+
}
|
|
48
|
+
return Result.ok(parsed.data);
|
|
49
|
+
};
|
|
50
|
+
// ---------------------------------------------------------------------------
|
|
51
|
+
// Override / cache lookups
|
|
52
|
+
// ---------------------------------------------------------------------------
|
|
53
|
+
const hasOwnServiceOverride = (overrides, id) => overrides !== undefined && Object.hasOwn(overrides, id);
|
|
54
|
+
const getCachedSingletonService = (declaredService, serviceContext) => {
|
|
55
|
+
const scopedCache = singletonServices.get(declaredService);
|
|
56
|
+
if (scopedCache === undefined) {
|
|
57
|
+
return { found: false, value: undefined };
|
|
58
|
+
}
|
|
59
|
+
const key = toServiceContextKey(serviceContext);
|
|
60
|
+
if (!scopedCache.has(key)) {
|
|
61
|
+
return { found: false, value: undefined };
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
found: true,
|
|
65
|
+
value: scopedCache.get(key),
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
const getProvidedService = (ctx, overrides, declaredService, serviceContext) => {
|
|
69
|
+
const { id } = declaredService;
|
|
70
|
+
if (hasOwnServiceOverride(overrides, id)) {
|
|
71
|
+
return Result.ok(overrides[id]);
|
|
72
|
+
}
|
|
73
|
+
if (Object.hasOwn(ctx.extensions ?? {}, id)) {
|
|
74
|
+
return Result.ok(ctx.extensions?.[id]);
|
|
75
|
+
}
|
|
76
|
+
const cached = getCachedSingletonService(declaredService, serviceContext);
|
|
77
|
+
if (cached.found) {
|
|
78
|
+
return Result.ok(cached.value);
|
|
79
|
+
}
|
|
80
|
+
return undefined;
|
|
81
|
+
};
|
|
82
|
+
const getOverrideOrExtension = (ctx, overrides, declaredService) => getProvidedService(ctx, overrides, declaredService, toServiceContext(ctx));
|
|
83
|
+
const resolveConfigAwareProvidedService = (ctx, declaredService, configValues) => {
|
|
84
|
+
const configResult = resolveServiceConfig(declaredService, configValues);
|
|
85
|
+
if (configResult.isErr()) {
|
|
86
|
+
return configResult;
|
|
87
|
+
}
|
|
88
|
+
const serviceContext = toServiceContext(ctx, configResult.value);
|
|
89
|
+
const provided = getProvidedService(ctx, undefined, declaredService, serviceContext);
|
|
90
|
+
return provided
|
|
91
|
+
? Result.ok({ kind: 'provided', value: provided.unwrap() })
|
|
92
|
+
: Result.ok({ kind: 'context', serviceContext });
|
|
93
|
+
};
|
|
94
|
+
// ---------------------------------------------------------------------------
|
|
95
|
+
// Instance creation
|
|
96
|
+
// ---------------------------------------------------------------------------
|
|
97
|
+
const toInternalServiceError = (id, error) => {
|
|
98
|
+
const cause = error instanceof Error ? error : undefined;
|
|
99
|
+
const message = cause?.message ?? String(error);
|
|
100
|
+
return new InternalError(`Service "${id}" failed to resolve: ${message}`, {
|
|
101
|
+
...(cause ? { cause } : {}),
|
|
102
|
+
context: { serviceId: id },
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
const getSingletonServiceCache = (declaredService) => {
|
|
106
|
+
const existing = singletonServices.get(declaredService);
|
|
107
|
+
if (existing !== undefined) {
|
|
108
|
+
return existing;
|
|
109
|
+
}
|
|
110
|
+
const created = new Map();
|
|
111
|
+
singletonServices.set(declaredService, created);
|
|
112
|
+
return created;
|
|
113
|
+
};
|
|
114
|
+
const doCreateServiceInstance = async (declaredService, serviceContext) => {
|
|
115
|
+
try {
|
|
116
|
+
const created = await declaredService.create(serviceContext);
|
|
117
|
+
if (created.isErr()) {
|
|
118
|
+
return Result.err(created.error);
|
|
119
|
+
}
|
|
120
|
+
const instance = created.unwrap();
|
|
121
|
+
getSingletonServiceCache(declaredService).set(toServiceContextKey(serviceContext), instance);
|
|
122
|
+
return Result.ok(instance);
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
return Result.err(toInternalServiceError(declaredService.id, error));
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
const trackPendingCreation = (declaredService, key, promise) => {
|
|
129
|
+
const pending = pendingCreations.get(declaredService);
|
|
130
|
+
if (pending) {
|
|
131
|
+
pending.set(key, promise);
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
pendingCreations.set(declaredService, new Map([[key, promise]]));
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* Deduplicates concurrent creation of the same service singleton.
|
|
139
|
+
* If a creation is already in flight for this service x context key,
|
|
140
|
+
* returns the existing promise instead of spawning a second factory call.
|
|
141
|
+
*/
|
|
142
|
+
const createServiceInstance = async (declaredService, serviceContext) => {
|
|
143
|
+
const key = toServiceContextKey(serviceContext);
|
|
144
|
+
const inflight = pendingCreations.get(declaredService)?.get(key);
|
|
145
|
+
if (inflight) {
|
|
146
|
+
return inflight;
|
|
147
|
+
}
|
|
148
|
+
const promise = doCreateServiceInstance(declaredService, serviceContext);
|
|
149
|
+
trackPendingCreation(declaredService, key, promise);
|
|
150
|
+
try {
|
|
151
|
+
return await promise;
|
|
152
|
+
}
|
|
153
|
+
finally {
|
|
154
|
+
pendingCreations.get(declaredService)?.delete(key);
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
/** Validate config and resolve a single declared service. */
|
|
158
|
+
const resolveDeclaredService = async (declaredService, ctx, overrides, configValues) => {
|
|
159
|
+
// Check overrides/extensions first — skip config validation entirely when
|
|
160
|
+
// a service instance is already provided.
|
|
161
|
+
const overrideOrExtension = getOverrideOrExtension(ctx, overrides, declaredService);
|
|
162
|
+
if (overrideOrExtension !== undefined) {
|
|
163
|
+
return overrideOrExtension;
|
|
164
|
+
}
|
|
165
|
+
// Resolve config before consulting the singleton cache so config-aware
|
|
166
|
+
// services use the same canonical context for cache reads and writes.
|
|
167
|
+
const configAwareService = resolveConfigAwareProvidedService(ctx, declaredService, configValues);
|
|
168
|
+
if (configAwareService.isErr()) {
|
|
169
|
+
return configAwareService;
|
|
170
|
+
}
|
|
171
|
+
// No provided instance — create via factory.
|
|
172
|
+
const resolved = configAwareService.unwrap();
|
|
173
|
+
if (resolved.kind === 'provided') {
|
|
174
|
+
return Result.ok(resolved.value);
|
|
175
|
+
}
|
|
176
|
+
return await createServiceInstance(declaredService, resolved.serviceContext);
|
|
177
|
+
};
|
|
178
|
+
// ---------------------------------------------------------------------------
|
|
179
|
+
// Full trail service resolution
|
|
180
|
+
// ---------------------------------------------------------------------------
|
|
181
|
+
const withResolvedServices = (ctx, resolvedServices) => {
|
|
182
|
+
const extensions = { ...ctx.extensions, ...resolvedServices };
|
|
183
|
+
const resolvedCtx = { ...ctx, extensions };
|
|
184
|
+
resolvedCtx.service = createServiceLookup(() => resolvedCtx);
|
|
185
|
+
return resolvedCtx;
|
|
186
|
+
};
|
|
187
|
+
/**
|
|
188
|
+
* Resolve all declared services for a trail.
|
|
189
|
+
*
|
|
190
|
+
* Validates per-service config, checks overrides and caches, and creates
|
|
191
|
+
* new instances as needed. Returns an enriched context with all service
|
|
192
|
+
* instances injected into extensions.
|
|
193
|
+
*/
|
|
194
|
+
export const resolveServices = async (trail, ctx, overrides, configValues) => {
|
|
195
|
+
if (trail.services.length === 0) {
|
|
196
|
+
return Result.ok(ctx);
|
|
197
|
+
}
|
|
198
|
+
const resolvedServices = {};
|
|
199
|
+
for (const declaredService of trail.services) {
|
|
200
|
+
const resolved = await resolveDeclaredService(declaredService, ctx, overrides, configValues);
|
|
201
|
+
if (resolved.isErr()) {
|
|
202
|
+
return resolved;
|
|
203
|
+
}
|
|
204
|
+
resolvedServices[declaredService.id] = resolved.unwrap();
|
|
205
|
+
}
|
|
206
|
+
return Result.ok(withResolvedServices(ctx, resolvedServices));
|
|
207
|
+
};
|
|
208
|
+
//# sourceMappingURL=service-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service-config.js","sourceRoot":"","sources":["../src/service-config.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAUH,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAQnD,8EAA8E;AAC9E,mBAAmB;AACnB,8EAA8E;AAE9E,MAAM,iBAAiB,GAAG,IAAI,OAAO,EAAoC,CAAC;AAE1E,uEAAuE;AACvE,MAAM,gBAAgB,GAAG,IAAI,OAAO,EAGjC,CAAC;AAEJ,8EAA8E;AAC9E,kBAAkB;AAClB,8EAA8E;AAE9E,MAAM,gBAAgB,GAAG,CACvB,GAAiB,EACjB,MAAgB,EACA,EAAE,CAAC,CAAC;IACpB,MAAM;IACN,GAAG,EAAE,GAAG,CAAC,GAAG;IACZ,GAAG,EAAE,GAAG,C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O,WAAW,CAAC;AACrB,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,EAClC,KAAe,EACf,GAAiB,EACjB,SAA8B,EAC9B,YAA2B,EACW,EAAE;IACxC,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAChC,OAAO,MAAM,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;IACxB,CAAC;IAED,MAAM,gBAAgB,GAA4B,EAAE,CAAC;IAErD,KAAK,MAAM,eAAe,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC;QAC7C,MAAM,QAAQ,GAAG,MAAM,sBAAsB,CAC3C,eAAe,EACf,GAAG,EACH,SAAS,EACT,YAAY,CACb,CAAC;QACF,IAAI,QAAQ,CAAC,KAAK,EAAE,EAAE,CAAC;YACrB,OAAO,QAAQ,CAAC;QAClB,CAAC;QACD,gBAAgB,CAAC,eAAe,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC;IAC3D,CAAC;IAED,OAAO,MAAM,CAAC,EAAE,CAAC,oBAAoB,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC,CAAC;AAChE,CAAC,CAAC"}
|
package/dist/service.d.ts
CHANGED
|
@@ -5,17 +5,23 @@ import type { z } from 'zod';
|
|
|
5
5
|
* Stable process-scoped fields available when constructing a service.
|
|
6
6
|
*
|
|
7
7
|
* Services are app-level singletons, so they intentionally do not receive the
|
|
8
|
-
* full per-request TrailContext.
|
|
8
|
+
* full per-request TrailContext. When a service declares a `config` schema,
|
|
9
|
+
* the validated config is passed as `svc.config`.
|
|
9
10
|
*/
|
|
10
|
-
export type ServiceContext = Pick<TrailContext, 'cwd' | 'env' | 'workspaceRoot'
|
|
11
|
+
export type ServiceContext<C = unknown> = Pick<TrailContext, 'cwd' | 'env' | 'workspaceRoot'> & {
|
|
12
|
+
readonly config: C;
|
|
13
|
+
};
|
|
11
14
|
/**
|
|
12
15
|
* Everything needed to describe a service before a factory is introduced.
|
|
16
|
+
*
|
|
17
|
+
* When `config` is a Zod schema, the `create` callback receives
|
|
18
|
+
* `ServiceContext<C>` with the validated config value.
|
|
13
19
|
*/
|
|
14
|
-
export interface ServiceSpec<T> {
|
|
20
|
+
export interface ServiceSpec<T, C = unknown> {
|
|
15
21
|
/** Create the service instance from stable process-scoped context. */
|
|
16
|
-
readonly create: (svc: ServiceContext) => Result<T, Error> | Promise<Result<T, Error>>;
|
|
17
|
-
/**
|
|
18
|
-
readonly config?: z.ZodType | undefined;
|
|
22
|
+
readonly create: (svc: ServiceContext<C>) => Result<T, Error> | Promise<Result<T, Error>>;
|
|
23
|
+
/** Config schema — when present, config is validated and passed to `create`. */
|
|
24
|
+
readonly config?: z.ZodType<C> | undefined;
|
|
19
25
|
/** Optional cleanup performed when the hosting surface shuts down. */
|
|
20
26
|
readonly dispose?: ((service: T) => void | Promise<void>) | undefined;
|
|
21
27
|
/** Optional operational readiness probe for introspection tooling. */
|
package/dist/service.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC9D,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC9D,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B;;;;;;GAMG;AACH,MAAM,MAAM,cAAc,CAAC,CAAC,GAA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AAW,OAAO,CAAC,CAAC,CAAE,SAAQ,WAAW,CAAC,CAAC,CAAC;IAChD,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,+DAA+D;IAC/D,IAAI,CAAC,GAAG,EAAE,YAAY,GAAG,CAAC,CAAC;CAC5B;AAED;;;;;GAKG;AAEH,MAAM,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;AAEtC,sDAAsD;AACtD,MAAM,MAAM,kBAAkB,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAmBnE,iFAAiF;AACjF,eAAO,MAAM,mBAAmB,GAC9B,YAAY,MAAM,IAAI,CAAC,YAAY,EAAE,YAAY,CAAC,KACjD,aAQkB,CAAC;AAEtB;;;;;GAKG;AACH,eAAO,MAAM,OAAO,GAAI,CAAC,EAAE,IAAI,MAAM,EAAE,MAAM,WAAW,CAAC,CAAC,CAAC,KAAG,OAAO,CAAC,CAAC,CASnE,CAAC;AAEL,0EAA0E;AAC1E,eAAO,MAAM,SAAS,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,UAMnD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,GACjC,UAAU,SAAS,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,EAAE,KAC1C,MAAM,GAAG,SASX,CAAC"}
|
package/dist/service.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAuE5C,MAAM,YAAY,GAAG,CACnB,WAA4C,EACpC,EAAE,CAAC,CAA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,IAAI,EAAE,SAAkB;CACzB,CAAC,CAAC;AAEL,0EAA0E;AAC1E,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,KAAc,EAAuB,EAAE;IAC/D,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QAChD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,CAAC,GAAG,KAAyC,CAAC;IACpD,OAAO,CAAC,CAAC,IAAI,KAAK,SAAS,IAAI,OAAO,CAAC,CAAC,EAAE,KAAK,QAAQ,CAAC;AAC1D,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CACpC,QAA2C,EACvB,EAAE;IACtB,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,KAAK,MAAM,SAAS,IAAI,QAAQ,EAAE,CAAC;QACjC,IAAI,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE,CAAC;YAC3B,OAAO,SAAS,CAAC,EAAE,CAAC;QACtB,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;IACzB,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC"}
|
package/dist/trail.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { z } from 'zod';
|
|
|
2
2
|
import type { FieldOverride } from './derive.js';
|
|
3
3
|
import type { Result } from './result.js';
|
|
4
4
|
import type { AnyService } from './service.js';
|
|
5
|
-
import type { Implementation, TrailContext } from './types.js';
|
|
5
|
+
import type { Implementation, PermitRequirement, TrailContext } from './types.js';
|
|
6
6
|
/**
|
|
7
7
|
* A named example for documentation and testing.
|
|
8
8
|
*
|
|
@@ -48,6 +48,8 @@ export interface TrailSpec<I, O> {
|
|
|
48
48
|
readonly follow?: readonly string[] | undefined;
|
|
49
49
|
/** Services this trail may access via service.from(ctx) */
|
|
50
50
|
readonly services?: readonly AnyService[] | undefined;
|
|
51
|
+
/** Auth requirement: scopes object, 'public', or omitted (undeclared) */
|
|
52
|
+
readonly permit?: PermitRequirement | undefined;
|
|
51
53
|
}
|
|
52
54
|
/** Intent describes what a trail does to the world */
|
|
53
55
|
export type Intent = 'read' | 'write' | 'destroy';
|
package/dist/trail.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trail.d.ts","sourceRoot":"","sources":["../src/trail.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"trail.d.ts","sourceRoot":"","sources":["../src/trail.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EACV,cAAc,EACd,iBAAiB,EACjB,YAAY,EACb,MAAM,YAAY,CAAC;AAMpB;;;;;;GAMG;AACH,MAAM,WAAW,YAAY,CAAC,CAAC,EAAE,CAAC;IAChC,0BAA0B;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,6DAA6D;IAC7D,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1C,mEAAmE;IACnE,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IAC3B,gDAAgD;IAChD,QAAQ,CAAC,QAAQ,CA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,MAAM,CAAA;CAAE,GAC9C,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAmCf,MAAM,MAAM,QAAQ,GAAG,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AAEvC,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,EAAE,CAAC"}
|
package/dist/trail.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trail.js","sourceRoot":"","sources":["../src/trail.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"trail.js","sourceRoot":"","sources":["../src/trail.ts"],"names":[],"mappings":"AA0HA,MAAM,UAAU,KAAK,CACnB,QAA8D,EAC9D,SAA2B;IAE3B,MAAM,QAAQ,GACZ,OAAO,QAAQ,KAAK,QAAQ;QAC1B,CAAC,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE;QACnC,CAAC,CAAC,EAAE,EAAE,EAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;IAE1C,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;QACnB,MAAM,IAAI,SAAS,CAAC,gDAAgD,CAAC,CAAC;IACxE,CAAC;IAED,MAAM,EACJ,GAAG,EACH,MAAM,EAAE,SAAS,EACjB,MAAM,EAAE,SAAS,EACjB,QAAQ,EAAE,WAAW,EACrB,GAAG,IAAI,EACR,GAAG,QAAQ,CAAC,IAAI,CAAC;IAElB,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,GAAG,IAAI;QACP,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,CAAC;QAC7C,EAAE,EAAE,QAAQ,CAAC,EAAE;QACf,MAAM,EAAE,SAAS,IAAI,OAAO;QAC5B,IAAI,EAAE,OAAgB;QACtB,GAAG,EAAE,KAAK,EAAE,KAAQ,EAAE,GAAiB,EAAE,EAAE,CAAC,MAAM,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC;QACjE,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC,CAAC;KAClD,CAAC,CAAC;AACL,CAAC"}
|