@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/docs.mjs CHANGED
@@ -9,9 +9,9 @@ import {
9
9
  isFarmDocsRequest,
10
10
  loadFarmDocsPage,
11
11
  resolveFarmDocsContentDir
12
- } from "./chunk-TWOCKYU7.mjs";
12
+ } from "./chunk-5VHPEW6N.mjs";
13
13
  import "./chunk-V7RBCSDJ.mjs";
14
- import "./chunk-ZCTTYTRZ.mjs";
14
+ import "./chunk-7BX7NEA7.mjs";
15
15
  import "./chunk-UVCIEUJC.mjs";
16
16
  import "./chunk-RQ633A5I.mjs";
17
17
  import "./chunk-USLFXFFH.mjs";
@@ -26,7 +26,7 @@ import "./chunk-ZVWA4ZQ3.mjs";
26
26
  import "./chunk-7FBJLMQH.mjs";
27
27
  import "./chunk-4E6VRJ6P.mjs";
28
28
  import "./chunk-GXASWWJU.mjs";
29
- import "./chunk-SBLHLAE3.mjs";
29
+ import "./chunk-ZYDQS2TT.mjs";
30
30
  import "./chunk-QGOHVJ6J.mjs";
31
31
  import "./chunk-FQYDHKKU.mjs";
32
32
  import "./chunk-GQVGIUSN.mjs";
package/dist/index.cjs CHANGED
@@ -875,6 +875,26 @@ var init_integration_api = __esm({
875
875
  }
876
876
  });
877
877
 
878
+ // src/plugin-integration-context.ts
879
+ function setFarmPluginIntegrationContext(plugin, integration) {
880
+ Object.defineProperty(plugin, FARM_PLUGIN_INTEGRATION_CONTEXT, {
881
+ value: integration
882
+ });
883
+ }
884
+ function getFarmPluginIntegrationContext(plugin) {
885
+ const value = plugin[FARM_PLUGIN_INTEGRATION_CONTEXT];
886
+ return value && typeof value === "object" ? value : void 0;
887
+ }
888
+ var FARM_PLUGIN_INTEGRATION_CONTEXT;
889
+ var init_plugin_integration_context = __esm({
890
+ "src/plugin-integration-context.ts"() {
891
+ "use strict";
892
+ FARM_PLUGIN_INTEGRATION_CONTEXT = /* @__PURE__ */ Symbol.for("@farm.js/core/plugin-integration-context");
893
+ __name(setFarmPluginIntegrationContext, "setFarmPluginIntegrationContext");
894
+ __name(getFarmPluginIntegrationContext, "getFarmPluginIntegrationContext");
895
+ }
896
+ });
897
+
878
898
  // src/request-context.ts
879
899
  function getRequestContextStore() {
880
900
  const globalState2 = globalThis;
@@ -1434,6 +1454,10 @@ function getFarmIntegrationPluginServerRuntime(plugin) {
1434
1454
  const value = plugin[FARM_INTEGRATION_PLUGIN_SERVER_RUNTIME];
1435
1455
  return typeof value === "boolean" ? value : void 0;
1436
1456
  }
1457
+ function getFarmIntegrationPluginOwner(plugin) {
1458
+ const value = plugin[FARM_INTEGRATION_PLUGIN_OWNER];
1459
+ return value && typeof value === "object" ? value : void 0;
1460
+ }
1437
1461
  function defineTypedIntegrationRoute(method, path32, input) {
1438
1462
  return {
1439
1463
  path: path32,
@@ -1582,13 +1606,70 @@ function resolveIntegrationPlugins(integrations) {
1582
1606
  if (!integration || !isFarmIntegration(integration)) {
1583
1607
  continue;
1584
1608
  }
1585
- plugins.push(createIntegrationPlugin(key, integration));
1586
- if (integration.plugins?.length) {
1587
- plugins.push(...integration.plugins);
1588
- }
1609
+ const owner = createIntegrationPluginOwner(key, integration, "lifecycle");
1610
+ plugins.push(withIntegrationPluginOwner(createIntegrationPlugin(key, integration), owner));
1611
+ plugins.push(...resolveIntegrationPluginContributions(key, integration));
1589
1612
  }
1590
1613
  return plugins;
1591
1614
  }
1615
+ function resolveIntegrationPluginContributions(key, integration) {
1616
+ const contributions = integration.plugins;
1617
+ if (!contributions) return [];
1618
+ if (!Array.isArray(contributions)) {
1619
+ throw new TypeError(`Integration "${key}" plugins must be an array`);
1620
+ }
1621
+ const names = /* @__PURE__ */ new Set();
1622
+ return contributions.map((plugin, index) => {
1623
+ if (!plugin || typeof plugin !== "object" || typeof plugin.name !== "string") {
1624
+ throw new TypeError(`Integration "${key}" plugin at index ${index} is invalid`);
1625
+ }
1626
+ const name = plugin.name.trim();
1627
+ if (!name) {
1628
+ throw new TypeError(`Integration "${key}" plugin at index ${index} requires a name`);
1629
+ }
1630
+ if (names.has(name)) {
1631
+ throw new Error(`Integration "${key}" contributes duplicate plugin name "${name}"`);
1632
+ }
1633
+ names.add(name);
1634
+ return withIntegrationPluginOwner(
1635
+ plugin,
1636
+ createIntegrationPluginOwner(key, integration, "contribution"),
1637
+ createIntegrationPluginContext(key, integration)
1638
+ );
1639
+ });
1640
+ }
1641
+ function createIntegrationPluginOwner(key, integration, source) {
1642
+ return Object.freeze({
1643
+ key,
1644
+ category: integration.category,
1645
+ type: integration.type,
1646
+ source,
1647
+ serverRuntime: integration.serverRuntime !== false
1648
+ });
1649
+ }
1650
+ function createIntegrationPluginContext(key, integration) {
1651
+ return Object.freeze({
1652
+ key,
1653
+ category: integration.category,
1654
+ type: integration.type,
1655
+ instance: integration.instance,
1656
+ serverRuntime: integration.serverRuntime !== false
1657
+ });
1658
+ }
1659
+ function withIntegrationPluginOwner(plugin, owner, integration) {
1660
+ const descriptors = Object.getOwnPropertyDescriptors(plugin);
1661
+ Reflect.deleteProperty(descriptors, FARM_INTEGRATION_PLUGIN_OWNER);
1662
+ Reflect.deleteProperty(descriptors, FARM_INTEGRATION_PLUGIN_SERVER_RUNTIME);
1663
+ const ownedPlugin = Object.create(Object.getPrototypeOf(plugin), descriptors);
1664
+ Object.defineProperty(ownedPlugin, FARM_INTEGRATION_PLUGIN_OWNER, { value: owner });
1665
+ Object.defineProperty(ownedPlugin, FARM_INTEGRATION_PLUGIN_SERVER_RUNTIME, {
1666
+ value: owner.serverRuntime
1667
+ });
1668
+ if (integration) {
1669
+ setFarmPluginIntegrationContext(ownedPlugin, integration);
1670
+ }
1671
+ return ownedPlugin;
1672
+ }
1592
1673
  function getIntegrationProviders(integrations) {
1593
1674
  if (!integrations) {
1594
1675
  return [];
@@ -3158,11 +3239,12 @@ function normalizeMatcher(matcher) {
3158
3239
  }
3159
3240
  return typeof matcher === "string" ? matcher : matcher.join(", ");
3160
3241
  }
3161
- 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;
3242
+ 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;
3162
3243
  var init_integrations = __esm({
3163
3244
  "src/integrations.ts"() {
3164
3245
  "use strict";
3165
3246
  init_integration_api();
3247
+ init_plugin_integration_context();
3166
3248
  init_request_context();
3167
3249
  init_response();
3168
3250
  init_server_http();
@@ -3172,7 +3254,9 @@ var init_integrations = __esm({
3172
3254
  FARM_INTEGRATION_PLUGIN_SERVER_RUNTIME = /* @__PURE__ */ Symbol.for(
3173
3255
  "@farm.js/core/integration-plugin-server-runtime"
3174
3256
  );
3257
+ FARM_INTEGRATION_PLUGIN_OWNER = /* @__PURE__ */ Symbol.for("@farm.js/core/integration-plugin-owner");
3175
3258
  __name(getFarmIntegrationPluginServerRuntime, "getFarmIntegrationPluginServerRuntime");
3259
+ __name(getFarmIntegrationPluginOwner, "getFarmIntegrationPluginOwner");
3176
3260
  __name(defineTypedIntegrationRoute, "defineTypedIntegrationRoute");
3177
3261
  __name(createIntegrationRouteFactory, "createIntegrationRouteFactory");
3178
3262
  __name(createIntegrationRoute, "createIntegrationRoute");
@@ -3185,6 +3269,10 @@ var init_integrations = __esm({
3185
3269
  __name(defineIntegration, "defineIntegration");
3186
3270
  __name(isFarmIntegration, "isFarmIntegration");
3187
3271
  __name(resolveIntegrationPlugins, "resolveIntegrationPlugins");
3272
+ __name(resolveIntegrationPluginContributions, "resolveIntegrationPluginContributions");
3273
+ __name(createIntegrationPluginOwner, "createIntegrationPluginOwner");
3274
+ __name(createIntegrationPluginContext, "createIntegrationPluginContext");
3275
+ __name(withIntegrationPluginOwner, "withIntegrationPluginOwner");
3188
3276
  __name(getIntegrationProviders, "getIntegrationProviders");
3189
3277
  __name(getIntegrationDocumentNavigationMatchers, "getIntegrationDocumentNavigationMatchers");
3190
3278
  __name(getIntegrationSchemas, "getIntegrationSchemas");
@@ -19758,7 +19846,7 @@ var init_environment_vite = __esm({
19758
19846
  var version;
19759
19847
  var init_package = __esm({
19760
19848
  "package.json"() {
19761
- version = "0.1.0-beta.18";
19849
+ version = "0.1.0-beta.20";
19762
19850
  }
19763
19851
  });
19764
19852
 
@@ -28800,7 +28888,15 @@ window.__FARM_MANIFEST__ = ${inlineValue({
28800
28888
  const startTime2 = Date.now();
28801
28889
  try {
28802
28890
  if (pm) {
28803
- await pm.runHookParallel("beforeRequest", req, res);
28891
+ await pm.runHookParallelFiltered(
28892
+ "beforeRequest",
28893
+ (plugin) => {
28894
+ const owner = getFarmIntegrationPluginOwner(plugin);
28895
+ return owner?.source !== "lifecycle" || owner.key !== matchedRoute.key;
28896
+ },
28897
+ req,
28898
+ res
28899
+ );
28804
28900
  }
28805
28901
  if (res.writableEnded) {
28806
28902
  const duration2 = Date.now() - startTime2;
@@ -31916,6 +32012,7 @@ var init_plugin = __esm({
31916
32012
  "use strict";
31917
32013
  init_env();
31918
32014
  init_request_context();
32015
+ init_plugin_integration_context();
31919
32016
  init_vite();
31920
32017
  _FarmRuntimeShutdownError = class _FarmRuntimeShutdownError extends Error {
31921
32018
  constructor(message, errors) {
@@ -31982,10 +32079,14 @@ var init_plugin = __esm({
31982
32079
  }
31983
32080
  };
31984
32081
  }
31985
- createRequestHookContext(target) {
32082
+ createPluginHookContext(plugin, context = this.context) {
32083
+ const integration = getFarmPluginIntegrationContext(plugin);
32084
+ return integration ? { ...context, integration } : context;
32085
+ }
32086
+ createRequestHookContext(target, plugin) {
31986
32087
  const requestContext = this.context.requestContext;
31987
32088
  return {
31988
- ...this.context,
32089
+ ...this.createPluginHookContext(plugin),
31989
32090
  req: {
31990
32091
  set(key, value, options) {
31991
32092
  requestContext.set(target, key, value, options);
@@ -32028,7 +32129,7 @@ var init_plugin = __esm({
32028
32129
  return {
32029
32130
  ...this.createStateHookContext(plugin),
32030
32131
  request,
32031
- req: this.createRequestHookContext(request).req,
32132
+ req: this.createRequestHookContext(request, plugin).req,
32032
32133
  kind: options.kind ?? "request",
32033
32134
  route: options.route,
32034
32135
  signal: request.signal,
@@ -32094,7 +32195,7 @@ var init_plugin = __esm({
32094
32195
  }
32095
32196
  createStateHookContext(plugin, context = this.context) {
32096
32197
  return {
32097
- ...context,
32198
+ ...this.createPluginHookContext(plugin, context),
32098
32199
  state: this.pluginStates.get(plugin)
32099
32200
  };
32100
32201
  }
@@ -32222,14 +32323,14 @@ var init_plugin = __esm({
32222
32323
  }
32223
32324
  return hooks;
32224
32325
  }
32225
- getHookContext(hookName, args) {
32326
+ getHookContext(plugin, hookName, args) {
32226
32327
  if (hookName === "beforeRequest" || hookName === "afterResponse" || hookName === "beforeApiHandler") {
32227
32328
  const target = args[0];
32228
32329
  if (target && typeof target === "object") {
32229
- return this.createRequestHookContext(target);
32330
+ return this.createRequestHookContext(target, plugin);
32230
32331
  }
32231
32332
  }
32232
- return this.context;
32333
+ return this.createPluginHookContext(plugin);
32233
32334
  }
32234
32335
  addPlugin(plugin) {
32235
32336
  this.plugins.push(plugin);
@@ -32278,7 +32379,7 @@ var init_plugin = __esm({
32278
32379
  for (const plugin of this.getSortedPlugins()) {
32279
32380
  if (!plugin.setup) continue;
32280
32381
  const state = await plugin.setup({
32281
- ...this.context,
32382
+ ...this.createPluginHookContext(plugin),
32282
32383
  env: getResolvedEnv()
32283
32384
  });
32284
32385
  this.pluginStates.set(plugin, state);
@@ -32449,7 +32550,7 @@ var init_plugin = __esm({
32449
32550
  const plugins = this.getSortedPlugins();
32450
32551
  for (const plugin of plugins) {
32451
32552
  for (const hook of this.getPluginHooks(plugin, hookName)) {
32452
- const hookContext = this.getHookContext(hookName, args);
32553
+ const hookContext = this.getHookContext(plugin, hookName, args);
32453
32554
  const result = await hook.apply(plugin, [...args, hookContext]);
32454
32555
  if (result !== void 0) {
32455
32556
  return result;
@@ -32463,7 +32564,7 @@ var init_plugin = __esm({
32463
32564
  for (const plugin of plugins) {
32464
32565
  for (const hook of this.getPluginHooks(plugin, hookName)) {
32465
32566
  const hookArgs = [value, ...args];
32466
- const hookContext = this.getHookContext(hookName, hookArgs);
32567
+ const hookContext = this.getHookContext(plugin, hookName, hookArgs);
32467
32568
  const result = await hook.apply(plugin, [...hookArgs, hookContext]);
32468
32569
  if (result !== void 0) {
32469
32570
  if (hookName === "beforeApiHandler" && result !== value && value && result && typeof value === "object" && typeof result === "object") {
@@ -32476,11 +32577,15 @@ var init_plugin = __esm({
32476
32577
  return value;
32477
32578
  }
32478
32579
  async runHookParallel(hookName, ...args) {
32580
+ return this.runHookParallelFiltered(hookName, () => true, ...args);
32581
+ }
32582
+ /** @internal Runs hooks for only the plugins selected by the runtime adapter. */
32583
+ async runHookParallelFiltered(hookName, include, ...args) {
32479
32584
  if (hookName === "shutdown" && !this.runtimeShutdownHooksRunning) {
32480
32585
  await this.closeRuntime(args[0]?.reason);
32481
32586
  return false;
32482
32587
  }
32483
- const plugins = this.getSortedPlugins();
32588
+ const plugins = this.getSortedPlugins().filter(include);
32484
32589
  const sequentialHooks = /* @__PURE__ */ new Set([
32485
32590
  "ready",
32486
32591
  "shutdown",
@@ -32503,7 +32608,7 @@ var init_plugin = __esm({
32503
32608
  return true;
32504
32609
  }
32505
32610
  }
32506
- const hookContext = this.getHookContext(hookName, args);
32611
+ const hookContext = this.getHookContext(plugin, hookName, args);
32507
32612
  try {
32508
32613
  await hook.apply(plugin, [...args, hookContext]);
32509
32614
  } catch (error) {
@@ -32525,7 +32630,7 @@ var init_plugin = __esm({
32525
32630
  const promises3 = [];
32526
32631
  for (const plugin of plugins) {
32527
32632
  for (const hook of this.getPluginHooks(plugin, hookName)) {
32528
- const hookContext = this.getHookContext(hookName, args);
32633
+ const hookContext = this.getHookContext(plugin, hookName, args);
32529
32634
  promises3.push(hook.apply(plugin, [...args, hookContext]));
32530
32635
  }
32531
32636
  }
@@ -32546,6 +32651,15 @@ var init_plugin = __esm({
32546
32651
  __name(_PluginManager, "PluginManager");
32547
32652
  PluginManager = _PluginManager;
32548
32653
  __name(definePlugin, "definePlugin");
32654
+ ((definePlugin2) => {
32655
+ function forIntegration() {
32656
+ return /* @__PURE__ */ __name(function defineBoundPlugin(plugin) {
32657
+ return plugin;
32658
+ }, "defineBoundPlugin");
32659
+ }
32660
+ definePlugin2.forIntegration = forIntegration;
32661
+ __name(forIntegration, "forIntegration");
32662
+ })(definePlugin || (definePlugin = {}));
32549
32663
  }
32550
32664
  });
32551
32665
 
@@ -33431,6 +33545,7 @@ __export(src_exports, {
33431
33545
  getFarmDeploymentMismatch: () => getFarmDeploymentMismatch,
33432
33546
  getFarmDocsDocumentNavigationMatchers: () => getFarmDocsDocumentNavigationMatchers,
33433
33547
  getFarmDocsRouteTypeEntries: () => getFarmDocsRouteTypeEntries,
33548
+ getFarmIntegrationPluginOwner: () => getFarmIntegrationPluginOwner,
33434
33549
  getFarmIntegrationPluginServerRuntime: () => getFarmIntegrationPluginServerRuntime,
33435
33550
  getFarmLayerAliases: () => getFarmLayerAliases,
33436
33551
  getFarmPresetRuntime: () => getFarmPresetRuntime,
@@ -46705,6 +46820,7 @@ __name(decodeCookiePart, "decodeCookiePart");
46705
46820
  getFarmDeploymentMismatch,
46706
46821
  getFarmDocsDocumentNavigationMatchers,
46707
46822
  getFarmDocsRouteTypeEntries,
46823
+ getFarmIntegrationPluginOwner,
46708
46824
  getFarmIntegrationPluginServerRuntime,
46709
46825
  getFarmLayerAliases,
46710
46826
  getFarmPresetRuntime,