Skip to content

Commit

Permalink
Rename remaining uses of service context to integration context (#9017)
Browse files Browse the repository at this point in the history
  • Loading branch information
twschiller authored Aug 18, 2024
1 parent 1120166 commit 88351b9
Show file tree
Hide file tree
Showing 23 changed files with 107 additions and 102 deletions.
1 change: 0 additions & 1 deletion eslint-local-rules/persistBackgroundData.txt
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@
./src/integrations/util/getModDefinitionIntegrationIds.ts
./src/integrations/util/getUnconfiguredComponentIntegrations.ts
./src/integrations/util/locateSanitizedIntegrationConfigWithRetry.ts
./src/integrations/util/makeServiceContextFromDependencies.ts
./src/integrations/util/permissionsHelpers.ts
./src/modDefinitions/modDefinitionPermissionsHelpers.ts
./src/modDefinitions/modDefinitionsTypes.ts
Expand Down
12 changes: 6 additions & 6 deletions src/analysis/analysisVisitors/varAnalysis/varAnalysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import {
} from "@/utils/expressionUtils";
import { MOD_VARIABLE_REFERENCE } from "@/runtime/extendModVariableContext";
import { joinPathParts } from "@/utils/formUtils";
import makeIntegrationsContextFromDependencies from "@/integrations/util/makeIntegrationsContextFromDependencies";
import makeIntegrationContextFromDependencies from "@/integrations/util/makeIntegrationContextFromDependencies";
import { getOutputReference, isOutputKey } from "@/runtime/runtimeTypes";
import { assertNotNullish } from "@/utils/nullishUtils";
import { BusinessError } from "@/errors/businessErrors";
Expand Down Expand Up @@ -103,7 +103,7 @@ export enum KnownSources {
/**
* Integration configuration.
*/
SERVICE = "service",
INTEGRATION = "integration",
/**
* Observed trace when running the bricks with the Page Editor open.
*/
Expand All @@ -112,7 +112,7 @@ export enum KnownSources {

/**
* Set availability of variables based on the integrations used by the ModComponentBase
* @see makeIntegrationsContextFromDependencies
* @see makeIntegrationContextFromDependencies
*/
async function setIntegrationDependencyVars(
{ integrationDependencies = [] }: ModComponentFormState,
Expand All @@ -121,12 +121,12 @@ async function setIntegrationDependencyVars(
// Loop through all the dependencies, so we can set the source for each dependency variable properly
await Promise.all(
integrationDependencies.map(async (integrationDependency) => {
const serviceContext = await makeIntegrationsContextFromDependencies([
const integrationContext = await makeIntegrationContextFromDependencies([
integrationDependency,
]);
contextVars.setExistenceFromValues({
source: `${KnownSources.SERVICE}:${integrationDependency.integrationId}`,
values: serviceContext,
source: `${KnownSources.INTEGRATION}:${integrationDependency.integrationId}`,
values: integrationContext,
});
}),
);
Expand Down
4 changes: 2 additions & 2 deletions src/bricks/transformers/brickFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,8 @@ class UserDefinedBrick extends BrickABC {
input: argsWithClosures,
// OptionsArgs are set at the blueprint level. For user-defined bricks, are passed via brick inputs
optionsArgs: undefined,
// Services are passed as inputs to the brick
serviceContext: undefined,
// Integration configurations are passed as inputs to the brick
integrationContext: undefined,
root: options.root,
};

Expand Down
2 changes: 1 addition & 1 deletion src/bricks/transformers/controlFlow/IfElse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ describe("IfElse", () => {
root: document.createElement("div"),
input: {},
optionsArgs: {},
serviceContext: {},
integrationContext: {},
},
reduceOptionsFactory("v3"),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const SourceLabel: React.FunctionComponent<SourceLabelProps> = ({
break;
}

case KnownSources.SERVICE: {
case KnownSources.INTEGRATION: {
label = "Integrations";
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function toVarPath(value: string | null): string[] {
export function excludeIntegrationVariables(options: MenuOptions): MenuOptions {
return options.filter(([source]) => {
const [kind] = source.split(":");
return (kind as KnownSources) !== KnownSources.SERVICE;
return (kind as KnownSources) !== KnownSources.INTEGRATION;
});
}

Expand Down
8 changes: 4 additions & 4 deletions src/contentScript/pipelineProtocol/runHeadlessPipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import { type RunPipelineParams } from "@/contentScript/pipelineProtocol/types";
import { getPlatform } from "@/platform/platformContext";
import { reducePipeline } from "@/runtime/reducePipeline";
import { type IntegrationsContext } from "@/types/runtimeTypes";
import { type IntegrationContext } from "@/types/runtimeTypes";
import { expectContext } from "@/utils/expectContext";

/**
Expand All @@ -41,11 +41,11 @@ export async function runHeadlessPipeline({
// Pass undefined here to force the runtime to handle correctly. Passing `document` here wouldn't make sense because
// it would be the page that contains the React tree (i.e., the frame of the sidebar)
root: undefined,
// `reducePipeline` just spreads the serviceContext. If we needed to pick out the actual services we could do the
// `reducePipeline` just spreads the integrationContext. If we needed to pick out the actual services we could do the
// following. However, we actually want to pass through the rest of the context and we don't have an affordance
// for that in the InitialValues type
// pickBy(context, (value: unknown) => isPlainObject(value) && ("__service" in (value as UnknownObject))) as ServiceContext
serviceContext: context as IntegrationsContext,
// pickBy(context, (value: unknown) => isPlainObject(value) && ("__service" in (value as UnknownObject))) as IntegrationContext
integrationContext: context as IntegrationContext,
},
{
...options,
Expand Down
10 changes: 5 additions & 5 deletions src/contentScript/pipelineProtocol/runRendererPipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { reducePipeline } from "@/runtime/reducePipeline";
import { expectContext } from "@/utils/expectContext";
import { HeadlessModeError } from "@/bricks/errors";
import { BusinessError } from "@/errors/businessErrors";
import { type IntegrationsContext } from "@/types/runtimeTypes";
import { type IntegrationContext } from "@/types/runtimeTypes";
import { type RendererRunPayload } from "@/types/rendererTypes";
import { getPlatform } from "@/platform/platformContext";
import { type RunPipelineParams } from "@/contentScript/pipelineProtocol/types";
Expand Down Expand Up @@ -37,11 +37,11 @@ export async function runRendererPipeline({
// Pass undefined here to force the runtime to handle correctly. Passing `document` here wouldn't make sense because
// it would be the page that contains the React tree (i.e., the frame of the sidebar)
root: undefined,
// `reducePipeline` just spreads the serviceContext. If we needed to pick out the actual services we could do the
// following. However, we actually want to pass through the rest of the context and we don't have an affordance
// for that in the InitialValues type
// `reducePipeline` just spreads the integrationContext. If we needed to pick out the actual integration
// configurations, we could do the following. However, we actually want to pass through the rest of the
// context and we don't have an affordance for that in the InitialValues type
// pickBy(context, (value: unknown) => isPlainObject(value) && ("__service" in (value as UnknownObject))) as ServiceContext
serviceContext: context as IntegrationsContext,
integrationContext: context as IntegrationContext,
},
{
logger: getPlatform().logger.childLogger(messageContext),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import { type IntegrationDependency } from "@/integrations/integrationTypes";
import {
type IntegrationDependencyVarRef,
type IntegrationsContext,
type IntegrationsContextValue,
type IntegrationContext,
type IntegrationContextValue,
} from "@/types/runtimeTypes";
import findSanitizedIntegrationConfigWithRetry from "@/integrations/util/findSanitizedIntegrationConfigWithRetry";
import { pickBy } from "lodash";
Expand All @@ -38,7 +38,7 @@ async function dependencyContextValue({
}: {
integrationId: RegistryId;
configId: UUID;
}): Promise<IntegrationsContextValue> {
}): Promise<IntegrationContextValue> {
// Should be safe to call locateWithRetry in parallel b/c the locator.refresh() method debounces/coalesces
// the promise
const integrationConfig = await findSanitizedIntegrationConfigWithRetry(
Expand All @@ -56,13 +56,13 @@ async function dependencyContextValue({
}

/** Build the integrations context by locating the dependencies */
export default async function makeIntegrationsContextFromDependencies(
export default async function makeIntegrationContextFromDependencies(
// `ModComponentBase.integrationDependencies` is an optional field. Since we don't have strict-nullness checking on, calls to this method
// are error-prone. So just be defensive in the signature
// https://github.com/pixiebrix/pixiebrix-extension/issues/3262
dependencies: Nullishable<IntegrationDependency[]>,
): Promise<IntegrationsContext> {
const context: IntegrationsContext = {};
): Promise<IntegrationContext> {
const context: IntegrationContext = {};

if (dependencies == null || dependencies.length === 0) {
return context;
Expand Down
4 changes: 2 additions & 2 deletions src/pageEditor/tabs/effect/BrickPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import { type Brick } from "@/types/brickTypes";
import { type ApiVersion, type BrickArgsContext } from "@/types/runtimeTypes";
import { type IntegrationDependency } from "@/integrations/integrationTypes";
import { type BaseStarterBrickState } from "@/pageEditor/store/editor/baseFormStateTypes";
import makeIntegrationsContextFromDependencies from "@/integrations/util/makeIntegrationsContextFromDependencies";
import makeIntegrationContextFromDependencies from "@/integrations/util/makeIntegrationContextFromDependencies";
import type { FetchableAsyncState } from "@/types/sliceTypes";
import useAsyncState from "@/hooks/useAsyncState";
import { inspectedTab } from "@/pageEditor/context/connection";
Expand Down Expand Up @@ -178,7 +178,7 @@ const BrickPreview: React.FunctionComponent<{
},
context: {
...context,
...(await makeIntegrationsContextFromDependencies(
...(await makeIntegrationContextFromDependencies(
integrationDependencies,
)),
},
Expand Down
4 changes: 2 additions & 2 deletions src/pageEditor/tabs/effect/useDocumentPreviewRunBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { selectActiveModComponentTraceForBrick } from "@/pageEditor/store/runtim
import { type UUID } from "@/types/stringTypes";
import { type BrickArgsContext } from "@/types/runtimeTypes";
import { isExpression } from "@/utils/expressionUtils";
import makeIntegrationsContextFromDependencies from "@/integrations/util/makeIntegrationsContextFromDependencies";
import makeIntegrationContextFromDependencies from "@/integrations/util/makeIntegrationContextFromDependencies";
import useAsyncState from "@/hooks/useAsyncState";
import { inspectedTab } from "@/pageEditor/context/connection";
import { assertNotNullish } from "@/utils/nullishUtils";
Expand Down Expand Up @@ -146,7 +146,7 @@ export default function useDocumentPreviewRunBlock(
);
const { data: integrationContext, isLoading: isLoadingIntegrationContext } =
useAsyncState(
makeIntegrationsContextFromDependencies(integrationDependencies),
makeIntegrationContextFromDependencies(integrationDependencies),
[integrationDependencies],
);
const context = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import {
PIXIEBRIX_INTEGRATION_ID,
PIXIEBRIX_OUTPUT_KEY,
} from "@/integrations/constants";
import makeIntegrationsContextFromDependencies from "@/integrations/util/makeIntegrationsContextFromDependencies";
import makeIntegrationContextFromDependencies from "@/integrations/util/makeIntegrationContextFromDependencies";
import { toExpression } from "@/utils/expressionUtils";
import { pixiebrixConfigurationFactory } from "@/integrations/util/pixiebrixConfigurationFactory";
import { autoUUIDSequence } from "@/testUtils/factories/stringFactories";
Expand All @@ -67,8 +67,8 @@ describe.each([["v1"], ["v2"], ["v3"]])(
}),
];

const serviceContext =
await makeIntegrationsContextFromDependencies(dependencies);
const integrationContext =
await makeIntegrationContextFromDependencies(dependencies);

const result = await reducePipeline(
{
Expand All @@ -77,7 +77,7 @@ describe.each([["v1"], ["v2"], ["v3"]])(
},
{
...simpleInput({}),
serviceContext,
integrationContext,
},
reduceOptionsFactory(apiVersion),
);
Expand Down Expand Up @@ -134,8 +134,8 @@ describe.each([["v1"], ["v2"], ["v3"]])(
);

const dependencies: IntegrationDependency[] = [dependency1, dependency2];
const serviceContext =
await makeIntegrationsContextFromDependencies(dependencies);
const integrationContext =
await makeIntegrationContextFromDependencies(dependencies);

const result = await reducePipeline(
{
Expand All @@ -144,7 +144,7 @@ describe.each([["v1"], ["v2"], ["v3"]])(
},
{
...simpleInput({}),
serviceContext,
integrationContext,
},
reduceOptionsFactory(apiVersion),
);
Expand Down Expand Up @@ -174,8 +174,8 @@ describe.each([["v1"], ["v2"]])("apiVersion: %s", (apiVersion: ApiVersion) => {
pixiebrixIntegrationDependencyFactory(),
];

const serviceContext =
await makeIntegrationsContextFromDependencies(dependencies);
const integrationContext =
await makeIntegrationContextFromDependencies(dependencies);

const result = await reducePipeline(
{
Expand All @@ -184,7 +184,7 @@ describe.each([["v1"], ["v2"]])("apiVersion: %s", (apiVersion: ApiVersion) => {
},
{
...simpleInput({}),
serviceContext,
integrationContext,
},
reduceOptionsFactory(apiVersion),
);
Expand All @@ -211,22 +211,22 @@ describe.each([["v1"], ["v2"]])("apiVersion: %s", (apiVersion: ApiVersion) => {
const dependencies: IntegrationDependency[] = [
integrationDependencyFactory({
integrationId: serviceId,
outputKey: validateOutputKey("service"),
outputKey: validateOutputKey("integration"),
configId: authId,
}),
];

const serviceContext =
await makeIntegrationsContextFromDependencies(dependencies);
const integrationContext =
await makeIntegrationContextFromDependencies(dependencies);

const result = await reducePipeline(
{
id: identityBrick.id,
config: { data: "@service.prop" },
config: { data: "@integration.prop" },
},
{
...simpleInput({}),
serviceContext,
integrationContext,
},
reduceOptionsFactory(apiVersion),
);
Expand All @@ -242,8 +242,8 @@ describe.each([["v3"]])("apiVersion: %s", (apiVersion: ApiVersion) => {
pixiebrixIntegrationDependencyFactory(),
];

const serviceContext =
await makeIntegrationsContextFromDependencies(dependencies);
const integrationContext =
await makeIntegrationContextFromDependencies(dependencies);

const result = await reducePipeline(
{
Expand All @@ -254,7 +254,7 @@ describe.each([["v3"]])("apiVersion: %s", (apiVersion: ApiVersion) => {
},
{
...simpleInput({}),
serviceContext,
integrationContext,
},
reduceOptionsFactory(apiVersion),
);
Expand Down Expand Up @@ -284,7 +284,7 @@ describe.each([["v3"]])("apiVersion: %s", (apiVersion: ApiVersion) => {
configId: authId,
});

const serviceContext = await makeIntegrationsContextFromDependencies([
const integrationContext = await makeIntegrationContextFromDependencies([
dependency,
]);

Expand All @@ -297,7 +297,7 @@ describe.each([["v3"]])("apiVersion: %s", (apiVersion: ApiVersion) => {
},
{
...simpleInput({}),
serviceContext,
integrationContext,
},
reduceOptionsFactory(apiVersion),
);
Expand Down Expand Up @@ -330,24 +330,24 @@ describe.each([["v3"]])("apiVersion: %s", (apiVersion: ApiVersion) => {
const dependencies: IntegrationDependency[] = [
integrationDependencyFactory({
integrationId: serviceId,
outputKey: validateOutputKey("service"),
outputKey: validateOutputKey("integration"),
configId: authId,
}),
];

const serviceContext =
await makeIntegrationsContextFromDependencies(dependencies);
const integrationContext =
await makeIntegrationContextFromDependencies(dependencies);

const result = await reducePipeline(
{
id: identityBrick.id,
config: {
data: toExpression(templateEngine, "{{ @service.prop }}"),
data: toExpression(templateEngine, "{{ @integration.prop }}"),
},
},
{
...simpleInput({}),
serviceContext,
integrationContext,
},
reduceOptionsFactory(apiVersion),
);
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/pipelineTests/pipelineTestHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ export function simpleInput(input: UnknownObject): InitialValues {
return {
input,
root: null,
serviceContext: {},
integrationContext: {},
optionsArgs: {} as OptionsArgs,
};
}
Loading

0 comments on commit 88351b9

Please sign in to comment.