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

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-XFYFRBX5.mjs → chunk-4KTN2BLF.mjs} +2 -2
  4. package/dist/{chunk-XFYFRBX5.mjs.map → chunk-4KTN2BLF.mjs.map} +1 -1
  5. package/dist/{chunk-TWOCKYU7.mjs → chunk-5VHPEW6N.mjs} +2 -2
  6. package/dist/{chunk-ZCTTYTRZ.mjs → chunk-7BX7NEA7.mjs} +2 -2
  7. package/dist/{chunk-PWLQWGXD.mjs → chunk-TMZEK265.mjs} +14 -5
  8. package/dist/chunk-TMZEK265.mjs.map +1 -0
  9. package/dist/{chunk-6OKRBYDC.mjs → chunk-UNDUIGWC.mjs} +33 -15
  10. package/dist/chunk-UNDUIGWC.mjs.map +1 -0
  11. package/dist/{chunk-DGJPXXVL.mjs → chunk-ZRMJY4G2.mjs} +6 -6
  12. package/dist/{chunk-SBLHLAE3.mjs → chunk-ZYDQS2TT.mjs} +88 -5
  13. package/dist/chunk-ZYDQS2TT.mjs.map +1 -0
  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-ZRMJY4G2.mjs.map} +0 -0
  49. /package/dist/{devtools-NVNCOYRJ.mjs.map → devtools-4RDGBT72.mjs.map} +0 -0
package/dist/plugin.mjs CHANGED
@@ -2,11 +2,11 @@ import {
2
2
  FarmRuntimeShutdownError,
3
3
  PluginManager,
4
4
  definePlugin
5
- } from "./chunk-6OKRBYDC.mjs";
5
+ } from "./chunk-UNDUIGWC.mjs";
6
6
  import "./chunk-RQ633A5I.mjs";
7
7
  import {
8
8
  farmPlugin
9
- } from "./chunk-PWLQWGXD.mjs";
9
+ } from "./chunk-TMZEK265.mjs";
10
10
  import "./chunk-LGHEOHBU.mjs";
11
11
  import "./chunk-FRPWCMMG.mjs";
12
12
  import "./chunk-53MVSX3R.mjs";
@@ -29,7 +29,7 @@ import "./chunk-ZVWA4ZQ3.mjs";
29
29
  import "./chunk-7FBJLMQH.mjs";
30
30
  import "./chunk-4E6VRJ6P.mjs";
31
31
  import "./chunk-GXASWWJU.mjs";
32
- import "./chunk-SBLHLAE3.mjs";
32
+ import "./chunk-ZYDQS2TT.mjs";
33
33
  import "./chunk-T4QJQK76.mjs";
34
34
  import "./chunk-MIUW47JX.mjs";
35
35
  import "./chunk-P7QDS5AT.mjs";
@@ -47,7 +47,7 @@ import "./chunk-KQCOGTU7.mjs";
47
47
  import "./chunk-YTMDIHQN.mjs";
48
48
  import "./chunk-RHIFZZUI.mjs";
49
49
  import "./chunk-LM2YNO4U.mjs";
50
- import "./chunk-XFYFRBX5.mjs";
50
+ import "./chunk-4KTN2BLF.mjs";
51
51
  import "./chunk-B3FFOIWS.mjs";
52
52
  import "./chunk-ITN462YM.mjs";
53
53
  import "./chunk-3HIVDX7J.mjs";
package/dist/server.cjs CHANGED
@@ -3400,6 +3400,26 @@ var init_integration_api = __esm({
3400
3400
  }
3401
3401
  });
3402
3402
 
3403
+ // src/plugin-integration-context.ts
3404
+ function setFarmPluginIntegrationContext(plugin, integration) {
3405
+ Object.defineProperty(plugin, FARM_PLUGIN_INTEGRATION_CONTEXT, {
3406
+ value: integration
3407
+ });
3408
+ }
3409
+ function getFarmPluginIntegrationContext(plugin) {
3410
+ const value = plugin[FARM_PLUGIN_INTEGRATION_CONTEXT];
3411
+ return value && typeof value === "object" ? value : void 0;
3412
+ }
3413
+ var FARM_PLUGIN_INTEGRATION_CONTEXT;
3414
+ var init_plugin_integration_context = __esm({
3415
+ "src/plugin-integration-context.ts"() {
3416
+ "use strict";
3417
+ FARM_PLUGIN_INTEGRATION_CONTEXT = /* @__PURE__ */ Symbol.for("@farm.js/core/plugin-integration-context");
3418
+ __name(setFarmPluginIntegrationContext, "setFarmPluginIntegrationContext");
3419
+ __name(getFarmPluginIntegrationContext, "getFarmPluginIntegrationContext");
3420
+ }
3421
+ });
3422
+
3403
3423
  // src/server/response.ts
3404
3424
  async function sendWebResponse(res, response) {
3405
3425
  res.statusCode = response.status;
@@ -3597,6 +3617,10 @@ var init_integration_orm = __esm({
3597
3617
  });
3598
3618
 
3599
3619
  // src/integrations.ts
3620
+ function getFarmIntegrationPluginOwner(plugin) {
3621
+ const value = plugin[FARM_INTEGRATION_PLUGIN_OWNER];
3622
+ return value && typeof value === "object" ? value : void 0;
3623
+ }
3600
3624
  function defineTypedIntegrationRoute(method, path27, input) {
3601
3625
  return {
3602
3626
  path: path27,
@@ -3691,13 +3715,70 @@ function resolveIntegrationPlugins(integrations) {
3691
3715
  if (!integration || !isFarmIntegration(integration)) {
3692
3716
  continue;
3693
3717
  }
3694
- plugins.push(createIntegrationPlugin(key, integration));
3695
- if (integration.plugins?.length) {
3696
- plugins.push(...integration.plugins);
3697
- }
3718
+ const owner = createIntegrationPluginOwner(key, integration, "lifecycle");
3719
+ plugins.push(withIntegrationPluginOwner(createIntegrationPlugin(key, integration), owner));
3720
+ plugins.push(...resolveIntegrationPluginContributions(key, integration));
3698
3721
  }
3699
3722
  return plugins;
3700
3723
  }
3724
+ function resolveIntegrationPluginContributions(key, integration) {
3725
+ const contributions = integration.plugins;
3726
+ if (!contributions) return [];
3727
+ if (!Array.isArray(contributions)) {
3728
+ throw new TypeError(`Integration "${key}" plugins must be an array`);
3729
+ }
3730
+ const names = /* @__PURE__ */ new Set();
3731
+ return contributions.map((plugin, index) => {
3732
+ if (!plugin || typeof plugin !== "object" || typeof plugin.name !== "string") {
3733
+ throw new TypeError(`Integration "${key}" plugin at index ${index} is invalid`);
3734
+ }
3735
+ const name = plugin.name.trim();
3736
+ if (!name) {
3737
+ throw new TypeError(`Integration "${key}" plugin at index ${index} requires a name`);
3738
+ }
3739
+ if (names.has(name)) {
3740
+ throw new Error(`Integration "${key}" contributes duplicate plugin name "${name}"`);
3741
+ }
3742
+ names.add(name);
3743
+ return withIntegrationPluginOwner(
3744
+ plugin,
3745
+ createIntegrationPluginOwner(key, integration, "contribution"),
3746
+ createIntegrationPluginContext(key, integration)
3747
+ );
3748
+ });
3749
+ }
3750
+ function createIntegrationPluginOwner(key, integration, source) {
3751
+ return Object.freeze({
3752
+ key,
3753
+ category: integration.category,
3754
+ type: integration.type,
3755
+ source,
3756
+ serverRuntime: integration.serverRuntime !== false
3757
+ });
3758
+ }
3759
+ function createIntegrationPluginContext(key, integration) {
3760
+ return Object.freeze({
3761
+ key,
3762
+ category: integration.category,
3763
+ type: integration.type,
3764
+ instance: integration.instance,
3765
+ serverRuntime: integration.serverRuntime !== false
3766
+ });
3767
+ }
3768
+ function withIntegrationPluginOwner(plugin, owner, integration) {
3769
+ const descriptors = Object.getOwnPropertyDescriptors(plugin);
3770
+ Reflect.deleteProperty(descriptors, FARM_INTEGRATION_PLUGIN_OWNER);
3771
+ Reflect.deleteProperty(descriptors, FARM_INTEGRATION_PLUGIN_SERVER_RUNTIME);
3772
+ const ownedPlugin = Object.create(Object.getPrototypeOf(plugin), descriptors);
3773
+ Object.defineProperty(ownedPlugin, FARM_INTEGRATION_PLUGIN_OWNER, { value: owner });
3774
+ Object.defineProperty(ownedPlugin, FARM_INTEGRATION_PLUGIN_SERVER_RUNTIME, {
3775
+ value: owner.serverRuntime
3776
+ });
3777
+ if (integration) {
3778
+ setFarmPluginIntegrationContext(ownedPlugin, integration);
3779
+ }
3780
+ return ownedPlugin;
3781
+ }
3701
3782
  function getIntegrationProviders(integrations) {
3702
3783
  if (!integrations) {
3703
3784
  return [];
@@ -5248,11 +5329,12 @@ function normalizeMatcher(matcher) {
5248
5329
  }
5249
5330
  return typeof matcher === "string" ? matcher : matcher.join(", ");
5250
5331
  }
5251
- 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;
5332
+ 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;
5252
5333
  var init_integrations = __esm({
5253
5334
  "src/integrations.ts"() {
5254
5335
  "use strict";
5255
5336
  init_integration_api();
5337
+ init_plugin_integration_context();
5256
5338
  init_request_context();
5257
5339
  init_response();
5258
5340
  init_server_http();
@@ -5261,6 +5343,8 @@ var init_integrations = __esm({
5261
5343
  FARM_INTEGRATION_PLUGIN_SERVER_RUNTIME = /* @__PURE__ */ Symbol.for(
5262
5344
  "@farm.js/core/integration-plugin-server-runtime"
5263
5345
  );
5346
+ FARM_INTEGRATION_PLUGIN_OWNER = /* @__PURE__ */ Symbol.for("@farm.js/core/integration-plugin-owner");
5347
+ __name(getFarmIntegrationPluginOwner, "getFarmIntegrationPluginOwner");
5264
5348
  __name(defineTypedIntegrationRoute, "defineTypedIntegrationRoute");
5265
5349
  __name(createIntegrationRouteFactory, "createIntegrationRouteFactory");
5266
5350
  integrationRoute = createIntegrationRouteFactory();
@@ -5269,6 +5353,10 @@ var init_integrations = __esm({
5269
5353
  __name(getIntegrationRuntimeRegistry, "getIntegrationRuntimeRegistry");
5270
5354
  __name(isFarmIntegration, "isFarmIntegration");
5271
5355
  __name(resolveIntegrationPlugins, "resolveIntegrationPlugins");
5356
+ __name(resolveIntegrationPluginContributions, "resolveIntegrationPluginContributions");
5357
+ __name(createIntegrationPluginOwner, "createIntegrationPluginOwner");
5358
+ __name(createIntegrationPluginContext, "createIntegrationPluginContext");
5359
+ __name(withIntegrationPluginOwner, "withIntegrationPluginOwner");
5272
5360
  __name(getIntegrationProviders, "getIntegrationProviders");
5273
5361
  __name(getIntegrationDocumentNavigationMatchers, "getIntegrationDocumentNavigationMatchers");
5274
5362
  __name(getRegisteredIntegrations, "getRegisteredIntegrations");
@@ -24814,7 +24902,7 @@ function transformError(id, message) {
24814
24902
  __name(transformError, "transformError");
24815
24903
 
24816
24904
  // package.json
24817
- var version = "0.1.0-beta.18";
24905
+ var version = "0.1.0-beta.20";
24818
24906
 
24819
24907
  // src/version.ts
24820
24908
  var FARM_VERSION = version;
@@ -26195,7 +26283,15 @@ window.__FARM_MANIFEST__ = ${inlineValue({
26195
26283
  const startTime2 = Date.now();
26196
26284
  try {
26197
26285
  if (pm) {
26198
- await pm.runHookParallel("beforeRequest", req, res);
26286
+ await pm.runHookParallelFiltered(
26287
+ "beforeRequest",
26288
+ (plugin) => {
26289
+ const owner = getFarmIntegrationPluginOwner(plugin);
26290
+ return owner?.source !== "lifecycle" || owner.key !== matchedRoute.key;
26291
+ },
26292
+ req,
26293
+ res
26294
+ );
26199
26295
  }
26200
26296
  if (res.writableEnded) {
26201
26297
  const duration2 = Date.now() - startTime2;
@@ -29599,6 +29695,7 @@ init_config2();
29599
29695
  // src/plugin.ts
29600
29696
  init_env();
29601
29697
  init_request_context();
29698
+ init_plugin_integration_context();
29602
29699
  var _FarmRuntimeShutdownError = class _FarmRuntimeShutdownError extends Error {
29603
29700
  constructor(message, errors) {
29604
29701
  super(message);
@@ -29664,10 +29761,14 @@ var _PluginManager = class _PluginManager {
29664
29761
  }
29665
29762
  };
29666
29763
  }
29667
- createRequestHookContext(target) {
29764
+ createPluginHookContext(plugin, context = this.context) {
29765
+ const integration = getFarmPluginIntegrationContext(plugin);
29766
+ return integration ? { ...context, integration } : context;
29767
+ }
29768
+ createRequestHookContext(target, plugin) {
29668
29769
  const requestContext = this.context.requestContext;
29669
29770
  return {
29670
- ...this.context,
29771
+ ...this.createPluginHookContext(plugin),
29671
29772
  req: {
29672
29773
  set(key, value, options) {
29673
29774
  requestContext.set(target, key, value, options);
@@ -29710,7 +29811,7 @@ var _PluginManager = class _PluginManager {
29710
29811
  return {
29711
29812
  ...this.createStateHookContext(plugin),
29712
29813
  request,
29713
- req: this.createRequestHookContext(request).req,
29814
+ req: this.createRequestHookContext(request, plugin).req,
29714
29815
  kind: options.kind ?? "request",
29715
29816
  route: options.route,
29716
29817
  signal: request.signal,
@@ -29776,7 +29877,7 @@ var _PluginManager = class _PluginManager {
29776
29877
  }
29777
29878
  createStateHookContext(plugin, context = this.context) {
29778
29879
  return {
29779
- ...context,
29880
+ ...this.createPluginHookContext(plugin, context),
29780
29881
  state: this.pluginStates.get(plugin)
29781
29882
  };
29782
29883
  }
@@ -29904,14 +30005,14 @@ var _PluginManager = class _PluginManager {
29904
30005
  }
29905
30006
  return hooks;
29906
30007
  }
29907
- getHookContext(hookName, args) {
30008
+ getHookContext(plugin, hookName, args) {
29908
30009
  if (hookName === "beforeRequest" || hookName === "afterResponse" || hookName === "beforeApiHandler") {
29909
30010
  const target = args[0];
29910
30011
  if (target && typeof target === "object") {
29911
- return this.createRequestHookContext(target);
30012
+ return this.createRequestHookContext(target, plugin);
29912
30013
  }
29913
30014
  }
29914
- return this.context;
30015
+ return this.createPluginHookContext(plugin);
29915
30016
  }
29916
30017
  addPlugin(plugin) {
29917
30018
  this.plugins.push(plugin);
@@ -29960,7 +30061,7 @@ var _PluginManager = class _PluginManager {
29960
30061
  for (const plugin of this.getSortedPlugins()) {
29961
30062
  if (!plugin.setup) continue;
29962
30063
  const state = await plugin.setup({
29963
- ...this.context,
30064
+ ...this.createPluginHookContext(plugin),
29964
30065
  env: getResolvedEnv()
29965
30066
  });
29966
30067
  this.pluginStates.set(plugin, state);
@@ -30131,7 +30232,7 @@ var _PluginManager = class _PluginManager {
30131
30232
  const plugins = this.getSortedPlugins();
30132
30233
  for (const plugin of plugins) {
30133
30234
  for (const hook of this.getPluginHooks(plugin, hookName)) {
30134
- const hookContext = this.getHookContext(hookName, args);
30235
+ const hookContext = this.getHookContext(plugin, hookName, args);
30135
30236
  const result = await hook.apply(plugin, [...args, hookContext]);
30136
30237
  if (result !== void 0) {
30137
30238
  return result;
@@ -30145,7 +30246,7 @@ var _PluginManager = class _PluginManager {
30145
30246
  for (const plugin of plugins) {
30146
30247
  for (const hook of this.getPluginHooks(plugin, hookName)) {
30147
30248
  const hookArgs = [value, ...args];
30148
- const hookContext = this.getHookContext(hookName, hookArgs);
30249
+ const hookContext = this.getHookContext(plugin, hookName, hookArgs);
30149
30250
  const result = await hook.apply(plugin, [...hookArgs, hookContext]);
30150
30251
  if (result !== void 0) {
30151
30252
  if (hookName === "beforeApiHandler" && result !== value && value && result && typeof value === "object" && typeof result === "object") {
@@ -30158,11 +30259,15 @@ var _PluginManager = class _PluginManager {
30158
30259
  return value;
30159
30260
  }
30160
30261
  async runHookParallel(hookName, ...args) {
30262
+ return this.runHookParallelFiltered(hookName, () => true, ...args);
30263
+ }
30264
+ /** @internal Runs hooks for only the plugins selected by the runtime adapter. */
30265
+ async runHookParallelFiltered(hookName, include, ...args) {
30161
30266
  if (hookName === "shutdown" && !this.runtimeShutdownHooksRunning) {
30162
30267
  await this.closeRuntime(args[0]?.reason);
30163
30268
  return false;
30164
30269
  }
30165
- const plugins = this.getSortedPlugins();
30270
+ const plugins = this.getSortedPlugins().filter(include);
30166
30271
  const sequentialHooks = /* @__PURE__ */ new Set([
30167
30272
  "ready",
30168
30273
  "shutdown",
@@ -30185,7 +30290,7 @@ var _PluginManager = class _PluginManager {
30185
30290
  return true;
30186
30291
  }
30187
30292
  }
30188
- const hookContext = this.getHookContext(hookName, args);
30293
+ const hookContext = this.getHookContext(plugin, hookName, args);
30189
30294
  try {
30190
30295
  await hook.apply(plugin, [...args, hookContext]);
30191
30296
  } catch (error) {
@@ -30207,7 +30312,7 @@ var _PluginManager = class _PluginManager {
30207
30312
  const promises3 = [];
30208
30313
  for (const plugin of plugins) {
30209
30314
  for (const hook of this.getPluginHooks(plugin, hookName)) {
30210
- const hookContext = this.getHookContext(hookName, args);
30315
+ const hookContext = this.getHookContext(plugin, hookName, args);
30211
30316
  promises3.push(hook.apply(plugin, [...args, hookContext]));
30212
30317
  }
30213
30318
  }
@@ -30227,6 +30332,19 @@ var _PluginManager = class _PluginManager {
30227
30332
  };
30228
30333
  __name(_PluginManager, "PluginManager");
30229
30334
  var PluginManager = _PluginManager;
30335
+ function definePlugin(plugin) {
30336
+ return plugin;
30337
+ }
30338
+ __name(definePlugin, "definePlugin");
30339
+ ((definePlugin2) => {
30340
+ function forIntegration() {
30341
+ return /* @__PURE__ */ __name(function defineBoundPlugin(plugin) {
30342
+ return plugin;
30343
+ }, "defineBoundPlugin");
30344
+ }
30345
+ definePlugin2.forIntegration = forIntegration;
30346
+ __name(forIntegration, "forIntegration");
30347
+ })(definePlugin || (definePlugin = {}));
30230
30348
 
30231
30349
  // src/server/create-server.ts
30232
30350
  var import_fs5 = __toESM(require("fs"));