@smthrs/plugin 1.0.0-rc.7 → 1.0.0-rc.9

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.
@@ -26,9 +26,19 @@ const empty = Object.freeze([]);
26
26
  // The typed catalog and the runtime catalog can only drift when a host casts
27
27
  // around `KeysOfKind`; refuse before any handler runs rather than execute a
28
28
  // hook under semantics its declaration never promised.
29
- const kindMismatch = (resolved, hook, kind) => {
30
- if (!Object.hasOwn(resolved.kinds, hook))
31
- return undefined;
29
+ // A hook the catalog does not declare dispatches as empty, unless a
30
+ // hand-built resolution registered handlers for it: those have no declared
31
+ // kind to honor, so they are refused too.
32
+ const kindMismatch = (resolved, hook, kind, handlers) => {
33
+ if (!Object.hasOwn(resolved.kinds, hook)) {
34
+ if (handlers.length === 0)
35
+ return undefined;
36
+ return new PluginError({
37
+ code: "hook_kind_mismatch",
38
+ message: `hook "${hook}" has handlers but is not declared in the runtime catalog`,
39
+ hook
40
+ });
41
+ }
32
42
  const declared = resolved.kinds[hook];
33
43
  if (declared === kind)
34
44
  return undefined;
@@ -64,7 +74,7 @@ const runHandler = (record, args) => {
64
74
  export const make = (resolved) => {
65
75
  const handlers = (hook) => resolved.handlers.get(hook) ?? empty;
66
76
  const sequential = ((hook, ...args) => Effect.gen(function* () {
67
- const mismatch = kindMismatch(resolved, hook, "sequential");
77
+ const mismatch = kindMismatch(resolved, hook, "sequential", handlers(hook));
68
78
  if (mismatch !== undefined)
69
79
  return yield* Effect.fail(mismatch);
70
80
  const results = [];
@@ -74,13 +84,13 @@ export const make = (resolved) => {
74
84
  return results;
75
85
  }));
76
86
  const parallel = ((hook, ...args) => {
77
- const mismatch = kindMismatch(resolved, hook, "parallel");
87
+ const mismatch = kindMismatch(resolved, hook, "parallel", handlers(hook));
78
88
  if (mismatch !== undefined)
79
89
  return Effect.succeed([mismatch]);
80
90
  return Effect.forEach(handlers(hook), (record) => runHandler(record, args).pipe(Effect.match({ onFailure: (error) => [error], onSuccess: () => [] })), { concurrency: resolved.parallelConcurrency }).pipe(Effect.map((chunks) => chunks.flat()));
81
91
  });
82
92
  const first = ((hook, ...args) => Effect.gen(function* () {
83
- const mismatch = kindMismatch(resolved, hook, "first");
93
+ const mismatch = kindMismatch(resolved, hook, "first", handlers(hook));
84
94
  if (mismatch !== undefined)
85
95
  return yield* Effect.fail(mismatch);
86
96
  for (const record of handlers(hook)) {
@@ -99,7 +109,7 @@ export const make = (resolved) => {
99
109
  return Option.none();
100
110
  }));
101
111
  const waterfall = ((hook, initial, merge) => Effect.gen(function* () {
102
- const mismatch = kindMismatch(resolved, hook, "waterfall");
112
+ const mismatch = kindMismatch(resolved, hook, "waterfall", handlers(hook));
103
113
  if (mismatch !== undefined)
104
114
  return yield* Effect.fail(mismatch);
105
115
  let value = initial;
@@ -114,13 +124,15 @@ export const make = (resolved) => {
114
124
  message: cause.message,
115
125
  plugin: record.plugin,
116
126
  hook: record.hook,
117
- path: cause.path
127
+ path: cause.path,
128
+ cause
118
129
  })
119
130
  : new PluginError({
120
131
  code: "config_invalid",
121
132
  message: `waterfall hook "${record.hook}" in plugin "${record.plugin}" returned an invalid patch`,
122
133
  plugin: record.plugin,
123
- hook: record.hook
134
+ hook: record.hook,
135
+ cause
124
136
  })
125
137
  });
126
138
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Plugins.js","sourceRoot":"","sources":["../../src/Plugins.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,YAAY,MAAM,+BAA+B,CAAA;AAE7D,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAExC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CA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CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAA;AAEzG;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,SAAS,GAAyB,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAA","sourcesContent":["/**\n * The dispatcher: a plain service over a resolved plugin list, generic over the\n * hook interface.\n *\n * The public package contract is documented at\n * {@link https://smithers.sh/docs/reference/api/plugin}. Each host holds an instance over its\n * augmented `FlowsHooks` and may dispatch only the runtime catalog it supplied.\n * The shipped cell host owns the three\n * waterfalls declared in `packages/smithers/agent/src/CellPlugin.ts`; there is\n * no engine-wide lifecycle dispatcher.\n *\n * Cancellation is fiber interruption via scope closure; nothing here threads an\n * `AbortSignal`.\n *\n * @since 1.0.0-rc.0\n */\n\nimport * as ImmutableMap from \"@smthrs/canonical/ReadonlyMap\"\nimport type * as Cause from \"effect/Cause\"\nimport * as Context from \"effect/Context\"\nimport * as Effect from \"effect/Effect\"\nimport * as Layer from \"effect/Layer\"\nimport * as Option from \"effect/Option\"\nimport type { ArgsOf, ContextOf, HookKind, KeysOfKind, SuccessOf } from \"./Hooks.ts\"\nimport { engineHooks } from \"./Hooks.ts\"\nimport type { FlowsHooks } from \"./index.ts\"\nimport { PluginError } from \"./PluginError.ts\"\nimport { defaultParallelConcurrency, type HandlerRecord, type Resolved } from \"./Resolve.ts\"\n\nconst empty: ReadonlyArray<HandlerRecord> = Object.freeze([])\n\n// The typed catalog and the runtime catalog can only drift when a host casts\n// around `KeysOfKind`; refuse before any handler runs rather than execute a\n// hook under semantics its declaration never promised.\nconst kindMismatch = (resolved: Resolved<unknown>, hook: string, kind: HookKind): PluginError | undefined => {\n if (!Object.hasOwn(resolved.kinds, hook)) return undefined\n const declared = resolved.kinds[hook]\n if (declared === kind) return undefined\n return new PluginError({\n code: \"hook_kind_mismatch\",\n message: `hook \"${hook}\" is declared ${JSON.stringify(declared)} in the runtime catalog but was dispatched as ${\n JSON.stringify(kind)\n }`,\n hook\n })\n}\n\nconst runHandler = (\n record: HandlerRecord,\n args: ReadonlyArray<unknown>\n): Effect.Effect<unknown, PluginError, any> => {\n const onCause = (cause: Cause.Cause<unknown>) =>\n Effect.fail(\n new PluginError({\n code: \"hook_failed\",\n message: `hook \"${record.hook}\" failed in plugin \"${record.plugin}\"`,\n plugin: record.plugin,\n hook: record.hook,\n cause\n })\n )\n\n return Effect.sync(() => record.handler(...args)).pipe(\n Effect.catchCause(onCause),\n Effect.flatMap((result) =>\n Effect.isEffect(result)\n ? result.pipe(Effect.catchCause(onCause))\n : Effect.fail(\n new PluginError({\n code: \"hook_failed\",\n message: `hook \"${record.hook}\" in plugin \"${record.plugin}\" returned a non-Effect (${typeof result})`,\n plugin: record.plugin,\n hook: record.hook\n })\n )\n )\n )\n}\n\n/**\n * The dispatch surface.\n *\n * @category models\n * @since 1.0.0-rc.0\n */\nexport interface Service<H = FlowsHooks> {\n /** The resolved list this dispatcher walks. */\n readonly resolved: Resolved<H>\n /** Frozen, ordered handler records for a hook. */\n readonly handlers: (hook: string) => ReadonlyArray<HandlerRecord>\n /** Runs every handler in resolved order, one at a time. */\n readonly sequential: <K extends KeysOfKind<H, \"sequential\">>(\n hook: K,\n ...args: ArgsOf<H[K]>\n ) => Effect.Effect<ReadonlyArray<SuccessOf<H[K]>>, PluginError, ContextOf<H[K]>>\n /**\n * Runs every handler concurrently, ignoring results. Never fails: handler\n * failures are returned so the caller can report them at its own boundary.\n */\n readonly parallel: <K extends KeysOfKind<H, \"parallel\">>(\n hook: K,\n ...args: ArgsOf<H[K]>\n ) => Effect.Effect<ReadonlyArray<PluginError>, never, ContextOf<H[K]>>\n /** Runs handlers in order until one returns `Option.some`. */\n readonly first: <K extends KeysOfKind<H, \"first\">>(\n hook: K,\n ...args: ArgsOf<H[K]>\n ) => Effect.Effect<SuccessOf<H[K]>, PluginError, ContextOf<H[K]>>\n /** Threads a value through every handler, merging each returned patch. */\n readonly waterfall: <K extends KeysOfKind<H, \"waterfall\">>(\n hook: K,\n initial: ArgsOf<H[K]>[0],\n merge: (previous: ArgsOf<H[K]>[0], patch: Exclude<SuccessOf<H[K]>, void>) => ArgsOf<H[K]>[0]\n ) => Effect.Effect<ArgsOf<H[K]>[0], PluginError, ContextOf<H[K]>>\n}\n\n/**\n * Builds a dispatcher over an already resolved plugin list.\n *\n * @category constructors\n * @since 1.0.0-rc.0\n */\nexport const make = <H = FlowsHooks>(resolved: Resolved<H>): Service<H> => {\n const handlers = (hook: string): ReadonlyArray<HandlerRecord> => resolved.handlers.get(hook) ?? empty\n\n const sequential = ((hook: string, ...args: Array<unknown>) =>\n Effect.gen(function*() {\n const mismatch = kindMismatch(resolved, hook, \"sequential\")\n if (mismatch !== undefined) return yield* Effect.fail(mismatch)\n const results: Array<unknown> = []\n for (const record of handlers(hook)) {\n results.push(yield* runHandler(record, args))\n }\n return results\n })) as Service<H>[\"sequential\"]\n\n const parallel = ((hook: string, ...args: Array<unknown>) => {\n const mismatch = kindMismatch(resolved, hook, \"parallel\")\n if (mismatch !== undefined) return Effect.succeed([mismatch])\n return Effect.forEach(\n handlers(hook),\n (record) =>\n runHandler(record, args).pipe(\n Effect.match({ onFailure: (error) => [error], onSuccess: () => [] as Array<PluginError> })\n ),\n { concurrency: resolved.parallelConcurrency }\n ).pipe(Effect.map((chunks) => chunks.flat()))\n }) as Service<H>[\"parallel\"]\n\n const first = ((hook: string, ...args: Array<unknown>) =>\n Effect.gen(function*() {\n const mismatch = kindMismatch(resolved, hook, \"first\")\n if (mismatch !== undefined) return yield* Effect.fail(mismatch)\n for (const record of handlers(hook)) {\n const result = yield* runHandler(record, args)\n if (!Option.isOption(result)) {\n return yield* Effect.fail(\n new PluginError({\n code: \"invalid_hook_result\",\n message: `first hook \"${record.hook}\" in plugin \"${record.plugin}\" did not return an Option`,\n plugin: record.plugin,\n hook: record.hook\n })\n )\n }\n if (Option.isSome(result)) return result\n }\n return Option.none()\n })) as unknown as Service<H>[\"first\"]\n\n const waterfall =\n ((hook: string, initial: unknown, merge: (previous: unknown, patch: unknown) => unknown) =>\n Effect.gen(function*() {\n const mismatch = kindMismatch(resolved, hook, \"waterfall\")\n if (mismatch !== undefined) return yield* Effect.fail(mismatch)\n let value = initial\n for (const record of handlers(hook)) {\n const patch = yield* runHandler(record, [value])\n if (patch !== undefined) {\n value = yield* Effect.try({\n try: () => merge(value, patch),\n catch: (cause) =>\n cause instanceof PluginError\n ? new PluginError({\n code: cause.code,\n message: cause.message,\n plugin: record.plugin,\n hook: record.hook,\n path: cause.path\n })\n : new PluginError({\n code: \"config_invalid\",\n message: `waterfall hook \"${record.hook}\" in plugin \"${record.plugin}\" returned an invalid patch`,\n plugin: record.plugin,\n hook: record.hook\n })\n })\n }\n }\n return value\n })) as Service<H>[\"waterfall\"]\n\n return Object.freeze({ resolved, handlers, sequential, parallel, first, waterfall })\n}\n\n/**\n * A dispatcher with no plugins at all.\n *\n * @category constructors\n * @since 1.0.0-rc.0\n */\nexport const makeNoop = <H = FlowsHooks>(): Service<H> =>\n make<H>(Object.freeze({\n plugins: Object.freeze([]),\n handlers: ImmutableMap.make<string, ReadonlyArray<HandlerRecord>>(),\n kinds: engineHooks,\n parallelConcurrency: defaultParallelConcurrency\n }))\n\n/**\n * The shared dispatcher, as a service tag.\n *\n * This tag holds one dispatcher over the process-wide augmented `FlowsHooks`.\n * `declare module \"@smthrs/plugin\"` augmentation is the supported extension\n * mechanism for values placed in the tag. A host typed against a separate hook\n * interface holds its `Service<H>` directly, as `@smthrs/agent` does, and does\n * not use this tag or its layers.\n *\n * @category context\n * @since 1.0.0-rc.0\n */\nexport class Plugins extends Context.Service<Plugins, Service>()(\"flows/plugin/Plugins\") {}\n\n/**\n * Layer providing a dispatcher over an already resolved plugin list.\n *\n * This layer targets the shared augmented `FlowsHooks` catalog only. A host\n * with a separate hook interface holds its `Service<H>` directly.\n *\n * @category layers\n * @since 1.0.0-rc.0\n */\nexport const layer = (resolved: Resolved): Layer.Layer<Plugins> => Layer.succeed(Plugins)(make(resolved))\n\n/**\n * Layer providing a dispatcher with no plugins.\n *\n * This layer targets the shared augmented `FlowsHooks` catalog only. A host\n * with a separate hook interface holds its `Service<H>` directly.\n *\n * @category layers\n * @since 1.0.0-rc.0\n */\nexport const layerNoop: Layer.Layer<Plugins> = Layer.succeed(Plugins)(makeNoop())\n"]}
1
+ {"version":3,"file":"Plugins.js","sourceRoot":"","sources":["../../src/Plugins.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,YAAY,MAAM,+BAA+B,CAAA;AAE7D,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAExC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,0BAA0B,EAAqC,MAAM,cAAc,CAAA;AAE5F,MAAM,KAAK,GAAiC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;AAE7D,6EAA6E;AAC7E,4EAA4E;AAC5E,uDAAuD;AACvD,oEAAoE;AACpE,2EAA2E;AAC3E,0CAA0C;AAC1C,MAAM,YAAY,GAAG,CACnB,QAA2B,EAC3B,IAAY,EACZ,IAAc,EACd,QAAsC,EACb,EAAE;IAC3B,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC;QACzC,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,SAAS,CAAA;QAC3C,OAAO,IAAI,WAAW,CAAC;YACrB,IAAI,EAAE,oBAAoB;YAC1B,OAAO,EAAE,SAAS,IAAI,2DAA2D;YACjF,IAAI;S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C,CAAC,QAAQ,EAAE,CAAC,CAAA","sourcesContent":["/**\n * The dispatcher: a plain service over a resolved plugin list, generic over the\n * hook interface.\n *\n * The public package contract is documented at\n * {@link https://smithers.sh/docs/reference/api/plugin}. Each host holds an instance over its\n * augmented `FlowsHooks` and may dispatch only the runtime catalog it supplied.\n * The shipped cell host owns the three\n * waterfalls declared in `packages/smithers/agent/src/CellPlugin.ts`; there is\n * no engine-wide lifecycle dispatcher.\n *\n * Cancellation is fiber interruption via scope closure; nothing here threads an\n * `AbortSignal`.\n *\n * @since 1.0.0-rc.0\n */\n\nimport * as ImmutableMap from \"@smthrs/canonical/ReadonlyMap\"\nimport type * as Cause from \"effect/Cause\"\nimport * as Context from \"effect/Context\"\nimport * as Effect from \"effect/Effect\"\nimport * as Layer from \"effect/Layer\"\nimport * as Option from \"effect/Option\"\nimport type { ArgsOf, ContextOf, HookKind, KeysOfKind, SuccessOf } from \"./Hooks.ts\"\nimport { engineHooks } from \"./Hooks.ts\"\nimport type { FlowsHooks } from \"./index.ts\"\nimport { PluginError } from \"./PluginError.ts\"\nimport { defaultParallelConcurrency, type HandlerRecord, type Resolved } from \"./Resolve.ts\"\n\nconst empty: ReadonlyArray<HandlerRecord> = Object.freeze([])\n\n// The typed catalog and the runtime catalog can only drift when a host casts\n// around `KeysOfKind`; refuse before any handler runs rather than execute a\n// hook under semantics its declaration never promised.\n// A hook the catalog does not declare dispatches as empty, unless a\n// hand-built resolution registered handlers for it: those have no declared\n// kind to honor, so they are refused too.\nconst kindMismatch = (\n resolved: Resolved<unknown>,\n hook: string,\n kind: HookKind,\n handlers: ReadonlyArray<HandlerRecord>\n): PluginError | undefined => {\n if (!Object.hasOwn(resolved.kinds, hook)) {\n if (handlers.length === 0) return undefined\n return new PluginError({\n code: \"hook_kind_mismatch\",\n message: `hook \"${hook}\" has handlers but is not declared in the runtime catalog`,\n hook\n })\n }\n const declared = resolved.kinds[hook]\n if (declared === kind) return undefined\n return new PluginError({\n code: \"hook_kind_mismatch\",\n message: `hook \"${hook}\" is declared ${JSON.stringify(declared)} in the runtime catalog but was dispatched as ${\n JSON.stringify(kind)\n }`,\n hook\n })\n}\n\nconst runHandler = (\n record: HandlerRecord,\n args: ReadonlyArray<unknown>\n): Effect.Effect<unknown, PluginError, any> => {\n const onCause = (cause: Cause.Cause<unknown>) =>\n Effect.fail(\n new PluginError({\n code: \"hook_failed\",\n message: `hook \"${record.hook}\" failed in plugin \"${record.plugin}\"`,\n plugin: record.plugin,\n hook: record.hook,\n cause\n })\n )\n\n return Effect.sync(() => record.handler(...args)).pipe(\n Effect.catchCause(onCause),\n Effect.flatMap((result) =>\n Effect.isEffect(result)\n ? result.pipe(Effect.catchCause(onCause))\n : Effect.fail(\n new PluginError({\n code: \"hook_failed\",\n message: `hook \"${record.hook}\" in plugin \"${record.plugin}\" returned a non-Effect (${typeof result})`,\n plugin: record.plugin,\n hook: record.hook\n })\n )\n )\n )\n}\n\n/**\n * The dispatch surface.\n *\n * @category models\n * @since 1.0.0-rc.0\n */\nexport interface Service<H = FlowsHooks> {\n /** The resolved list this dispatcher walks. */\n readonly resolved: Resolved<H>\n /** Frozen, ordered handler records for a hook. */\n readonly handlers: (hook: string) => ReadonlyArray<HandlerRecord>\n /** Runs every handler in resolved order, one at a time. */\n readonly sequential: <K extends KeysOfKind<H, \"sequential\">>(\n hook: K,\n ...args: ArgsOf<H[K]>\n ) => Effect.Effect<ReadonlyArray<SuccessOf<H[K]>>, PluginError, ContextOf<H[K]>>\n /**\n * Runs every handler concurrently, ignoring results. Never fails: handler\n * failures are returned so the caller can report them at its own boundary.\n */\n readonly parallel: <K extends KeysOfKind<H, \"parallel\">>(\n hook: K,\n ...args: ArgsOf<H[K]>\n ) => Effect.Effect<ReadonlyArray<PluginError>, never, ContextOf<H[K]>>\n /** Runs handlers in order until one returns `Option.some`. */\n readonly first: <K extends KeysOfKind<H, \"first\">>(\n hook: K,\n ...args: ArgsOf<H[K]>\n ) => Effect.Effect<SuccessOf<H[K]>, PluginError, ContextOf<H[K]>>\n /** Threads a value through every handler, merging each returned patch. */\n readonly waterfall: <K extends KeysOfKind<H, \"waterfall\">>(\n hook: K,\n initial: ArgsOf<H[K]>[0],\n merge: (previous: ArgsOf<H[K]>[0], patch: Exclude<SuccessOf<H[K]>, void>) => ArgsOf<H[K]>[0]\n ) => Effect.Effect<ArgsOf<H[K]>[0], PluginError, ContextOf<H[K]>>\n}\n\n/**\n * Builds a dispatcher over an already resolved plugin list.\n *\n * @category constructors\n * @since 1.0.0-rc.0\n */\nexport const make = <H = FlowsHooks>(resolved: Resolved<H>): Service<H> => {\n const handlers = (hook: string): ReadonlyArray<HandlerRecord> => resolved.handlers.get(hook) ?? empty\n\n const sequential = ((hook: string, ...args: Array<unknown>) =>\n Effect.gen(function*() {\n const mismatch = kindMismatch(resolved, hook, \"sequential\", handlers(hook))\n if (mismatch !== undefined) return yield* Effect.fail(mismatch)\n const results: Array<unknown> = []\n for (const record of handlers(hook)) {\n results.push(yield* runHandler(record, args))\n }\n return results\n })) as Service<H>[\"sequential\"]\n\n const parallel = ((hook: string, ...args: Array<unknown>) => {\n const mismatch = kindMismatch(resolved, hook, \"parallel\", handlers(hook))\n if (mismatch !== undefined) return Effect.succeed([mismatch])\n return Effect.forEach(\n handlers(hook),\n (record) =>\n runHandler(record, args).pipe(\n Effect.match({ onFailure: (error) => [error], onSuccess: () => [] as Array<PluginError> })\n ),\n { concurrency: resolved.parallelConcurrency }\n ).pipe(Effect.map((chunks) => chunks.flat()))\n }) as Service<H>[\"parallel\"]\n\n const first = ((hook: string, ...args: Array<unknown>) =>\n Effect.gen(function*() {\n const mismatch = kindMismatch(resolved, hook, \"first\", handlers(hook))\n if (mismatch !== undefined) return yield* Effect.fail(mismatch)\n for (const record of handlers(hook)) {\n const result = yield* runHandler(record, args)\n if (!Option.isOption(result)) {\n return yield* Effect.fail(\n new PluginError({\n code: \"invalid_hook_result\",\n message: `first hook \"${record.hook}\" in plugin \"${record.plugin}\" did not return an Option`,\n plugin: record.plugin,\n hook: record.hook\n })\n )\n }\n if (Option.isSome(result)) return result\n }\n return Option.none()\n })) as unknown as Service<H>[\"first\"]\n\n const waterfall =\n ((hook: string, initial: unknown, merge: (previous: unknown, patch: unknown) => unknown) =>\n Effect.gen(function*() {\n const mismatch = kindMismatch(resolved, hook, \"waterfall\", handlers(hook))\n if (mismatch !== undefined) return yield* Effect.fail(mismatch)\n let value = initial\n for (const record of handlers(hook)) {\n const patch = yield* runHandler(record, [value])\n if (patch !== undefined) {\n value = yield* Effect.try({\n try: () => merge(value, patch),\n catch: (cause) =>\n cause instanceof PluginError\n ? new PluginError({\n code: cause.code,\n message: cause.message,\n plugin: record.plugin,\n hook: record.hook,\n path: cause.path,\n cause\n })\n : new PluginError({\n code: \"config_invalid\",\n message: `waterfall hook \"${record.hook}\" in plugin \"${record.plugin}\" returned an invalid patch`,\n plugin: record.plugin,\n hook: record.hook,\n cause\n })\n })\n }\n }\n return value\n })) as Service<H>[\"waterfall\"]\n\n return Object.freeze({ resolved, handlers, sequential, parallel, first, waterfall })\n}\n\n/**\n * A dispatcher with no plugins at all.\n *\n * @category constructors\n * @since 1.0.0-rc.0\n */\nexport const makeNoop = <H = FlowsHooks>(): Service<H> =>\n make<H>(Object.freeze({\n plugins: Object.freeze([]),\n handlers: ImmutableMap.make<string, ReadonlyArray<HandlerRecord>>(),\n kinds: engineHooks,\n parallelConcurrency: defaultParallelConcurrency\n }))\n\n/**\n * The shared dispatcher, as a service tag.\n *\n * This tag holds one dispatcher over the process-wide augmented `FlowsHooks`.\n * `declare module \"@smthrs/plugin\"` augmentation is the supported extension\n * mechanism for values placed in the tag. A host typed against a separate hook\n * interface holds its `Service<H>` directly, as `@smthrs/agent` does, and does\n * not use this tag or its layers.\n *\n * @category context\n * @since 1.0.0-rc.0\n */\nexport class Plugins extends Context.Service<Plugins, Service>()(\"flows/plugin/Plugins\") {}\n\n/**\n * Layer providing a dispatcher over an already resolved plugin list.\n *\n * This layer targets the shared augmented `FlowsHooks` catalog only. A host\n * with a separate hook interface holds its `Service<H>` directly.\n *\n * @category layers\n * @since 1.0.0-rc.0\n */\nexport const layer = (resolved: Resolved): Layer.Layer<Plugins> => Layer.succeed(Plugins)(make(resolved))\n\n/**\n * Layer providing a dispatcher with no plugins.\n *\n * This layer targets the shared augmented `FlowsHooks` catalog only. A host\n * with a separate hook interface holds its `Service<H>` directly.\n *\n * @category layers\n * @since 1.0.0-rc.0\n */\nexport const layerNoop: Layer.Layer<Plugins> = Layer.succeed(Plugins)(makeNoop())\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"Resolve.d.ts","sourceRoot":"","sources":["../../src/Resolve.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAE9C,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAc,MAAM,YAAY,CAAA;AAEnE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAI5C,OAAO,KAAK,EAAS,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAClE,OAAO,EAAE,WAAW,EAAwB,MAAM,kBAAkB,CAAA;AAEpE;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,KAAK,CAAA;AAEpC;;;;;GAKG;AACH,eAAO,MAAM,cAAc,MAAM,CAAA;AAEjC;;;;;GAKG;AACH,eAAO,MAAM,eAAe,OAAQ,CAAA;AAEpC;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,OAAQ,CAAA;AAE5C;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,MAAM,CAAA;AAE1C;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,KAAK,CAAA;AAE5C;;;;;GAKG;AACH,eAA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,gBAAgB,GAAG,SAAS,CAAA;IAC/D,2EAA2E;IAC3E,QAAQ,CAAC,mBAAmB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAClD;AAqQD;;;;;GAKG;AACH,eAAO,MAAM,OAAO,GAAI,CAAC,GAAG,UAAU,EACpC,OAAO,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAC9B,UAAS,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAM,EACjC,iBAAiB,WAAW,KAC3B,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,WAAW,CAiIrC,CAAA;AAEJ;;;;;;GAMG;AACH,eAAO,MAAM,KAAK,GAAI,CAAC,EAAE,UAAU,QAAQ,CAAC,CAAC,CAAC,KAAG,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,CAClB,CAAA"}
@@ -73,23 +73,24 @@ const childPath = (path, key) => {
73
73
  const bounded = diagnosticKey(key);
74
74
  return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(bounded) ? `${path}.${bounded}` : `${path}[${JSON.stringify(bounded)}]`;
75
75
  };
76
- const ownData = (input, path, allowed) => {
76
+ const ownData = (input, path, allowed, fields = {}) => {
77
77
  if (typeof input !== "object" || input === null || Array.isArray(input)) {
78
- throw invalidPlugin(path, "must be an ordinary record");
78
+ throw invalidPlugin(path, "must be an ordinary record", fields);
79
79
  }
80
80
  const prototype = Object.getPrototypeOf(input);
81
- if (prototype !== Object.prototype && prototype !== null)
82
- throw invalidPlugin(path, "must be an ordinary record");
81
+ if (prototype !== Object.prototype && prototype !== null) {
82
+ throw invalidPlugin(path, "must be an ordinary record", fields);
83
+ }
83
84
  const output = {};
84
85
  for (const key of Reflect.ownKeys(input)) {
85
86
  if (typeof key !== "string")
86
- throw invalidPlugin(path, "must not contain symbol keys");
87
+ throw invalidPlugin(path, "must not contain symbol keys", fields);
87
88
  if (allowed !== undefined && !allowed.has(key)) {
88
- throw invalidPlugin(childPath(path, key), "contains an unknown property");
89
+ throw invalidPlugin(childPath(path, key), "contains an unknown property", fields);
89
90
  }
90
91
  const descriptor = Object.getOwnPropertyDescriptor(input, key);
91
92
  if (descriptor === undefined || !("value" in descriptor) || !descriptor.enumerable) {
92
- throw invalidPlugin(childPath(path, key), "must be an enumerable data property");
93
+ throw invalidPlugin(childPath(path, key), "must be an enumerable data property", fields);
93
94
  }
94
95
  Object.defineProperty(output, key, { value: descriptor.value, enumerable: true });
95
96
  }
@@ -142,7 +143,7 @@ const snapshotHook = (entry, path, plugin, hook) => {
142
143
  if (entry === undefined) {
143
144
  throw invalidPlugin(path, "must be a function or a hook object", { plugin, hook });
144
145
  }
145
- const values = ownData(entry, path, new Set(["order", "handler"]));
146
+ const values = ownData(entry, path, new Set(["order", "handler"]), { plugin, hook });
146
147
  if (typeof values.handler !== "function") {
147
148
  throw invalidPlugin(`${path}.handler`, "must be a function", { plugin, hook });
148
149
  }
@@ -173,11 +174,11 @@ const snapshotPlugin = (input, path) => {
173
174
  }
174
175
  let hooks;
175
176
  if (values.hooks !== undefined) {
176
- const rawHooks = ownData(values.hooks, `${path}.hooks`);
177
+ const rawHooks = ownData(values.hooks, `${path}.hooks`, undefined, { plugin: name });
177
178
  const snapshot = Object.create(null);
178
179
  for (const [index, hook] of Object.keys(rawHooks).entries()) {
179
180
  if (!validName(hook)) {
180
- throw invalidPlugin(`${path}.hooks[${index}]`, "contains an invalid hook name");
181
+ throw invalidPlugin(`${path}.hooks[${index}]`, "contains an invalid hook name", { plugin: name });
181
182
  }
182
183
  const entry = rawHooks[hook];
183
184
  Object.defineProperty(snapshot, hook, {
@@ -241,7 +242,7 @@ const flatten = (input) => {
241
242
  }
242
243
  return output;
243
244
  };
244
- const included = (plugin, config, target) => {
245
+ const included = ({ path, plugin }, config, target) => {
245
246
  const apply = plugin.apply;
246
247
  if (apply === undefined)
247
248
  return Effect.succeed(true);
@@ -249,12 +250,12 @@ const included = (plugin, config, target) => {
249
250
  return Effect.succeed(apply === target);
250
251
  return Effect.try({
251
252
  try: () => apply(config),
252
- catch: () => failure("apply_failed", `plugin "${plugin.name}" apply predicate failed`, "$.apply", {
253
+ catch: () => failure("apply_failed", `plugin "${plugin.name}" apply predicate failed`, `${path}.apply`, {
253
254
  plugin: plugin.name
254
255
  })
255
256
  }).pipe(Effect.flatMap((result) => typeof result === "boolean"
256
257
  ? Effect.succeed(result)
257
- : Effect.fail(invalidPlugin("$.apply", "predicate must return a boolean", { plugin: plugin.name }))));
258
+ : Effect.fail(invalidPlugin(`${path}.apply`, "predicate must return a boolean", { plugin: plugin.name }))));
258
259
  };
259
260
  const rank = (enforce) => (enforce === "pre" ? 0 : enforce === "post" ? 2 : 1);
260
261
  /**
@@ -299,7 +300,7 @@ export const resolve = (input, options = {}, configOverride) => Effect.gen(funct
299
300
  : invalidPlugin("$", "could not be inspected without executing user code")
300
301
  });
301
302
  const target = raw.target ?? "engine";
302
- const selected = yield* Effect.filter(admitted, ({ plugin }) => included(plugin, config, target));
303
+ const selected = yield* Effect.filter(admitted, (entry) => included(entry, config, target));
303
304
  let handlerCount = 0;
304
305
  for (const { path, plugin } of selected) {
305
306
  const pluginHooks = plugin.hooks;
@@ -316,16 +317,17 @@ export const resolve = (input, options = {}, configOverride) => Effect.gen(funct
316
317
  }
317
318
  }
318
319
  const seen = new Set();
319
- for (const { plugin } of selected) {
320
+ for (const { path, plugin } of selected) {
320
321
  if (seen.has(plugin.name)) {
321
- return yield* Effect.fail(failure("duplicate_name", `duplicate plugin name "${plugin.name}"`, "$.name", { plugin: plugin.name }));
322
+ return yield* Effect.fail(failure("duplicate_name", `duplicate plugin name "${plugin.name}"`, `${path}.name`, { plugin: plugin.name }));
322
323
  }
323
324
  seen.add(plugin.name);
324
325
  }
325
- const plugins = Object.freeze(selected
326
- .map(({ plugin }, index) => ({ plugin, index }))
327
- .sort((left, right) => rank(left.plugin.enforce) - rank(right.plugin.enforce) || left.index - right.index)
328
- .map(({ plugin }) => plugin));
326
+ const orderedEntries = selected
327
+ .map((entry, index) => ({ entry, index }))
328
+ .sort((left, right) => rank(left.entry.plugin.enforce) - rank(right.entry.plugin.enforce) || left.index - right.index)
329
+ .map(({ entry }) => entry);
330
+ const plugins = Object.freeze(orderedEntries.map(({ plugin }) => plugin));
329
331
  const entries = [];
330
332
  for (const hook of Object.keys(known)) {
331
333
  const records = [];
@@ -347,7 +349,7 @@ export const resolve = (input, options = {}, configOverride) => Effect.gen(funct
347
349
  if (ordered.length > 0)
348
350
  entries.push([hook, Object.freeze(ordered)]);
349
351
  }
350
- const cacheEnvironment = yield* snapshotCacheEnvironment(raw.cacheEnvironment, plugins);
352
+ const cacheEnvironment = yield* snapshotCacheEnvironment(raw.cacheEnvironment, orderedEntries);
351
353
  return Object.freeze({
352
354
  plugins,
353
355
  handlers: ImmutableMap.make(entries),
@@ -1 +1 @@
1
- {"version":3,"file":"Resolve.js","sourceRoot":"","sources":["../../src/Resolve.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,YAAY,MAAM,+BAA+B,CAAA;AAE7D,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAErC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAErC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAE5D,OAAO,KAAK,QAAQ,MAAM,wBAAwB,CAAA;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAA;AACnE,OAAO,EAAE,wBAAwB,EAAE,MAAM,wCAAwC,CAAA;AAEjF,OAAO,EAAE,WAAW,EAAwB,MAAM,kBAAkB,CAAA;AAEpE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,EAAE,CAAA;AAEpC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,CAAA;AAEjC;;;;;GAKG;AACH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rG;aACA,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC,CAAA;QAC9B,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC;YAAE,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;IACtE,CAAC;IACD,MAAM,gBAAgB,GAAG,KAAK,CAAC,CAAC,wBAAwB,CAAC,GAAG,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAA;IACvF,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,OAAO;QACP,QAAQ,EAAE,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC;QACpC,KAAK,EAAE,KAAK;QACZ,mBAAmB;QACnB,GAAG,CAAC,gBAAgB,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,gBAAgB,EAAE,CAAC;KAChE,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA;AAEJ;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CAAI,QAAqB,EAAsC,EAAE,CACpF,iBAAiB,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,gBAAgB,CAAC,CAAA","sourcesContent":["/**\n * Bounded plugin resolution: admit, filter, validate, order, and snapshot.\n *\n * The resulting catalog owns every record it exposes. Dispatch never reads a\n * caller-owned map, plugin record, hook object, config value, or cache identity.\n *\n * @since 1.0.0-rc.0\n */\n\nimport * as ImmutableMap from \"@smthrs/canonical/ReadonlyMap\"\nimport type { Action } from \"@smthrs/flow\"\nimport * as Effect from \"effect/Effect\"\nimport * as Layer from \"effect/Layer\"\nimport type { FlowsConfig } from \"./Config.ts\"\nimport * as Config from \"./Config.ts\"\nimport type { HookCatalog, HookKind, HookObject } from \"./Hooks.ts\"\nimport { engineHooks, handlerOf, orderOf } from \"./Hooks.ts\"\nimport type { FlowsHooks } from \"./index.ts\"\nimport * as Boundary from \"./internal/Boundary.ts\"\nimport { mergePluginLayers } from \"./internal/mergePluginLayers.ts\"\nimport { snapshotCacheEnvironment } from \"./internal/snapshotCacheEnvironment.ts\"\nimport type { Apply, FlowsPlugin, PluginInput } from \"./Plugin.ts\"\nimport { PluginError, type PluginErrorCode } from \"./PluginError.ts\"\n\n/**\n * Maximum nested preset-array depth accepted at startup.\n *\n * @category limits\n * @since 1.0.0-rc.0\n */\nexport const maximumPluginDepth = 64\n\n/**\n * Maximum plugins accepted by one kernel.\n *\n * @category limits\n * @since 1.0.0-rc.0\n */\nexport const maximumPlugins = 256\n\n/**\n * Maximum aggregate hook handlers accepted by one kernel.\n *\n * @category limits\n * @since 1.0.0-rc.0\n */\nexport const maximumHandlers = 1_024\n\n/**\n * Maximum input nodes, including arrays and omitted entries.\n *\n * @category limits\n * @since 1.0.0-rc.0\n */\nexport const maximumPluginInputNodes = 4_096\n\n/**\n * Maximum UTF-16 length of one plugin or hook name.\n *\n * @category limits\n * @since 1.0.0-rc.0\n */\nexport const maximumPluginNameLength = 256\n\n/**\n * Default fiber bound for parallel observers.\n *\n * @category limits\n * @since 1.0.0-rc.0\n */\nexport const defaultParallelConcurrency = 16\n\n/**\n * Maximum configurable parallel-observer bound.\n *\n * @category limits\n * @since 1.0.0-rc.0\n */\nexport const maximumParallelConcurrency = 256\n\n/**\n * One resolved handler with immutable attribution.\n *\n * @category models\n * @since 1.0.0-rc.0\n */\nexport interface HandlerRecord {\n readonly plugin: string\n readonly hook: string\n readonly handler: (...args: Array<any>) => unknown\n}\n\n/**\n * The immutable output of plugin resolution.\n *\n * @category models\n * @since 1.0.0-rc.0\n */\nexport interface Resolved<H = FlowsHooks> {\n readonly plugins: ReadonlyArray<FlowsPlugin<H>>\n readonly handlers: ReadonlyMap<string, ReadonlyArray<HandlerRecord>>\n /** The frozen runtime catalog this resolution admitted. Dispatch refuses a method whose kind differs from it. */\n readonly kinds: Readonly<Record<string, HookKind>>\n readonly parallelConcurrency: number\n readonly cacheEnvironment?: Action.CacheEnvironment | undefined\n}\n\n/**\n * Options for {@link resolve}.\n *\n * @category models\n * @since 1.0.0-rc.0\n */\nexport interface Options<H = FlowsHooks> {\n /** Pre-resolution config tested by `apply` predicates. */\n readonly config?: FlowsConfig | undefined\n /** Host whose literal `apply` selectors are active. Defaults to `\"engine\"`. */\n readonly target?: \"engine\" | \"harness\" | undefined\n /**\n * Hook names recognized by this host, each with the kind `H` declares for\n * it. The shared `config` and `configResolved` hooks are fixed to\n * `waterfall` and `parallel`; another kind fails with `hook_kind_mismatch`.\n */\n readonly hooks?: HookCatalog<H> | undefined\n /** Complete composition identity for sealed activity keys. Requires every selected plugin to have a version. */\n readonly cacheEnvironment?: Action.CacheEnvironment | undefined\n /** Maximum observers run at once. Defaults to 16 and cannot exceed 256. */\n readonly parallelConcurrency?: number | undefined\n}\n\ninterface RawOptions {\n readonly config: unknown\n readonly target: unknown\n readonly hooks: unknown\n readonly cacheEnvironment: unknown\n readonly parallelConcurrency: unknown\n}\n\nconst failure = (\n code: PluginErrorCode,\n message: string,\n path: string,\n fields: { readonly plugin?: string; readonly hook?: string } = {}\n): PluginError => new PluginError({ code, message, path, ...fields })\n\nconst invalidPlugin = (\n path: string,\n complaint: string,\n fields: { readonly plugin?: string; readonly hook?: string } = {}\n): PluginError => failure(\"invalid_plugin\", `plugin input ${complaint}`, path, fields)\n\n// Bound before quoting or scanning caller-controlled keys. Keep Boundary's\n// identifier/dot and JSON-quoted/bracket path convention.\nconst diagnosticKey = (key: string): string => key.length > 64 ? `${key.slice(0, 64)}...` : key\n\nconst childPath = (path: string, key: string): string => {\n const bounded = diagnosticKey(key)\n return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(bounded) ? `${path}.${bounded}` : `${path}[${JSON.stringify(bounded)}]`\n}\n\nconst ownData = (\n input: unknown,\n path: string,\n allowed?: ReadonlySet<string>\n): Readonly<Record<string, unknown>> => {\n if (typeof input !== \"object\" || input === null || Array.isArray(input)) {\n throw invalidPlugin(path, \"must be an ordinary record\")\n }\n const prototype = Object.getPrototypeOf(input)\n if (prototype !== Object.prototype && prototype !== null) throw invalidPlugin(path, \"must be an ordinary record\")\n const output: Record<string, unknown> = {}\n for (const key of Reflect.ownKeys(input)) {\n if (typeof key !== \"string\") throw invalidPlugin(path, \"must not contain symbol keys\")\n if (allowed !== undefined && !allowed.has(key)) {\n throw invalidPlugin(childPath(path, key), \"contains an unknown property\")\n }\n const descriptor = Object.getOwnPropertyDescriptor(input, key)\n if (descriptor === undefined || !(\"value\" in descriptor) || !descriptor.enumerable) {\n throw invalidPlugin(childPath(path, key), \"must be an enumerable data property\")\n }\n Object.defineProperty(output, key, { value: descriptor.value, enumerable: true })\n }\n return output\n}\n\nconst snapshotOptions = (input: unknown): RawOptions => {\n const values = ownData(\n input,\n \"$options\",\n new Set([\"config\", \"target\", \"hooks\", \"cacheEnvironment\", \"parallelConcurrency\"])\n )\n return {\n config: values.config,\n target: values.target,\n hooks: values.hooks,\n cacheEnvironment: values.cacheEnvironment,\n parallelConcurrency: values.parallelConcurrency\n }\n}\n\nconst validName = (value: unknown): value is string =>\n typeof value === \"string\" && value.length > 0 && value.length <= maximumPluginNameLength &&\n Boundary.isWellFormedText(value) && !/^\\s*$/u.test(value) && !/\\p{Cc}/u.test(value)\n\nconst snapshotCatalog = (input: unknown): Readonly<Record<string, HookKind>> => {\n if (typeof input !== \"object\" || input === null || Array.isArray(input)) {\n throw invalidPlugin(\"$options.hooks\", \"must be an ordinary hook catalog\")\n }\n const prototype = Object.getPrototypeOf(input)\n if (prototype !== Object.prototype && prototype !== null) {\n throw invalidPlugin(\"$options.hooks\", \"must be an ordinary hook catalog\")\n }\n const output: Record<string, HookKind> = {}\n for (const key of Reflect.ownKeys(input)) {\n if (typeof key !== \"string\" || !validName(key)) {\n throw invalidPlugin(\"$options.hooks\", \"contains an invalid hook name\")\n }\n const descriptor = Object.getOwnPropertyDescriptor(input, key)\n if (descriptor === undefined || !(\"value\" in descriptor) || !descriptor.enumerable) {\n throw invalidPlugin(childPath(\"$options.hooks\", key), \"must be an enumerable data property\")\n }\n if (!([\"sequential\", \"parallel\", \"first\", \"waterfall\"] as ReadonlyArray<unknown>).includes(descriptor.value)) {\n throw invalidPlugin(childPath(\"$options.hooks\", key), \"contains an invalid hook kind\")\n }\n Object.defineProperty(output, key, { value: descriptor.value, enumerable: true })\n }\n for (const hook of Object.keys(engineHooks) as ReadonlyArray<keyof typeof engineHooks>) {\n if (Object.hasOwn(output, hook) && output[hook] !== engineHooks[hook]) {\n throw failure(\n \"hook_kind_mismatch\",\n `hook catalog declares shared hook ${JSON.stringify(hook)} as ${\n JSON.stringify(output[hook])\n }, the kernel dispatches it as ${JSON.stringify(engineHooks[hook])}`,\n childPath(\"$options.hooks\", hook),\n { hook }\n )\n }\n }\n return Object.freeze(output)\n}\n\nconst snapshotHook = (\n entry: unknown,\n path: string,\n plugin: string,\n hook: string\n): ((...args: Array<any>) => unknown) | HookObject<(...args: Array<any>) => unknown> => {\n if (typeof entry === \"function\") return entry as (...args: Array<any>) => unknown\n if (entry === undefined) {\n throw invalidPlugin(path, \"must be a function or a hook object\", { plugin, hook })\n }\n const values = ownData(entry, path, new Set([\"order\", \"handler\"]))\n if (typeof values.handler !== \"function\") {\n throw invalidPlugin(`${path}.handler`, \"must be a function\", { plugin, hook })\n }\n if (values.order !== undefined && values.order !== \"pre\" && values.order !== \"post\") {\n throw invalidPlugin(`${path}.order`, \"must be pre or post\", { plugin, hook })\n }\n return Object.freeze({\n ...(values.order === undefined ? {} : { order: values.order }),\n handler: values.handler\n }) as HookObject<(...args: Array<any>) => unknown>\n}\n\nconst snapshotPlugin = <H>(\n input: unknown,\n path: string\n): FlowsPlugin<H> => {\n const values = ownData(input, path, new Set([\"name\", \"version\", \"enforce\", \"apply\", \"layer\", \"hooks\"]))\n if (!validName(values.name)) throw invalidPlugin(`${path}.name`, \"requires a bounded non-empty name\")\n const name = values.name\n if (values.version !== undefined && !validName(values.version)) {\n throw invalidPlugin(`${path}.version`, \"requires a bounded non-empty version\", { plugin: name })\n }\n if (values.enforce !== undefined && values.enforce !== \"pre\" && values.enforce !== \"post\") {\n throw invalidPlugin(`${path}.enforce`, \"must be pre or post\", { plugin: name })\n }\n if (\n values.apply !== undefined && values.apply !== \"engine\" && values.apply !== \"harness\" &&\n typeof values.apply !== \"function\"\n ) throw invalidPlugin(`${path}.apply`, \"must be engine, harness, or a predicate\", { plugin: name })\n if (values.layer !== undefined && !Layer.isLayer(values.layer)) {\n throw invalidPlugin(`${path}.layer`, \"must be an Effect Layer\", { plugin: name })\n }\n\n let hooks: Readonly<Record<string, unknown>> | undefined\n if (values.hooks !== undefined) {\n const rawHooks = ownData(values.hooks, `${path}.hooks`)\n const snapshot: Record<string, unknown> = Object.create(null)\n for (const [index, hook] of Object.keys(rawHooks).entries()) {\n if (!validName(hook)) {\n throw invalidPlugin(`${path}.hooks[${index}]`, \"contains an invalid hook name\")\n }\n const entry = rawHooks[hook]\n Object.defineProperty(snapshot, hook, {\n value: snapshotHook(entry, childPath(`${path}.hooks`, hook), name, hook),\n enumerable: true\n })\n }\n hooks = Object.freeze(snapshot)\n }\n\n return Object.freeze({\n name,\n ...(values.version === undefined ? {} : { version: values.version }),\n ...(values.enforce === undefined ? {} : { enforce: values.enforce }),\n ...(values.apply === undefined ? {} : { apply: values.apply as Apply }),\n ...(values.layer === undefined ? {} : { layer: values.layer as Layer.Layer<never, any, any> }),\n ...(hooks === undefined ? {} : { hooks: hooks as Partial<H> })\n })\n}\n\ninterface AdmittedPlugin<H> {\n readonly plugin: FlowsPlugin<H>\n readonly path: string\n}\n\nconst flatten = <H>(input: unknown): ReadonlyArray<AdmittedPlugin<H>> => {\n const output: Array<AdmittedPlugin<H>> = []\n const arrays = new WeakSet<object>()\n const stack: Array<{ readonly value: unknown; readonly path: string; readonly depth: number }> = [\n { value: input, path: \"$\", depth: 0 }\n ]\n let nodes = 0\n while (stack.length > 0) {\n const current = stack.pop()!\n nodes += 1\n if (current.value === false || current.value === null || current.value === undefined) continue\n if (Array.isArray(current.value)) {\n if (current.depth >= maximumPluginDepth) {\n throw failure(\"resource_limit\", `plugin input exceeds the depth limit of ${maximumPluginDepth}`, current.path)\n }\n if (arrays.has(current.value)) throw invalidPlugin(current.path, \"contains a cycle or repeated preset array\")\n arrays.add(current.value)\n const length = current.value.length\n // Every queued frame and array element costs a node, including omitted\n // entries. Refuse before enumerating keys, descriptors, or child frames.\n if (length > maximumPluginInputNodes - nodes - stack.length) {\n throw failure(\"resource_limit\", `plugin input exceeds the ${maximumPluginInputNodes}-node limit`, current.path)\n }\n const keys = Reflect.ownKeys(current.value)\n if (keys.length !== length + 1 || !keys.includes(\"length\")) {\n throw invalidPlugin(current.path, \"must be a dense preset array with no extra properties\")\n }\n for (let index = length - 1; index >= 0; index--) {\n const descriptor = Object.getOwnPropertyDescriptor(current.value, String(index))\n if (descriptor === undefined || !(\"value\" in descriptor) || !descriptor.enumerable) {\n throw invalidPlugin(`${current.path}[${index}]`, \"must be an enumerable data property\")\n }\n stack.push({ value: descriptor.value, path: `${current.path}[${index}]`, depth: current.depth + 1 })\n }\n continue\n }\n output.push(Object.freeze({ plugin: snapshotPlugin<H>(current.value, current.path), path: current.path }))\n if (output.length > maximumPlugins) {\n throw failure(\"resource_limit\", `plugin input exceeds the ${maximumPlugins}-plugin limit`, current.path)\n }\n }\n return output\n}\n\nconst included = <H>(\n plugin: FlowsPlugin<H>,\n config: FlowsConfig,\n target: \"engine\" | \"harness\"\n): Effect.Effect<boolean, PluginError> => {\n const apply = plugin.apply\n if (apply === undefined) return Effect.succeed(true)\n if (typeof apply !== \"function\") return Effect.succeed(apply === target)\n return Effect.try({\n try: () => apply(config),\n catch: () =>\n failure(\"apply_failed\", `plugin \"${plugin.name}\" apply predicate failed`, \"$.apply\", {\n plugin: plugin.name\n })\n }).pipe(\n Effect.flatMap((result) =>\n typeof result === \"boolean\"\n ? Effect.succeed(result)\n : Effect.fail(invalidPlugin(\"$.apply\", \"predicate must return a boolean\", { plugin: plugin.name }))\n )\n )\n}\n\nconst rank = (enforce: \"pre\" | \"post\" | undefined): number => (enforce === \"pre\" ? 0 : enforce === \"post\" ? 2 : 1)\n\n/**\n * Resolves a plugin preset into an immutable, resource-bounded catalog.\n *\n * @category constructors\n * @since 1.0.0-rc.0\n */\nexport const resolve = <H = FlowsHooks>(\n input: PluginInput<NoInfer<H>>,\n options: Options<NoInfer<H>> = {},\n configOverride?: FlowsConfig\n): Effect.Effect<Resolved<H>, PluginError> =>\n Effect.gen(function*() {\n const raw = yield* Effect.try({\n try: () => snapshotOptions(options),\n catch: (cause) =>\n cause instanceof PluginError\n ? cause\n : invalidPlugin(\"$options\", \"could not be inspected without executing user code\")\n })\n if (configOverride !== undefined && raw.config !== undefined) {\n return yield* Effect.fail(invalidPlugin(\n \"$options.config\",\n \"cannot declare config in options alongside the positional override\"\n ))\n }\n if (raw.target !== undefined && raw.target !== \"engine\" && raw.target !== \"harness\") {\n return yield* Effect.fail(invalidPlugin(\"$options.target\", \"must be engine or harness\"))\n }\n if (\n raw.parallelConcurrency !== undefined &&\n (typeof raw.parallelConcurrency !== \"number\" || !Number.isSafeInteger(raw.parallelConcurrency) ||\n raw.parallelConcurrency <= 0 ||\n raw.parallelConcurrency > maximumParallelConcurrency)\n ) {\n return yield* Effect.fail(failure(\n \"resource_limit\",\n `parallel concurrency must be between 1 and ${maximumParallelConcurrency}`,\n \"$options.parallelConcurrency\"\n ))\n }\n const parallelConcurrency = raw.parallelConcurrency === undefined\n ? defaultParallelConcurrency\n : raw.parallelConcurrency\n const config = yield* Config.snapshot(configOverride ?? raw.config ?? {})\n const known = yield* Effect.try({\n try: () => snapshotCatalog(raw.hooks ?? engineHooks),\n catch: (cause) =>\n cause instanceof PluginError\n ? cause\n : invalidPlugin(\"$options.hooks\", \"could not be inspected without executing user code\")\n })\n const admitted = yield* Effect.try({\n try: () => flatten<H>(input),\n catch: (cause) =>\n cause instanceof PluginError\n ? cause\n : invalidPlugin(\"$\", \"could not be inspected without executing user code\")\n })\n const target = raw.target ?? \"engine\"\n const selected = yield* Effect.filter(admitted, ({ plugin }) => included(plugin, config, target))\n\n let handlerCount = 0\n for (const { path, plugin } of selected) {\n const pluginHooks = plugin.hooks as Readonly<Record<string, unknown>> | undefined\n if (pluginHooks === undefined) continue\n for (const hook of Object.keys(pluginHooks)) {\n if (!Object.hasOwn(known, hook)) {\n return yield* Effect.fail(failure(\n \"unknown_hook\",\n `plugin ${JSON.stringify(plugin.name)} declares unknown hook ${JSON.stringify(diagnosticKey(hook))}`,\n childPath(`${path}.hooks`, hook),\n { plugin: plugin.name, hook }\n ))\n }\n handlerCount += 1\n if (handlerCount > maximumHandlers) {\n return yield* Effect.fail(failure(\n \"resource_limit\",\n `plugin handlers exceed the limit of ${maximumHandlers}`,\n childPath(`${path}.hooks`, hook)\n ))\n }\n }\n }\n\n const seen = new Set<string>()\n for (const { plugin } of selected) {\n if (seen.has(plugin.name)) {\n return yield* Effect.fail(failure(\n \"duplicate_name\",\n `duplicate plugin name \"${plugin.name}\"`,\n \"$.name\",\n { plugin: plugin.name }\n ))\n }\n seen.add(plugin.name)\n }\n\n const plugins = Object.freeze(\n selected\n .map(({ plugin }, index) => ({ plugin, index }))\n .sort((left, right) => rank(left.plugin.enforce) - rank(right.plugin.enforce) || left.index - right.index)\n .map(({ plugin }) => plugin)\n )\n const entries: Array<readonly [string, ReadonlyArray<HandlerRecord>]> = []\n for (const hook of Object.keys(known)) {\n const records: Array<{\n readonly record: HandlerRecord\n readonly enforceRank: number\n readonly orderRank: number\n readonly index: number\n }> = []\n for (const [index, plugin] of plugins.entries()) {\n const pluginHooks = plugin.hooks as Readonly<Record<string, unknown>> | undefined\n if (pluginHooks === undefined || !Object.hasOwn(pluginHooks, hook)) continue\n const entry = pluginHooks[hook]\n const record = Object.freeze({ plugin: plugin.name, hook, handler: handlerOf(entry) })\n records.push({ record, enforceRank: rank(plugin.enforce), orderRank: rank(orderOf(entry)), index })\n }\n // Vite's rule, verbatim: the per-hook `order` is the outer partition and\n // the enforce-sorted plugin list supplies the stable order inside it, so a\n // hook marked `order: \"pre\"` runs ahead of every normal-order handler even\n // when its plugin is `enforce: \"post\"`.\n const ordered = records\n .sort((left, right) =>\n left.orderRank - right.orderRank || left.enforceRank - right.enforceRank || left.index - right.index\n )\n .map(({ record }) => record)\n if (ordered.length > 0) entries.push([hook, Object.freeze(ordered)])\n }\n const cacheEnvironment = yield* snapshotCacheEnvironment(raw.cacheEnvironment, plugins)\n return Object.freeze({\n plugins,\n handlers: ImmutableMap.make(entries),\n kinds: known,\n parallelConcurrency,\n ...(cacheEnvironment === undefined ? {} : { cacheEnvironment })\n })\n })\n\n/**\n * Merges every resolved plugin layer left-to-right and supplies the detached\n * cache environment captured during resolution.\n *\n * @category combinators\n * @since 1.0.0-rc.0\n */\nexport const layer = <H>(resolved: Resolved<H>): Layer.Layer<any, PluginError, any> =>\n mergePluginLayers(resolved.plugins, resolved.cacheEnvironment)\n"]}
1
+ {"version":3,"file":"Resolve.js","sourceRoot":"","sources":["../../src/Resolve.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,YAAY,MAAM,+BAA+B,CAAA;AAE7D,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAErC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAErC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAE5D,OAAO,KAAK,QAAQ,MAAM,wBAAwB,CAAA;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAA;AACnE,OAAO,EAAE,wBAAwB,EAAE,MAAM,wCAAwC,CAAA;AAEjF,OAAO,EAAE,WAAW,EAAwB,MAAM,kBAAkB,CAAA;AAEpE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,EAAE,CAAA;AAEpC;;;;;GAKG;AACH,MA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AAQ,CAAC,gBAAgB,CAAC,CAAA","sourcesContent":["/**\n * Bounded plugin resolution: admit, filter, validate, order, and snapshot.\n *\n * The resulting catalog owns every record it exposes. Dispatch never reads a\n * caller-owned map, plugin record, hook object, config value, or cache identity.\n *\n * @since 1.0.0-rc.0\n */\n\nimport * as ImmutableMap from \"@smthrs/canonical/ReadonlyMap\"\nimport type { Action } from \"@smthrs/flow\"\nimport * as Effect from \"effect/Effect\"\nimport * as Layer from \"effect/Layer\"\nimport type { FlowsConfig } from \"./Config.ts\"\nimport * as Config from \"./Config.ts\"\nimport type { HookCatalog, HookKind, HookObject } from \"./Hooks.ts\"\nimport { engineHooks, handlerOf, orderOf } from \"./Hooks.ts\"\nimport type { FlowsHooks } from \"./index.ts\"\nimport * as Boundary from \"./internal/Boundary.ts\"\nimport { mergePluginLayers } from \"./internal/mergePluginLayers.ts\"\nimport { snapshotCacheEnvironment } from \"./internal/snapshotCacheEnvironment.ts\"\nimport type { Apply, FlowsPlugin, PluginInput } from \"./Plugin.ts\"\nimport { PluginError, type PluginErrorCode } from \"./PluginError.ts\"\n\n/**\n * Maximum nested preset-array depth accepted at startup.\n *\n * @category limits\n * @since 1.0.0-rc.0\n */\nexport const maximumPluginDepth = 64\n\n/**\n * Maximum plugins accepted by one kernel.\n *\n * @category limits\n * @since 1.0.0-rc.0\n */\nexport const maximumPlugins = 256\n\n/**\n * Maximum aggregate hook handlers accepted by one kernel.\n *\n * @category limits\n * @since 1.0.0-rc.0\n */\nexport const maximumHandlers = 1_024\n\n/**\n * Maximum input nodes, including arrays and omitted entries.\n *\n * @category limits\n * @since 1.0.0-rc.0\n */\nexport const maximumPluginInputNodes = 4_096\n\n/**\n * Maximum UTF-16 length of one plugin or hook name.\n *\n * @category limits\n * @since 1.0.0-rc.0\n */\nexport const maximumPluginNameLength = 256\n\n/**\n * Default fiber bound for parallel observers.\n *\n * @category limits\n * @since 1.0.0-rc.0\n */\nexport const defaultParallelConcurrency = 16\n\n/**\n * Maximum configurable parallel-observer bound.\n *\n * @category limits\n * @since 1.0.0-rc.0\n */\nexport const maximumParallelConcurrency = 256\n\n/**\n * One resolved handler with immutable attribution.\n *\n * @category models\n * @since 1.0.0-rc.0\n */\nexport interface HandlerRecord {\n readonly plugin: string\n readonly hook: string\n readonly handler: (...args: Array<any>) => unknown\n}\n\n/**\n * The immutable output of plugin resolution.\n *\n * @category models\n * @since 1.0.0-rc.0\n */\nexport interface Resolved<H = FlowsHooks> {\n readonly plugins: ReadonlyArray<FlowsPlugin<H>>\n readonly handlers: ReadonlyMap<string, ReadonlyArray<HandlerRecord>>\n /** The frozen runtime catalog this resolution admitted. Dispatch refuses a method whose kind differs from it. */\n readonly kinds: Readonly<Record<string, HookKind>>\n readonly parallelConcurrency: number\n readonly cacheEnvironment?: Action.CacheEnvironment | undefined\n}\n\n/**\n * Options for {@link resolve}.\n *\n * @category models\n * @since 1.0.0-rc.0\n */\nexport interface Options<H = FlowsHooks> {\n /** Pre-resolution config tested by `apply` predicates. */\n readonly config?: FlowsConfig | undefined\n /** Host whose literal `apply` selectors are active. Defaults to `\"engine\"`. */\n readonly target?: \"engine\" | \"harness\" | undefined\n /**\n * Hook names recognized by this host, each with the kind `H` declares for\n * it. The shared `config` and `configResolved` hooks are fixed to\n * `waterfall` and `parallel`; another kind fails with `hook_kind_mismatch`.\n */\n readonly hooks?: HookCatalog<H> | undefined\n /** Complete composition identity for sealed activity keys. Requires every selected plugin to have a version. */\n readonly cacheEnvironment?: Action.CacheEnvironment | undefined\n /** Maximum observers run at once. Defaults to 16 and cannot exceed 256. */\n readonly parallelConcurrency?: number | undefined\n}\n\ninterface RawOptions {\n readonly config: unknown\n readonly target: unknown\n readonly hooks: unknown\n readonly cacheEnvironment: unknown\n readonly parallelConcurrency: unknown\n}\n\nconst failure = (\n code: PluginErrorCode,\n message: string,\n path: string,\n fields: { readonly plugin?: string; readonly hook?: string } = {}\n): PluginError => new PluginError({ code, message, path, ...fields })\n\nconst invalidPlugin = (\n path: string,\n complaint: string,\n fields: { readonly plugin?: string; readonly hook?: string } = {}\n): PluginError => failure(\"invalid_plugin\", `plugin input ${complaint}`, path, fields)\n\n// Bound before quoting or scanning caller-controlled keys. Keep Boundary's\n// identifier/dot and JSON-quoted/bracket path convention.\nconst diagnosticKey = (key: string): string => key.length > 64 ? `${key.slice(0, 64)}...` : key\n\nconst childPath = (path: string, key: string): string => {\n const bounded = diagnosticKey(key)\n return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(bounded) ? `${path}.${bounded}` : `${path}[${JSON.stringify(bounded)}]`\n}\n\nconst ownData = (\n input: unknown,\n path: string,\n allowed?: ReadonlySet<string>,\n fields: { readonly plugin?: string; readonly hook?: string } = {}\n): Readonly<Record<string, unknown>> => {\n if (typeof input !== \"object\" || input === null || Array.isArray(input)) {\n throw invalidPlugin(path, \"must be an ordinary record\", fields)\n }\n const prototype = Object.getPrototypeOf(input)\n if (prototype !== Object.prototype && prototype !== null) {\n throw invalidPlugin(path, \"must be an ordinary record\", fields)\n }\n const output: Record<string, unknown> = {}\n for (const key of Reflect.ownKeys(input)) {\n if (typeof key !== \"string\") throw invalidPlugin(path, \"must not contain symbol keys\", fields)\n if (allowed !== undefined && !allowed.has(key)) {\n throw invalidPlugin(childPath(path, key), \"contains an unknown property\", fields)\n }\n const descriptor = Object.getOwnPropertyDescriptor(input, key)\n if (descriptor === undefined || !(\"value\" in descriptor) || !descriptor.enumerable) {\n throw invalidPlugin(childPath(path, key), \"must be an enumerable data property\", fields)\n }\n Object.defineProperty(output, key, { value: descriptor.value, enumerable: true })\n }\n return output\n}\n\nconst snapshotOptions = (input: unknown): RawOptions => {\n const values = ownData(\n input,\n \"$options\",\n new Set([\"config\", \"target\", \"hooks\", \"cacheEnvironment\", \"parallelConcurrency\"])\n )\n return {\n config: values.config,\n target: values.target,\n hooks: values.hooks,\n cacheEnvironment: values.cacheEnvironment,\n parallelConcurrency: values.parallelConcurrency\n }\n}\n\nconst validName = (value: unknown): value is string =>\n typeof value === \"string\" && value.length > 0 && value.length <= maximumPluginNameLength &&\n Boundary.isWellFormedText(value) && !/^\\s*$/u.test(value) && !/\\p{Cc}/u.test(value)\n\nconst snapshotCatalog = (input: unknown): Readonly<Record<string, HookKind>> => {\n if (typeof input !== \"object\" || input === null || Array.isArray(input)) {\n throw invalidPlugin(\"$options.hooks\", \"must be an ordinary hook catalog\")\n }\n const prototype = Object.getPrototypeOf(input)\n if (prototype !== Object.prototype && prototype !== null) {\n throw invalidPlugin(\"$options.hooks\", \"must be an ordinary hook catalog\")\n }\n const output: Record<string, HookKind> = {}\n for (const key of Reflect.ownKeys(input)) {\n if (typeof key !== \"string\" || !validName(key)) {\n throw invalidPlugin(\"$options.hooks\", \"contains an invalid hook name\")\n }\n const descriptor = Object.getOwnPropertyDescriptor(input, key)\n if (descriptor === undefined || !(\"value\" in descriptor) || !descriptor.enumerable) {\n throw invalidPlugin(childPath(\"$options.hooks\", key), \"must be an enumerable data property\")\n }\n if (!([\"sequential\", \"parallel\", \"first\", \"waterfall\"] as ReadonlyArray<unknown>).includes(descriptor.value)) {\n throw invalidPlugin(childPath(\"$options.hooks\", key), \"contains an invalid hook kind\")\n }\n Object.defineProperty(output, key, { value: descriptor.value, enumerable: true })\n }\n for (const hook of Object.keys(engineHooks) as ReadonlyArray<keyof typeof engineHooks>) {\n if (Object.hasOwn(output, hook) && output[hook] !== engineHooks[hook]) {\n throw failure(\n \"hook_kind_mismatch\",\n `hook catalog declares shared hook ${JSON.stringify(hook)} as ${\n JSON.stringify(output[hook])\n }, the kernel dispatches it as ${JSON.stringify(engineHooks[hook])}`,\n childPath(\"$options.hooks\", hook),\n { hook }\n )\n }\n }\n return Object.freeze(output)\n}\n\nconst snapshotHook = (\n entry: unknown,\n path: string,\n plugin: string,\n hook: string\n): ((...args: Array<any>) => unknown) | HookObject<(...args: Array<any>) => unknown> => {\n if (typeof entry === \"function\") return entry as (...args: Array<any>) => unknown\n if (entry === undefined) {\n throw invalidPlugin(path, \"must be a function or a hook object\", { plugin, hook })\n }\n const values = ownData(entry, path, new Set([\"order\", \"handler\"]), { plugin, hook })\n if (typeof values.handler !== \"function\") {\n throw invalidPlugin(`${path}.handler`, \"must be a function\", { plugin, hook })\n }\n if (values.order !== undefined && values.order !== \"pre\" && values.order !== \"post\") {\n throw invalidPlugin(`${path}.order`, \"must be pre or post\", { plugin, hook })\n }\n return Object.freeze({\n ...(values.order === undefined ? {} : { order: values.order }),\n handler: values.handler\n }) as HookObject<(...args: Array<any>) => unknown>\n}\n\nconst snapshotPlugin = <H>(\n input: unknown,\n path: string\n): FlowsPlugin<H> => {\n const values = ownData(input, path, new Set([\"name\", \"version\", \"enforce\", \"apply\", \"layer\", \"hooks\"]))\n if (!validName(values.name)) throw invalidPlugin(`${path}.name`, \"requires a bounded non-empty name\")\n const name = values.name\n if (values.version !== undefined && !validName(values.version)) {\n throw invalidPlugin(`${path}.version`, \"requires a bounded non-empty version\", { plugin: name })\n }\n if (values.enforce !== undefined && values.enforce !== \"pre\" && values.enforce !== \"post\") {\n throw invalidPlugin(`${path}.enforce`, \"must be pre or post\", { plugin: name })\n }\n if (\n values.apply !== undefined && values.apply !== \"engine\" && values.apply !== \"harness\" &&\n typeof values.apply !== \"function\"\n ) throw invalidPlugin(`${path}.apply`, \"must be engine, harness, or a predicate\", { plugin: name })\n if (values.layer !== undefined && !Layer.isLayer(values.layer)) {\n throw invalidPlugin(`${path}.layer`, \"must be an Effect Layer\", { plugin: name })\n }\n\n let hooks: Readonly<Record<string, unknown>> | undefined\n if (values.hooks !== undefined) {\n const rawHooks = ownData(values.hooks, `${path}.hooks`, undefined, { plugin: name })\n const snapshot: Record<string, unknown> = Object.create(null)\n for (const [index, hook] of Object.keys(rawHooks).entries()) {\n if (!validName(hook)) {\n throw invalidPlugin(`${path}.hooks[${index}]`, \"contains an invalid hook name\", { plugin: name })\n }\n const entry = rawHooks[hook]\n Object.defineProperty(snapshot, hook, {\n value: snapshotHook(entry, childPath(`${path}.hooks`, hook), name, hook),\n enumerable: true\n })\n }\n hooks = Object.freeze(snapshot)\n }\n\n return Object.freeze({\n name,\n ...(values.version === undefined ? {} : { version: values.version }),\n ...(values.enforce === undefined ? {} : { enforce: values.enforce }),\n ...(values.apply === undefined ? {} : { apply: values.apply as Apply }),\n ...(values.layer === undefined ? {} : { layer: values.layer as Layer.Layer<never, any, any> }),\n ...(hooks === undefined ? {} : { hooks: hooks as Partial<H> })\n })\n}\n\ninterface AdmittedPlugin<H> {\n readonly plugin: FlowsPlugin<H>\n readonly path: string\n}\n\nconst flatten = <H>(input: unknown): ReadonlyArray<AdmittedPlugin<H>> => {\n const output: Array<AdmittedPlugin<H>> = []\n const arrays = new WeakSet<object>()\n const stack: Array<{ readonly value: unknown; readonly path: string; readonly depth: number }> = [\n { value: input, path: \"$\", depth: 0 }\n ]\n let nodes = 0\n while (stack.length > 0) {\n const current = stack.pop()!\n nodes += 1\n if (current.value === false || current.value === null || current.value === undefined) continue\n if (Array.isArray(current.value)) {\n if (current.depth >= maximumPluginDepth) {\n throw failure(\"resource_limit\", `plugin input exceeds the depth limit of ${maximumPluginDepth}`, current.path)\n }\n if (arrays.has(current.value)) throw invalidPlugin(current.path, \"contains a cycle or repeated preset array\")\n arrays.add(current.value)\n const length = current.value.length\n // Every queued frame and array element costs a node, including omitted\n // entries. Refuse before enumerating keys, descriptors, or child frames.\n if (length > maximumPluginInputNodes - nodes - stack.length) {\n throw failure(\"resource_limit\", `plugin input exceeds the ${maximumPluginInputNodes}-node limit`, current.path)\n }\n const keys = Reflect.ownKeys(current.value)\n if (keys.length !== length + 1 || !keys.includes(\"length\")) {\n throw invalidPlugin(current.path, \"must be a dense preset array with no extra properties\")\n }\n for (let index = length - 1; index >= 0; index--) {\n const descriptor = Object.getOwnPropertyDescriptor(current.value, String(index))\n if (descriptor === undefined || !(\"value\" in descriptor) || !descriptor.enumerable) {\n throw invalidPlugin(`${current.path}[${index}]`, \"must be an enumerable data property\")\n }\n stack.push({ value: descriptor.value, path: `${current.path}[${index}]`, depth: current.depth + 1 })\n }\n continue\n }\n output.push(Object.freeze({ plugin: snapshotPlugin<H>(current.value, current.path), path: current.path }))\n if (output.length > maximumPlugins) {\n throw failure(\"resource_limit\", `plugin input exceeds the ${maximumPlugins}-plugin limit`, current.path)\n }\n }\n return output\n}\n\nconst included = <H>(\n { path, plugin }: AdmittedPlugin<H>,\n config: FlowsConfig,\n target: \"engine\" | \"harness\"\n): Effect.Effect<boolean, PluginError> => {\n const apply = plugin.apply\n if (apply === undefined) return Effect.succeed(true)\n if (typeof apply !== \"function\") return Effect.succeed(apply === target)\n return Effect.try({\n try: () => apply(config),\n catch: () =>\n failure(\"apply_failed\", `plugin \"${plugin.name}\" apply predicate failed`, `${path}.apply`, {\n plugin: plugin.name\n })\n }).pipe(\n Effect.flatMap((result) =>\n typeof result === \"boolean\"\n ? Effect.succeed(result)\n : Effect.fail(invalidPlugin(`${path}.apply`, \"predicate must return a boolean\", { plugin: plugin.name }))\n )\n )\n}\n\nconst rank = (enforce: \"pre\" | \"post\" | undefined): number => (enforce === \"pre\" ? 0 : enforce === \"post\" ? 2 : 1)\n\n/**\n * Resolves a plugin preset into an immutable, resource-bounded catalog.\n *\n * @category constructors\n * @since 1.0.0-rc.0\n */\nexport const resolve = <H = FlowsHooks>(\n input: PluginInput<NoInfer<H>>,\n options: Options<NoInfer<H>> = {},\n configOverride?: FlowsConfig\n): Effect.Effect<Resolved<H>, PluginError> =>\n Effect.gen(function*() {\n const raw = yield* Effect.try({\n try: () => snapshotOptions(options),\n catch: (cause) =>\n cause instanceof PluginError\n ? cause\n : invalidPlugin(\"$options\", \"could not be inspected without executing user code\")\n })\n if (configOverride !== undefined && raw.config !== undefined) {\n return yield* Effect.fail(invalidPlugin(\n \"$options.config\",\n \"cannot declare config in options alongside the positional override\"\n ))\n }\n if (raw.target !== undefined && raw.target !== \"engine\" && raw.target !== \"harness\") {\n return yield* Effect.fail(invalidPlugin(\"$options.target\", \"must be engine or harness\"))\n }\n if (\n raw.parallelConcurrency !== undefined &&\n (typeof raw.parallelConcurrency !== \"number\" || !Number.isSafeInteger(raw.parallelConcurrency) ||\n raw.parallelConcurrency <= 0 ||\n raw.parallelConcurrency > maximumParallelConcurrency)\n ) {\n return yield* Effect.fail(failure(\n \"resource_limit\",\n `parallel concurrency must be between 1 and ${maximumParallelConcurrency}`,\n \"$options.parallelConcurrency\"\n ))\n }\n const parallelConcurrency = raw.parallelConcurrency === undefined\n ? defaultParallelConcurrency\n : raw.parallelConcurrency\n const config = yield* Config.snapshot(configOverride ?? raw.config ?? {})\n const known = yield* Effect.try({\n try: () => snapshotCatalog(raw.hooks ?? engineHooks),\n catch: (cause) =>\n cause instanceof PluginError\n ? cause\n : invalidPlugin(\"$options.hooks\", \"could not be inspected without executing user code\")\n })\n const admitted = yield* Effect.try({\n try: () => flatten<H>(input),\n catch: (cause) =>\n cause instanceof PluginError\n ? cause\n : invalidPlugin(\"$\", \"could not be inspected without executing user code\")\n })\n const target = raw.target ?? \"engine\"\n const selected = yield* Effect.filter(admitted, (entry) => included(entry, config, target))\n\n let handlerCount = 0\n for (const { path, plugin } of selected) {\n const pluginHooks = plugin.hooks as Readonly<Record<string, unknown>> | undefined\n if (pluginHooks === undefined) continue\n for (const hook of Object.keys(pluginHooks)) {\n if (!Object.hasOwn(known, hook)) {\n return yield* Effect.fail(failure(\n \"unknown_hook\",\n `plugin ${JSON.stringify(plugin.name)} declares unknown hook ${JSON.stringify(diagnosticKey(hook))}`,\n childPath(`${path}.hooks`, hook),\n { plugin: plugin.name, hook }\n ))\n }\n handlerCount += 1\n if (handlerCount > maximumHandlers) {\n return yield* Effect.fail(failure(\n \"resource_limit\",\n `plugin handlers exceed the limit of ${maximumHandlers}`,\n childPath(`${path}.hooks`, hook)\n ))\n }\n }\n }\n\n const seen = new Set<string>()\n for (const { path, plugin } of selected) {\n if (seen.has(plugin.name)) {\n return yield* Effect.fail(failure(\n \"duplicate_name\",\n `duplicate plugin name \"${plugin.name}\"`,\n `${path}.name`,\n { plugin: plugin.name }\n ))\n }\n seen.add(plugin.name)\n }\n\n const orderedEntries = selected\n .map((entry, index) => ({ entry, index }))\n .sort((left, right) =>\n rank(left.entry.plugin.enforce) - rank(right.entry.plugin.enforce) || left.index - right.index\n )\n .map(({ entry }) => entry)\n const plugins = Object.freeze(orderedEntries.map(({ plugin }) => plugin))\n const entries: Array<readonly [string, ReadonlyArray<HandlerRecord>]> = []\n for (const hook of Object.keys(known)) {\n const records: Array<{\n readonly record: HandlerRecord\n readonly enforceRank: number\n readonly orderRank: number\n readonly index: number\n }> = []\n for (const [index, plugin] of plugins.entries()) {\n const pluginHooks = plugin.hooks as Readonly<Record<string, unknown>> | undefined\n if (pluginHooks === undefined || !Object.hasOwn(pluginHooks, hook)) continue\n const entry = pluginHooks[hook]\n const record = Object.freeze({ plugin: plugin.name, hook, handler: handlerOf(entry) })\n records.push({ record, enforceRank: rank(plugin.enforce), orderRank: rank(orderOf(entry)), index })\n }\n // Vite's rule, verbatim: the per-hook `order` is the outer partition and\n // the enforce-sorted plugin list supplies the stable order inside it, so a\n // hook marked `order: \"pre\"` runs ahead of every normal-order handler even\n // when its plugin is `enforce: \"post\"`.\n const ordered = records\n .sort((left, right) =>\n left.orderRank - right.orderRank || left.enforceRank - right.enforceRank || left.index - right.index\n )\n .map(({ record }) => record)\n if (ordered.length > 0) entries.push([hook, Object.freeze(ordered)])\n }\n const cacheEnvironment = yield* snapshotCacheEnvironment(raw.cacheEnvironment, orderedEntries)\n return Object.freeze({\n plugins,\n handlers: ImmutableMap.make(entries),\n kinds: known,\n parallelConcurrency,\n ...(cacheEnvironment === undefined ? {} : { cacheEnvironment })\n })\n })\n\n/**\n * Merges every resolved plugin layer left-to-right and supplies the detached\n * cache environment captured during resolution.\n *\n * @category combinators\n * @since 1.0.0-rc.0\n */\nexport const layer = <H>(resolved: Resolved<H>): Layer.Layer<any, PluginError, any> =>\n mergePluginLayers(resolved.plugins, resolved.cacheEnvironment)\n"]}
@@ -10,10 +10,14 @@ import type { FlowsPlugin } from "../Plugin.ts";
10
10
  import { PluginError } from "../PluginError.ts";
11
11
  /**
12
12
  * Admits a caller cache environment and prepends one escaped `name@version`
13
- * identity per plugin, in resolved order. An absent input stays absent.
13
+ * identity per plugin, in resolved order. An absent input stays absent. A
14
+ * versionless plugin is refused at the dollar-path it was admitted from.
14
15
  *
15
16
  * @private
16
17
  * @since 1.0.0-rc.0
17
18
  */
18
- export declare const snapshotCacheEnvironment: <H>(input: unknown, plugins: ReadonlyArray<FlowsPlugin<H>>) => Effect.Effect<Action.CacheEnvironment | undefined, PluginError>;
19
+ export declare const snapshotCacheEnvironment: <H>(input: unknown, plugins: ReadonlyArray<{
20
+ readonly plugin: FlowsPlugin<H>;
21
+ readonly path: string;
22
+ }>) => Effect.Effect<Action.CacheEnvironment | undefined, PluginError>;
19
23
  //# sourceMappingURL=snapshotCacheEnvironment.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"snapshotCacheEnvironment.d.ts","sourceRoot":"","sources":["../../../src/internal/snapshotCacheEnvironment.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAO/C;;;;;;GAMG;AACH,eAAO,MAAM,wBAAwB,GAAI,CAAC,EACxC,OAAO,OAAO,EACd,SAAS,aAAa,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,KACrC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,gBAAgB,GAAG,SAAS,EAAE,WAAW,CAgDhE,CAAA"}
1
+ {"version":3,"file":"snapshotCacheEnvironment.d.ts","sourceRoot":"","sources":["../../../src/internal/snapshotCacheEnvironment.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAO/C;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB,GAAI,CAAC,EACxC,OAAO,OAAO,EACd,SAAS,aAAa,CAAC;IAAE,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,KACjF,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,gBAAgB,GAAG,SAAS,EAAE,WAAW,CAgDhE,CAAA"}
@@ -14,7 +14,8 @@ const escapePluginIdentityPart = (value) =>
14
14
  value.replaceAll("%", "%25").replaceAll("@", "%40");
15
15
  /**
16
16
  * Admits a caller cache environment and prepends one escaped `name@version`
17
- * identity per plugin, in resolved order. An absent input stays absent.
17
+ * identity per plugin, in resolved order. An absent input stays absent. A
18
+ * versionless plugin is refused at the dollar-path it was admitted from.
18
19
  *
19
20
  * @private
20
21
  * @since 1.0.0-rc.0
@@ -23,12 +24,12 @@ export const snapshotCacheEnvironment = (input, plugins) => {
23
24
  if (input === undefined)
24
25
  return Effect.succeed(undefined);
25
26
  const pluginIdentities = [];
26
- for (const plugin of plugins) {
27
+ for (const { path, plugin } of plugins) {
27
28
  if (plugin.version === undefined) {
28
29
  return Effect.fail(new PluginError({
29
30
  code: "cache_environment_invalid",
30
31
  message: `cache environment requires a version for plugin "${plugin.name}"`,
31
- path: "$.version",
32
+ path: `${path}.version`,
32
33
  plugin: plugin.name
33
34
  }));
34
35
  }
@@ -1 +1 @@
1
- {"version":3,"file":"snapshotCacheEnvironment.js","sourceRoot":"","sources":["../../../src/internal/snapshotCacheEnvironment.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,E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,WAAW,CAAC;YACd,IAAI,EAAE,2BAA2B;YACjC,OAAO,EAAE,qBAAqB,QAAQ,CAAC,SAAS,EAAE;YAClD,IAAI,EAAE,4BAA4B,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;SAC3D,CAAC,CACH,CAAA;IACH,CAAC;IACD,OAAO,MAAM,CAAC,mBAAmB,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,IAAI,CAC7E,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,CACnB,IAAI,WAAW,CAAC;QACd,IAAI,EAAE,2BAA2B;QACjC,OAAO,EAAE,qEAAqE;QAC9E,IAAI,EAAE,2BAA2B;KAClC,CAAC,CACH,EACD,MAAM,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,EAAE;QACzB,MAAM,YAAY,GAA0C,EAAE,CAAA;QAC9D,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,EAAE,CAAC;YACzD,MAAM,CAAC,cAAc,CAAC,YAAY,EAAE,IAAI,EAAE;gBACxC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,WAAW,CAAC,YAAY,CAAC,IAAI,CAAE,CAAC,CAAC;gBAC1D,UAAU,EAAE,IAAI;aACjB,CAAC,CAAA;QACJ,CAAC;QACD,OAAO,MAAM,CAAC,MAAM,CAAC;YACnB,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,gBAAgB,EAAE,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;YACnE,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC;SAC1C,CAAC,CAAA;IACJ,CAAC,CAAC,CACH,CAAA;AACH,CAAC,CAAA","sourcesContent":["/**\n * Cache identity admission for a resolved plugin list.\n *\n * @private\n * @since 1.0.0-rc.0\n */\n\nimport { Action } from \"@smthrs/flow\"\nimport * as Effect from \"effect/Effect\"\nimport * as Schema from \"effect/Schema\"\nimport type { FlowsPlugin } from \"../Plugin.ts\"\nimport { PluginError } from \"../PluginError.ts\"\nimport * as Boundary from \"./Boundary.ts\"\n\nconst escapePluginIdentityPart = (value: string): string =>\n // Percent must be escaped first so literal escape-looking text remains distinct from the `@` escape added next.\n value.replaceAll(\"%\", \"%25\").replaceAll(\"@\", \"%40\")\n\n/**\n * Admits a caller cache environment and prepends one escaped `name@version`\n * identity per plugin, in resolved order. An absent input stays absent.\n *\n * @private\n * @since 1.0.0-rc.0\n */\nexport const snapshotCacheEnvironment = <H>(\n input: unknown,\n plugins: ReadonlyArray<FlowsPlugin<H>>\n): Effect.Effect<Action.CacheEnvironment | undefined, PluginError> => {\n if (input === undefined) return Effect.succeed(undefined)\n const pluginIdentities: Array<string> = []\n for (const plugin of plugins) {\n if (plugin.version === undefined) {\n return Effect.fail(\n new PluginError({\n code: \"cache_environment_invalid\",\n message: `cache environment requires a version for plugin \"${plugin.name}\"`,\n path: \"$.version\",\n plugin: plugin.name\n })\n )\n }\n pluginIdentities.push(`${escapePluginIdentityPart(plugin.name)}@${escapePluginIdentityPart(plugin.version)}`)\n }\n const admitted = Boundary.record(input)\n if (!admitted.ok) {\n return Effect.fail(\n new PluginError({\n code: \"cache_environment_invalid\",\n message: `cache environment ${admitted.complaint}`,\n path: `$options.cacheEnvironment${admitted.path.slice(1)}`\n })\n )\n }\n return Schema.decodeUnknownEffect(Action.CacheEnvironment)(admitted.value).pipe(\n Effect.mapError(() =>\n new PluginError({\n code: \"cache_environment_invalid\",\n message: \"cache environment does not match the complete cache identity schema\",\n path: \"$options.cacheEnvironment\"\n })\n ),\n Effect.map((environment) => {\n const capabilities: Record<string, ReadonlyArray<string>> = {}\n for (const name of Object.keys(environment.capabilities)) {\n Object.defineProperty(capabilities, name, {\n value: Object.freeze([...environment.capabilities[name]!]),\n enumerable: true\n })\n }\n return Object.freeze({\n layers: Object.freeze([...pluginIdentities, ...environment.layers]),\n capabilities: Object.freeze(capabilities)\n })\n })\n )\n}\n"]}
1
+ {"version":3,"file":"snapshotCacheEnvironment.js","sourceRoot":"","sources":["../../../src/internal/snapshotCacheEnvironment.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AAEzC,MAAM,wBAAwB,GAAG,CAAC,KAAa,EAAU,EAAE;AACzD,gHAAgH;AAChH,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;AAErD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CACtC,KAAc,EACd,OAAkF,EACjB,EAAE;IACnE,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;IACzD,MAAM,gBAAgB,GAAkB,EAAE,CAAA;IAC1C,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,OAAO,EAAE,CAAC;QACvC,IAAI,MAAM,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;YACjC,OAAO,MAAM,CAAC,IAAI,CAChB,IAAI,WAAW,CAAC;gBACd,IAAI,EAAE,2BAA2B;gBACjC,OAAO,EAAE,oDAAoD,MAAM,CAAC,IAAI,GAAG;gBAC3E,IAAI,EAAE,GAAG,IAAI,UAAU;gBACvB,MAAM,EAAE,MAAM,CAAC,IAAI;aACpB,CAAC,CACH,CAAA;QACH,CAAC;QACD,gBAAgB,CAAC,IAAI,CAAC,GAAG,wBAAwB,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,wBAAwB,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;YACnE,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC;SAC1C,CAAC,CAAA;IACJ,CAAC,CAAC,CACH,CAAA;AACH,CAAC,CAAA","sourcesContent":["/**\n * Cache identity admission for a resolved plugin list.\n *\n * @private\n * @since 1.0.0-rc.0\n */\n\nimport { Action } from \"@smthrs/flow\"\nimport * as Effect from \"effect/Effect\"\nimport * as Schema from \"effect/Schema\"\nimport type { FlowsPlugin } from \"../Plugin.ts\"\nimport { PluginError } from \"../PluginError.ts\"\nimport * as Boundary from \"./Boundary.ts\"\n\nconst escapePluginIdentityPart = (value: string): string =>\n // Percent must be escaped first so literal escape-looking text remains distinct from the `@` escape added next.\n value.replaceAll(\"%\", \"%25\").replaceAll(\"@\", \"%40\")\n\n/**\n * Admits a caller cache environment and prepends one escaped `name@version`\n * identity per plugin, in resolved order. An absent input stays absent. A\n * versionless plugin is refused at the dollar-path it was admitted from.\n *\n * @private\n * @since 1.0.0-rc.0\n */\nexport const snapshotCacheEnvironment = <H>(\n input: unknown,\n plugins: ReadonlyArray<{ readonly plugin: FlowsPlugin<H>; readonly path: string }>\n): Effect.Effect<Action.CacheEnvironment | undefined, PluginError> => {\n if (input === undefined) return Effect.succeed(undefined)\n const pluginIdentities: Array<string> = []\n for (const { path, plugin } of plugins) {\n if (plugin.version === undefined) {\n return Effect.fail(\n new PluginError({\n code: \"cache_environment_invalid\",\n message: `cache environment requires a version for plugin \"${plugin.name}\"`,\n path: `${path}.version`,\n plugin: plugin.name\n })\n )\n }\n pluginIdentities.push(`${escapePluginIdentityPart(plugin.name)}@${escapePluginIdentityPart(plugin.version)}`)\n }\n const admitted = Boundary.record(input)\n if (!admitted.ok) {\n return Effect.fail(\n new PluginError({\n code: \"cache_environment_invalid\",\n message: `cache environment ${admitted.complaint}`,\n path: `$options.cacheEnvironment${admitted.path.slice(1)}`\n })\n )\n }\n return Schema.decodeUnknownEffect(Action.CacheEnvironment)(admitted.value).pipe(\n Effect.mapError(() =>\n new PluginError({\n code: \"cache_environment_invalid\",\n message: \"cache environment does not match the complete cache identity schema\",\n path: \"$options.cacheEnvironment\"\n })\n ),\n Effect.map((environment) => {\n const capabilities: Record<string, ReadonlyArray<string>> = {}\n for (const name of Object.keys(environment.capabilities)) {\n Object.defineProperty(capabilities, name, {\n value: Object.freeze([...environment.capabilities[name]!]),\n enumerable: true\n })\n }\n return Object.freeze({\n layers: Object.freeze([...pluginIdentities, ...environment.layers]),\n capabilities: Object.freeze(capabilities)\n })\n })\n )\n}\n"]}
package/docs/README.md CHANGED
@@ -51,7 +51,9 @@ class, no registration call, and no inheritance.
51
51
 
52
52
  ## Install
53
53
 
54
- Not on npm yet; see [Installation](https://github.com/smithersai/smithers/blob/main/packages/smithers/flows/flow/docs/installation.md#use-the-libraries).
54
+ ```bash
55
+ npm install @smthrs/plugin@next effect
56
+ ```
55
57
 
56
58
  Node.js 26.4.0 or later is required. For the runtime requirements, the import
57
59
  forms, and the subpaths the export map blocks, see
package/docs/api.md CHANGED
@@ -256,8 +256,10 @@ Every method first compares its kind with the runtime catalog the resolution
256
256
  admitted (`Resolved.kinds`). A hook the catalog declares with a different kind
257
257
  is refused before any handler runs: `sequential`, `first`, and `waterfall` fail
258
258
  with `hook_kind_mismatch`, and `parallel` returns that one error. A hook name
259
- absent from the catalog dispatches nothing. The typed signatures make the
260
- mismatch unreachable without a cast; the runtime check covers the cast.
259
+ absent from the catalog dispatches nothing, unless a hand-built `Resolved`
260
+ registered handlers under it; those are refused the same way, because no kind
261
+ was declared for them. The typed signatures make the mismatch unreachable
262
+ without a cast; the runtime check covers the cast.
261
263
 
262
264
  Handlers must return an Effect. Synchronous throws, Effect failures and defects,
263
265
  and non-Effect results (including `undefined`, scalars, and Promises) become
@@ -482,8 +484,8 @@ class PluginError extends Schema.TaggedError<PluginError>()("flows/plugin/Plugin
482
484
 
483
485
  Every startup and dispatch refusal uses this one error. `plugin` and `hook` are
484
486
  attribution, `path` is a diagnostic dollar-path into the refused value, and
485
- `cause` carries a failing handler's or layer's original failure. Match on
486
- `code`; the messages are prose.
487
+ `cause` carries a failing handler's, layer's, or waterfall merge's original
488
+ failure. Match on `code`; the messages are prose.
487
489
 
488
490
  `cause` is not redacted. It holds whatever the plugin failed or threw with,
489
491
  which can include credentials or config values. Keep it in process for
@@ -67,7 +67,7 @@ const refused = Kernel.make(
67
67
  {},
68
68
  { cacheEnvironment: { layers: [], capabilities: {} } }
69
69
  )
70
- // Fails with PluginError { code: "cache_environment_invalid", plugin: "flows-plugin-model-sonnet", path: "$.version" }
70
+ // Fails with PluginError { code: "cache_environment_invalid", plugin: "flows-plugin-model-sonnet", path: "$[0].version" }
71
71
  ```
72
72
 
73
73
  A versionless plugin is refused rather than folded in as a bare name, because a