Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1076: nominal subtyping for ids #1077

Merged
merged 3 commits into from Aug 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/actionPanel/native.tsx
Expand Up @@ -17,7 +17,7 @@

import { browser } from "webextension-polyfill-ts";
import { reportError } from "@/telemetry/logging";
import { v4 as uuidv4 } from "uuid";
import { uuidv4 } from "@/types/helpers";
import {
ActionPanelStore,
PanelEntry,
Expand Down
2 changes: 1 addition & 1 deletion src/background/devtools/external.ts
Expand Up @@ -29,7 +29,7 @@ import {
TabId,
} from "@/background/devtools/contract";
import { browser, Runtime, WebNavigation } from "webextension-polyfill-ts";
import { v4 as uuidv4 } from "uuid";
import { uuidv4 } from "@/types/helpers";
import { SimpleEvent } from "@/hooks/events";
import { forbidBackgroundPage } from "@/utils/expectContext";
import { getErrorMessage } from "@/errors";
Expand Down
2 changes: 1 addition & 1 deletion src/background/devtools/internal.ts
Expand Up @@ -36,7 +36,7 @@ import {
} from "@/background/devtools/contract";
import { reportError } from "@/telemetry/logging";
import { isBackgroundPage } from "webext-detect-page";
import { v4 as uuidv4 } from "uuid";
import { uuidv4 } from "@/types/helpers";
import { callBackground } from "@/background/devtools/external";
import { ensureContentScript } from "@/background/util";
import * as nativeEditorProtocol from "@/nativeEditor";
Expand Down
4 changes: 3 additions & 1 deletion src/background/locator.ts
Expand Up @@ -18,6 +18,7 @@
import LazyLocatorFactory from "@/services/locator";
import { liftBackground } from "@/background/protocol";
import { isBackgroundPage } from "webext-detect-page";
import { RegistryId, UUID } from "@/core";

export const locator = new LazyLocatorFactory();

Expand All @@ -27,7 +28,8 @@ async function initLocator() {

export const locate = liftBackground(
"LOCATE_SERVICE",
async (serviceId: string, id: string | null) => locator.locate(serviceId, id)
async (serviceId: RegistryId, id: UUID | null) =>
locator.locate(serviceId, id)
);

type RefreshOptions = {
Expand Down
2 changes: 1 addition & 1 deletion src/background/logging.ts
Expand Up @@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import { v4 as uuidv4 } from "uuid";
import { uuidv4 } from "@/types/helpers";
import { liftBackground } from "@/background/protocol";
import { rollbar } from "@/telemetry/rollbar";
import { MessageContext, Logger as ILogger, SerializedError } from "@/core";
Expand Down
6 changes: 3 additions & 3 deletions src/background/preload.ts
Expand Up @@ -23,11 +23,11 @@ import {
} from "@/extensionPoints/contextMenu";
import { reportError } from "@/telemetry/logging";
import { loadOptions } from "@/options/loader";
import { EmptyConfig } from "@/core";
import { EmptyConfig, RegistryId, UUID } from "@/core";

type PreloadOptions<TConfig = EmptyConfig> = {
id: string;
extensionPointId: string;
id: UUID;
extensionPointId: RegistryId;
config: TConfig;
};

Expand Down
2 changes: 1 addition & 1 deletion src/background/protocol.ts
Expand Up @@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import { v4 as uuidv4 } from "uuid";
import { uuidv4 } from "@/types/helpers";
import { getChromeExtensionId, RuntimeNotFoundError } from "@/chrome";
import { browser, Runtime } from "webextension-polyfill-ts";
import { patternToRegex } from "webext-patterns";
Expand Down
2 changes: 1 addition & 1 deletion src/background/telemetry.ts
Expand Up @@ -17,7 +17,7 @@

import { liftBackground } from "@/background/protocol";
import { JsonObject } from "type-fest";
import { v4 as uuidv4 } from "uuid";
import { uuidv4 } from "@/types/helpers";
import { debounce, uniq, throttle, compact } from "lodash";
import { browser } from "webextension-polyfill-ts";
import { readStorage, setStorage } from "@/chrome";
Expand Down
6 changes: 3 additions & 3 deletions src/baseRegistry.ts
Expand Up @@ -104,7 +104,7 @@ export class Registry<TItem extends RegistryItem> {
* @deprecated needed for header generation; will be removed in future versions
*/
cached(): TItem[] {
return Object.values(this.cache);
return [...this.cache.values()];
}

/**
Expand All @@ -121,7 +121,7 @@ export class Registry<TItem extends RegistryItem> {
}
})
);
return Object.values(this.cache);
return [...this.cache.values()];
}

register(...items: TItem[]): void {
Expand Down Expand Up @@ -173,7 +173,7 @@ export class Registry<TItem extends RegistryItem> {

if (!this.kinds.has(item.kind)) {
console.warn(
`Item ${item.metadata?.id ?? "<unknown>"} has kind ${
`Item ${item.metadata?.id ?? "[[unknown]]"} has kind ${
item.kind
}; expected: ${[...this.kinds.values()].join(", ")}`
);
Expand Down
2 changes: 1 addition & 1 deletion src/blocks/transformers/modal.tsx
Expand Up @@ -21,7 +21,7 @@ import Form from "@rjsf/core";
import { Transformer } from "@/types";
import { BlockArg, Schema } from "@/core";
import { registerBlock } from "@/blocks/registry";
import { v4 as uuidv4 } from "uuid";
import { uuidv4 } from "@/types/helpers";
import { BusinessError, CancelError } from "@/errors";

// eslint-disable-next-line @typescript-eslint/no-var-requires, unicorn/prefer-module
Expand Down
2 changes: 0 additions & 2 deletions src/blocks/types.ts
Expand Up @@ -15,8 +15,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

export const PACKAGE_REGEX = /^((?<scope>@[\da-z~-][\d._a-z~-]*)\/)?((?<collection>[\da-z~-][\d._a-z~-]*)\/)?(?<name>[\da-z~-][\d._a-z~-]*)$/;

export interface Availability {
matchPatterns?: string | string[];
selectors?: string | string[];
Expand Down
2 changes: 1 addition & 1 deletion src/components/logViewer/LogTable.stories.tsx
Expand Up @@ -17,7 +17,7 @@

import React from "react";
import { ComponentStory, ComponentMeta } from "@storybook/react";
import { v4 as uuidv4 } from "uuid";
import { uuidv4 } from "@/types/helpers";
import LogTable from "@/components/logViewer/LogTable";
import { serializeError } from "serialize-error";
import { Card } from "react-bootstrap";
Expand Down
3 changes: 2 additions & 1 deletion src/contentScript.ts
Expand Up @@ -15,9 +15,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import { uuidv4 } from "@/types/helpers";

const start = Date.now();

import { v4 as uuidv4 } from "uuid";
import "@/extensionContext";
import addErrorListeners from "@/contentScript/errors";
import "@/blocks";
Expand Down
2 changes: 1 addition & 1 deletion src/contentScript/context.ts
Expand Up @@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import { v4 as uuidv4 } from "uuid";
import { uuidv4 } from "@/types/helpers";

export const sessionId = uuidv4();
export const sessionTimestamp = new Date();
Expand Down
2 changes: 1 addition & 1 deletion src/contentScript/externalProtocol.ts
Expand Up @@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import { v4 as uuidv4 } from "uuid";
import { uuidv4 } from "@/types/helpers";
import {
HandlerEntry,
HandlerOptions,
Expand Down
15 changes: 10 additions & 5 deletions src/contentScript/lifecycle.ts
Expand Up @@ -17,7 +17,7 @@

import { loadOptions } from "@/options/loader";
import extensionPointRegistry from "@/extensionPoints/registry";
import { IExtensionPoint } from "@/core";
import { IExtensionPoint, RegistryId } from "@/core";
import {
liftContentScript,
notifyContentScripts,
Expand All @@ -30,7 +30,7 @@ import { testMatchPatterns } from "@/blocks/available";
import { reportError } from "@/telemetry/logging";
import { browser } from "webextension-polyfill-ts";

let _scriptPromise: Promise<void>;
let _scriptPromise: Promise<void> | undefined;
const _dynamic: Map<string, IExtensionPoint> = new Map();
const _frameHref: Map<number, string> = new Map();
let _extensionPoints: IExtensionPoint[];
Expand All @@ -44,7 +44,7 @@ const WAIT_LOADED_INTERVAL_MS = 25;
async function installScriptOnce(): Promise<void> {
// https://stackoverflow.com/questions/9515704/insert-code-into-the-page-context-using-a-content-script/9517879#9517879
// https://stackoverflow.com/questions/9602022/chrome-extension-retrieving-global-variable-from-webpage
if (!_scriptPromise) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linter was complaining about using "!" on a promise (which makes sense, as it's error-prone, since in most cases the intention would probably be using "!" on the result of the promise)

if (_scriptPromise == null) {
console.debug("Installing page script");
_scriptPromise = new Promise((resolve) => {
const script = document.createElement("script");
Expand Down Expand Up @@ -179,7 +179,9 @@ export async function runDynamic(
async function loadExtensions() {
console.debug("Loading extensions for page");

const previousIds = new Set((_extensionPoints ?? []).map((x) => x.id));
const previousIds = new Set<RegistryId>(
(_extensionPoints ?? []).map((x) => x.id)
);

_extensionPoints = [];

Expand All @@ -190,7 +192,10 @@ async function loadExtensions() {
)) {
const extensions = Object.values(extensionMap);

if (extensions.length === 0 && !previousIds.has(extensionPointId)) {
if (
extensions.length === 0 &&
!previousIds.has(extensionPointId as RegistryId)
) {
// Ignore the case where we uninstalled the last extension, but the extension point was
// not deleted from the state.
//
Expand Down
2 changes: 1 addition & 1 deletion src/contrib/uipath/embedApp.ts
Expand Up @@ -19,7 +19,7 @@ import { Renderer } from "@/types";
import { registerBlock } from "@/blocks/registry";
import { isEmpty } from "lodash";
import { BlockArg, BlockOptions, Schema } from "@/core";
import { v4 as uuidv4 } from "uuid";
import { uuidv4 } from "@/types/helpers";
import { browser, Permissions } from "webextension-polyfill-ts";
import { executeForNonce } from "@/background/executor";

Expand Down
2 changes: 1 addition & 1 deletion src/contrib/zapier/push.ts
Expand Up @@ -24,7 +24,7 @@ import { getBaseURL } from "@/services/baseService";
import { validateInput } from "@/validators/generic";
import { Webhook } from "@/contrib/zapier/contract";
import { Permissions } from "webextension-polyfill-ts";
import { v4 as uuidv4 } from "uuid";
import { uuidv4 } from "@/types/helpers";
import { BusinessError } from "@/errors";

export const ZAPIER_ID = "@pixiebrix/zapier/push-data";
Expand Down