@farm.js/core 0.1.0-beta.18 → 0.1.0-beta.19

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.
Files changed (49) hide show
  1. package/dist/agent-runtime.cjs.map +1 -1
  2. package/dist/agent-runtime.mjs +1 -1
  3. package/dist/{chunk-TWOCKYU7.mjs → chunk-5VHPEW6N.mjs} +2 -2
  4. package/dist/{chunk-ZCTTYTRZ.mjs → chunk-7BX7NEA7.mjs} +2 -2
  5. package/dist/{chunk-PWLQWGXD.mjs → chunk-JUQB43GK.mjs} +14 -5
  6. package/dist/chunk-JUQB43GK.mjs.map +1 -0
  7. package/dist/{chunk-XFYFRBX5.mjs → chunk-MFH7BNPY.mjs} +2 -2
  8. package/dist/{chunk-XFYFRBX5.mjs.map → chunk-MFH7BNPY.mjs.map} +1 -1
  9. package/dist/{chunk-6OKRBYDC.mjs → chunk-UNDUIGWC.mjs} +33 -15
  10. package/dist/chunk-UNDUIGWC.mjs.map +1 -0
  11. package/dist/{chunk-SBLHLAE3.mjs → chunk-ZYDQS2TT.mjs} +88 -5
  12. package/dist/chunk-ZYDQS2TT.mjs.map +1 -0
  13. package/dist/{chunk-DGJPXXVL.mjs → chunk-ZYHIM7O7.mjs} +6 -6
  14. package/dist/{devtools-NVNCOYRJ.mjs → devtools-4RDGBT72.mjs} +3 -3
  15. package/dist/docs.cjs.map +1 -1
  16. package/dist/docs.mjs +3 -3
  17. package/dist/index.cjs +136 -20
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.mjs +9 -7
  20. package/dist/index.mjs.map +1 -1
  21. package/dist/integrations.cjs +82 -4
  22. package/dist/integrations.cjs.map +1 -1
  23. package/dist/integrations.mjs +3 -1
  24. package/dist/internal/build-runtime.cjs +134 -20
  25. package/dist/internal/build-runtime.cjs.map +1 -1
  26. package/dist/internal/build-runtime.mjs +7 -7
  27. package/dist/internal/config-runtime.cjs +75 -4
  28. package/dist/internal/config-runtime.cjs.map +1 -1
  29. package/dist/internal/config-runtime.mjs +2 -2
  30. package/dist/plugin.cjs +62 -15
  31. package/dist/plugin.cjs.map +1 -1
  32. package/dist/plugin.mjs +4 -4
  33. package/dist/server.cjs +138 -20
  34. package/dist/server.cjs.map +1 -1
  35. package/dist/server.mjs +5 -5
  36. package/dist/version.cjs +1 -1
  37. package/dist/version.cjs.map +1 -1
  38. package/dist/version.mjs +1 -1
  39. package/dist/vite.cjs +25 -3
  40. package/dist/vite.cjs.map +1 -1
  41. package/dist/vite.mjs +3 -3
  42. package/package.json +1 -1
  43. package/dist/chunk-6OKRBYDC.mjs.map +0 -1
  44. package/dist/chunk-PWLQWGXD.mjs.map +0 -1
  45. package/dist/chunk-SBLHLAE3.mjs.map +0 -1
  46. /package/dist/{chunk-TWOCKYU7.mjs.map → chunk-5VHPEW6N.mjs.map} +0 -0
  47. /package/dist/{chunk-ZCTTYTRZ.mjs.map → chunk-7BX7NEA7.mjs.map} +0 -0
  48. /package/dist/{chunk-DGJPXXVL.mjs.map → chunk-ZYHIM7O7.mjs.map} +0 -0
  49. /package/dist/{devtools-NVNCOYRJ.mjs.map → devtools-4RDGBT72.mjs.map} +0 -0
@@ -4,6 +4,7 @@ import {
4
4
  defineIntegration,
5
5
  defineIntegrationSchema,
6
6
  dispatchIntegrationRequest,
7
+ getFarmIntegrationPluginOwner,
7
8
  getFarmIntegrationPluginServerRuntime,
8
9
  getIntegrationDocumentNavigationMatchers,
9
10
  getIntegrationProviders,
@@ -17,7 +18,7 @@ import {
17
18
  matchIntegrationRoute,
18
19
  matchRegisteredIntegrationRoute,
19
20
  resolveIntegrationPlugins
20
- } from "./chunk-SBLHLAE3.mjs";
21
+ } from "./chunk-ZYDQS2TT.mjs";
21
22
  import "./chunk-QGOHVJ6J.mjs";
22
23
  import "./chunk-YTMDIHQN.mjs";
23
24
  import {
@@ -35,6 +36,7 @@ export {
35
36
  defineIntegrationAPIOperation,
36
37
  defineIntegrationSchema,
37
38
  dispatchIntegrationRequest,
39
+ getFarmIntegrationPluginOwner,
38
40
  getFarmIntegrationPluginServerRuntime,
39
41
  getIntegrationDocumentNavigationMatchers,
40
42
  getIntegrationProviders,
@@ -45,6 +45,26 @@ var init_integration_api = __esm({
45
45
  }
46
46
  });
47
47
 
48
+ // src/plugin-integration-context.ts
49
+ function setFarmPluginIntegrationContext(plugin, integration) {
50
+ Object.defineProperty(plugin, FARM_PLUGIN_INTEGRATION_CONTEXT, {
51
+ value: integration
52
+ });
53
+ }
54
+ function getFarmPluginIntegrationContext(plugin) {
55
+ const value = plugin[FARM_PLUGIN_INTEGRATION_CONTEXT];
56
+ return value && typeof value === "object" ? value : void 0;
57
+ }
58
+ var FARM_PLUGIN_INTEGRATION_CONTEXT;
59
+ var init_plugin_integration_context = __esm({
60
+ "src/plugin-integration-context.ts"() {
61
+ "use strict";
62
+ FARM_PLUGIN_INTEGRATION_CONTEXT = /* @__PURE__ */ Symbol.for("@farm.js/core/plugin-integration-context");
63
+ __name(setFarmPluginIntegrationContext, "setFarmPluginIntegrationContext");
64
+ __name(getFarmPluginIntegrationContext, "getFarmPluginIntegrationContext");
65
+ }
66
+ });
67
+
48
68
  // src/request-context.ts
49
69
  function getRequestContextStore() {
50
70
  const globalState2 = globalThis;
@@ -1062,6 +1082,10 @@ function getFarmIntegrationPluginServerRuntime(plugin) {
1062
1082
  const value = plugin[FARM_INTEGRATION_PLUGIN_SERVER_RUNTIME];
1063
1083
  return typeof value === "boolean" ? value : void 0;
1064
1084
  }
1085
+ function getFarmIntegrationPluginOwner(plugin) {
1086
+ const value = plugin[FARM_INTEGRATION_PLUGIN_OWNER];
1087
+ return value && typeof value === "object" ? value : void 0;
1088
+ }
1065
1089
  function defineTypedIntegrationRoute(method, path31, input) {
1066
1090
  return {
1067
1091
  path: path31,
@@ -1156,13 +1180,70 @@ function resolveIntegrationPlugins(integrations) {
1156
1180
  if (!integration || !isFarmIntegration(integration)) {
1157
1181
  continue;
1158
1182
  }
1159
- plugins.push(createIntegrationPlugin(key, integration));
1160
- if (integration.plugins?.length) {
1161
- plugins.push(...integration.plugins);
1162
- }
1183
+ const owner = createIntegrationPluginOwner(key, integration, "lifecycle");
1184
+ plugins.push(withIntegrationPluginOwner(createIntegrationPlugin(key, integration), owner));
1185
+ plugins.push(...resolveIntegrationPluginContributions(key, integration));
1163
1186
  }
1164
1187
  return plugins;
1165
1188
  }
1189
+ function resolveIntegrationPluginContributions(key, integration) {
1190
+ const contributions = integration.plugins;
1191
+ if (!contributions) return [];
1192
+ if (!Array.isArray(contributions)) {
1193
+ throw new TypeError(`Integration "${key}" plugins must be an array`);
1194
+ }
1195
+ const names = /* @__PURE__ */ new Set();
1196
+ return contributions.map((plugin, index) => {
1197
+ if (!plugin || typeof plugin !== "object" || typeof plugin.name !== "string") {
1198
+ throw new TypeError(`Integration "${key}" plugin at index ${index} is invalid`);
1199
+ }
1200
+ const name = plugin.name.trim();
1201
+ if (!name) {
1202
+ throw new TypeError(`Integration "${key}" plugin at index ${index} requires a name`);
1203
+ }
1204
+ if (names.has(name)) {
1205
+ throw new Error(`Integration "${key}" contributes duplicate plugin name "${name}"`);
1206
+ }
1207
+ names.add(name);
1208
+ return withIntegrationPluginOwner(
1209
+ plugin,
1210
+ createIntegrationPluginOwner(key, integration, "contribution"),
1211
+ createIntegrationPluginContext(key, integration)
1212
+ );
1213
+ });
1214
+ }
1215
+ function createIntegrationPluginOwner(key, integration, source) {
1216
+ return Object.freeze({
1217
+ key,
1218
+ category: integration.category,
1219
+ type: integration.type,
1220
+ source,
1221
+ serverRuntime: integration.serverRuntime !== false
1222
+ });
1223
+ }
1224
+ function createIntegrationPluginContext(key, integration) {
1225
+ return Object.freeze({
1226
+ key,
1227
+ category: integration.category,
1228
+ type: integration.type,
1229
+ instance: integration.instance,
1230
+ serverRuntime: integration.serverRuntime !== false
1231
+ });
1232
+ }
1233
+ function withIntegrationPluginOwner(plugin, owner, integration) {
1234
+ const descriptors = Object.getOwnPropertyDescriptors(plugin);
1235
+ Reflect.deleteProperty(descriptors, FARM_INTEGRATION_PLUGIN_OWNER);
1236
+ Reflect.deleteProperty(descriptors, FARM_INTEGRATION_PLUGIN_SERVER_RUNTIME);
1237
+ const ownedPlugin = Object.create(Object.getPrototypeOf(plugin), descriptors);
1238
+ Object.defineProperty(ownedPlugin, FARM_INTEGRATION_PLUGIN_OWNER, { value: owner });
1239
+ Object.defineProperty(ownedPlugin, FARM_INTEGRATION_PLUGIN_SERVER_RUNTIME, {
1240
+ value: owner.serverRuntime
1241
+ });
1242
+ if (integration) {
1243
+ setFarmPluginIntegrationContext(ownedPlugin, integration);
1244
+ }
1245
+ return ownedPlugin;
1246
+ }
1166
1247
  function getIntegrationProviders(integrations) {
1167
1248
  if (!integrations) {
1168
1249
  return [];
@@ -2713,11 +2794,12 @@ function normalizeMatcher(matcher) {
2713
2794
  }
2714
2795
  return typeof matcher === "string" ? matcher : matcher.join(", ");
2715
2796
  }
2716
- var FARM_INTEGRATION_INTERNAL_DISPATCH_CONTEXT_KEY, FARM_INTEGRATION_PLUGIN_SERVER_RUNTIME, integrationRoute, INTEGRATION_RUNTIME_REGISTRY_KEY, INTEGRATION_REQUEST_DISPATCHER_KEY, INTEGRATION_DATA_HEADER, INTEGRATION_DATA_HEADER_MAX_LENGTH, BLOCKED_INTEGRATION_DATA_KEYS;
2797
+ var FARM_INTEGRATION_INTERNAL_DISPATCH_CONTEXT_KEY, FARM_INTEGRATION_PLUGIN_SERVER_RUNTIME, FARM_INTEGRATION_PLUGIN_OWNER, integrationRoute, INTEGRATION_RUNTIME_REGISTRY_KEY, INTEGRATION_REQUEST_DISPATCHER_KEY, INTEGRATION_DATA_HEADER, INTEGRATION_DATA_HEADER_MAX_LENGTH, BLOCKED_INTEGRATION_DATA_KEYS;
2717
2798
  var init_integrations = __esm({
2718
2799
  "src/integrations.ts"() {
2719
2800
  "use strict";
2720
2801
  init_integration_api();
2802
+ init_plugin_integration_context();
2721
2803
  init_request_context();
2722
2804
  init_response();
2723
2805
  init_server_http();
@@ -2726,7 +2808,9 @@ var init_integrations = __esm({
2726
2808
  FARM_INTEGRATION_PLUGIN_SERVER_RUNTIME = /* @__PURE__ */ Symbol.for(
2727
2809
  "@farm.js/core/integration-plugin-server-runtime"
2728
2810
  );
2811
+ FARM_INTEGRATION_PLUGIN_OWNER = /* @__PURE__ */ Symbol.for("@farm.js/core/integration-plugin-owner");
2729
2812
  __name(getFarmIntegrationPluginServerRuntime, "getFarmIntegrationPluginServerRuntime");
2813
+ __name(getFarmIntegrationPluginOwner, "getFarmIntegrationPluginOwner");
2730
2814
  __name(defineTypedIntegrationRoute, "defineTypedIntegrationRoute");
2731
2815
  __name(createIntegrationRouteFactory, "createIntegrationRouteFactory");
2732
2816
  integrationRoute = createIntegrationRouteFactory();
@@ -2735,6 +2819,10 @@ var init_integrations = __esm({
2735
2819
  __name(getIntegrationRuntimeRegistry, "getIntegrationRuntimeRegistry");
2736
2820
  __name(isFarmIntegration, "isFarmIntegration");
2737
2821
  __name(resolveIntegrationPlugins, "resolveIntegrationPlugins");
2822
+ __name(resolveIntegrationPluginContributions, "resolveIntegrationPluginContributions");
2823
+ __name(createIntegrationPluginOwner, "createIntegrationPluginOwner");
2824
+ __name(createIntegrationPluginContext, "createIntegrationPluginContext");
2825
+ __name(withIntegrationPluginOwner, "withIntegrationPluginOwner");
2738
2826
  __name(getIntegrationProviders, "getIntegrationProviders");
2739
2827
  __name(getIntegrationDocumentNavigationMatchers, "getIntegrationDocumentNavigationMatchers");
2740
2828
  __name(getRegisteredIntegrations, "getRegisteredIntegrations");
@@ -17986,7 +18074,7 @@ var init_type_artifacts = __esm({
17986
18074
  var version;
17987
18075
  var init_package = __esm({
17988
18076
  "package.json"() {
17989
- version = "0.1.0-beta.18";
18077
+ version = "0.1.0-beta.19";
17990
18078
  }
17991
18079
  });
17992
18080
 
@@ -25963,7 +26051,15 @@ window.__FARM_MANIFEST__ = ${inlineValue({
25963
26051
  const startTime2 = Date.now();
25964
26052
  try {
25965
26053
  if (pm) {
25966
- await pm.runHookParallel("beforeRequest", req, res);
26054
+ await pm.runHookParallelFiltered(
26055
+ "beforeRequest",
26056
+ (plugin) => {
26057
+ const owner = getFarmIntegrationPluginOwner(plugin);
26058
+ return owner?.source !== "lifecycle" || owner.key !== matchedRoute.key;
26059
+ },
26060
+ req,
26061
+ res
26062
+ );
25967
26063
  }
25968
26064
  if (res.writableEnded) {
25969
26065
  const duration2 = Date.now() - startTime2;
@@ -29079,6 +29175,7 @@ var init_plugin = __esm({
29079
29175
  "use strict";
29080
29176
  init_env();
29081
29177
  init_request_context();
29178
+ init_plugin_integration_context();
29082
29179
  init_vite();
29083
29180
  _FarmRuntimeShutdownError = class _FarmRuntimeShutdownError extends Error {
29084
29181
  constructor(message, errors) {
@@ -29145,10 +29242,14 @@ var init_plugin = __esm({
29145
29242
  }
29146
29243
  };
29147
29244
  }
29148
- createRequestHookContext(target) {
29245
+ createPluginHookContext(plugin, context = this.context) {
29246
+ const integration = getFarmPluginIntegrationContext(plugin);
29247
+ return integration ? { ...context, integration } : context;
29248
+ }
29249
+ createRequestHookContext(target, plugin) {
29149
29250
  const requestContext = this.context.requestContext;
29150
29251
  return {
29151
- ...this.context,
29252
+ ...this.createPluginHookContext(plugin),
29152
29253
  req: {
29153
29254
  set(key, value, options) {
29154
29255
  requestContext.set(target, key, value, options);
@@ -29191,7 +29292,7 @@ var init_plugin = __esm({
29191
29292
  return {
29192
29293
  ...this.createStateHookContext(plugin),
29193
29294
  request,
29194
- req: this.createRequestHookContext(request).req,
29295
+ req: this.createRequestHookContext(request, plugin).req,
29195
29296
  kind: options.kind ?? "request",
29196
29297
  route: options.route,
29197
29298
  signal: request.signal,
@@ -29257,7 +29358,7 @@ var init_plugin = __esm({
29257
29358
  }
29258
29359
  createStateHookContext(plugin, context = this.context) {
29259
29360
  return {
29260
- ...context,
29361
+ ...this.createPluginHookContext(plugin, context),
29261
29362
  state: this.pluginStates.get(plugin)
29262
29363
  };
29263
29364
  }
@@ -29385,14 +29486,14 @@ var init_plugin = __esm({
29385
29486
  }
29386
29487
  return hooks;
29387
29488
  }
29388
- getHookContext(hookName, args) {
29489
+ getHookContext(plugin, hookName, args) {
29389
29490
  if (hookName === "beforeRequest" || hookName === "afterResponse" || hookName === "beforeApiHandler") {
29390
29491
  const target = args[0];
29391
29492
  if (target && typeof target === "object") {
29392
- return this.createRequestHookContext(target);
29493
+ return this.createRequestHookContext(target, plugin);
29393
29494
  }
29394
29495
  }
29395
- return this.context;
29496
+ return this.createPluginHookContext(plugin);
29396
29497
  }
29397
29498
  addPlugin(plugin) {
29398
29499
  this.plugins.push(plugin);
@@ -29441,7 +29542,7 @@ var init_plugin = __esm({
29441
29542
  for (const plugin of this.getSortedPlugins()) {
29442
29543
  if (!plugin.setup) continue;
29443
29544
  const state = await plugin.setup({
29444
- ...this.context,
29545
+ ...this.createPluginHookContext(plugin),
29445
29546
  env: getResolvedEnv()
29446
29547
  });
29447
29548
  this.pluginStates.set(plugin, state);
@@ -29612,7 +29713,7 @@ var init_plugin = __esm({
29612
29713
  const plugins = this.getSortedPlugins();
29613
29714
  for (const plugin of plugins) {
29614
29715
  for (const hook of this.getPluginHooks(plugin, hookName)) {
29615
- const hookContext = this.getHookContext(hookName, args);
29716
+ const hookContext = this.getHookContext(plugin, hookName, args);
29616
29717
  const result = await hook.apply(plugin, [...args, hookContext]);
29617
29718
  if (result !== void 0) {
29618
29719
  return result;
@@ -29626,7 +29727,7 @@ var init_plugin = __esm({
29626
29727
  for (const plugin of plugins) {
29627
29728
  for (const hook of this.getPluginHooks(plugin, hookName)) {
29628
29729
  const hookArgs = [value, ...args];
29629
- const hookContext = this.getHookContext(hookName, hookArgs);
29730
+ const hookContext = this.getHookContext(plugin, hookName, hookArgs);
29630
29731
  const result = await hook.apply(plugin, [...hookArgs, hookContext]);
29631
29732
  if (result !== void 0) {
29632
29733
  if (hookName === "beforeApiHandler" && result !== value && value && result && typeof value === "object" && typeof result === "object") {
@@ -29639,11 +29740,15 @@ var init_plugin = __esm({
29639
29740
  return value;
29640
29741
  }
29641
29742
  async runHookParallel(hookName, ...args) {
29743
+ return this.runHookParallelFiltered(hookName, () => true, ...args);
29744
+ }
29745
+ /** @internal Runs hooks for only the plugins selected by the runtime adapter. */
29746
+ async runHookParallelFiltered(hookName, include, ...args) {
29642
29747
  if (hookName === "shutdown" && !this.runtimeShutdownHooksRunning) {
29643
29748
  await this.closeRuntime(args[0]?.reason);
29644
29749
  return false;
29645
29750
  }
29646
- const plugins = this.getSortedPlugins();
29751
+ const plugins = this.getSortedPlugins().filter(include);
29647
29752
  const sequentialHooks = /* @__PURE__ */ new Set([
29648
29753
  "ready",
29649
29754
  "shutdown",
@@ -29666,7 +29771,7 @@ var init_plugin = __esm({
29666
29771
  return true;
29667
29772
  }
29668
29773
  }
29669
- const hookContext = this.getHookContext(hookName, args);
29774
+ const hookContext = this.getHookContext(plugin, hookName, args);
29670
29775
  try {
29671
29776
  await hook.apply(plugin, [...args, hookContext]);
29672
29777
  } catch (error) {
@@ -29688,7 +29793,7 @@ var init_plugin = __esm({
29688
29793
  const promises3 = [];
29689
29794
  for (const plugin of plugins) {
29690
29795
  for (const hook of this.getPluginHooks(plugin, hookName)) {
29691
- const hookContext = this.getHookContext(hookName, args);
29796
+ const hookContext = this.getHookContext(plugin, hookName, args);
29692
29797
  promises3.push(hook.apply(plugin, [...args, hookContext]));
29693
29798
  }
29694
29799
  }
@@ -29709,6 +29814,15 @@ var init_plugin = __esm({
29709
29814
  __name(_PluginManager, "PluginManager");
29710
29815
  PluginManager = _PluginManager;
29711
29816
  __name(definePlugin, "definePlugin");
29817
+ ((definePlugin2) => {
29818
+ function forIntegration() {
29819
+ return /* @__PURE__ */ __name(function defineBoundPlugin(plugin) {
29820
+ return plugin;
29821
+ }, "defineBoundPlugin");
29822
+ }
29823
+ definePlugin2.forIntegration = forIntegration;
29824
+ __name(forIntegration, "forIntegration");
29825
+ })(definePlugin || (definePlugin = {}));
29712
29826
  }
29713
29827
  });
29714
29828