Skip to content

Commit

Permalink
Use the word "create" in method names instead of "gen" for better cla…
Browse files Browse the repository at this point in the history
…rity
  • Loading branch information
MovByte committed Dec 30, 2024
1 parent fbae1c4 commit 61d883d
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 53 deletions.
6 changes: 3 additions & 3 deletions AeroSandbox/src/interceptors/storage/iDB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ import { storageNomenclatureHandlers } from "$util/storage";

export default [
{
genProxyHandler: ctx => storageNomenclatureHandlers(ctx.cookieStoreId),
createProxyHandler: ctx => storageNomenclatureHandlers(ctx.cookieStoreId),
forStorage: true,
globalProp: "indexedDB.open",
supports: SupportEnum.widelyAvailable
},
{
genProxyHandler: ctx => storageNomenclatureHandlers(ctx.cookieStoreId),
createProxyHandler: ctx => storageNomenclatureHandlers(ctx.cookieStoreId),
forStorage: true,
globalProp: "indexedDB.deleteDatabase",
supports: SupportEnum.widelyAvailable
},
{
genProxyHandler: ctx => ({
createProxyHandler: ctx => ({
async apply(target, that, args) {
const dbs = (await Reflect.apply(
target,
Expand Down
8 changes: 4 additions & 4 deletions AeroSandbox/src/interceptors/storage/storage.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { type APIInterceptor, SupportEnum } from "$types/apiInterceptors";

import genStorageAPIInterceptors from "$util/storageAPIInterceptorsGeneric";
import createStorageAPIInterceptors from "$util/storageAPIInterceptorsGeneric";
import { proxyLocation } from "$shared/proxyLocation";

export default [
...genStorageAPIInterceptors("sharedStorage", $aero.sandbox.config.sharedStorageId),
...genStorageAPIInterceptors("storage", $aero.sandbox.config.storageStoreId),
...genStorageAPIInterceptors("sessionStorage", `${$aero.sandbox.config.sessionStoreId}_${$aero.clientId}`),
...createStorageAPIInterceptors("sharedStorage", $aero.sandbox.config.sharedStorageId),
...createStorageAPIInterceptors("storage", $aero.sandbox.config.storageStoreId),
...createStorageAPIInterceptors("sessionStorage", `${$aero.sandbox.config.sessionStoreId}_${$aero.clientId}`),
// This is needed for Session Storage only
{
init: () => {
Expand Down
4 changes: 2 additions & 2 deletions AeroSandbox/src/interceptors/util/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { storagePrefix } from "$shared/storage";

function genStorageNomenclatureHandlers(storeId): { [key: string]: ProxyHandler<Storage> } {
function createStorageNomenclatureHandlers(storeId): { [key: string]: ProxyHandler<Storage> } {
return {
prefix: {
apply: (target, that, args) => {
Expand Down Expand Up @@ -41,4 +41,4 @@ function unprefixKey(storeId: string, key: string): string {
return keyWithoutStoreIdKey;
}

export { genStorageNomenclatureHandlers, prefixKey, unprefixKey };
export { createStorageNomenclatureHandlers, prefixKey, unprefixKey };
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { type APIInterceptor, SupportEnum } from "$types/apiInterceptors.d.ts";

import { genStorageNomenclatureHandlers, unprefixKey } from "./storage";
import { createStorageNomenclatureHandlers, unprefixKey } from "./storage";
import { storagePrefix } from "$shared/storage";

export default function genStorageApiInterceptors(key: string, storeId: string): APIInterceptor[] {
const storageNomenclatureHandlers = genStorageNomenclatureHandlers(storeId);
export default function createStorageApiInterceptors(key: string, storeId: string): APIInterceptor[] {
const storageNomenclatureHandlers = createStorageNomenclatureHandlers(storeId);
const storageAPIInterceptorsGeneric = [
{
proxyHandler: {
Expand Down
80 changes: 40 additions & 40 deletions AeroSandbox/src/interceptors/util/swlessUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,65 +3,65 @@
/*
// This is what is already set in handleFetchEvent (whatever needs to be passed into handleFetchEvent)
interface FakeEventPartial {
request: Request;
request: Request;
}
function genFakeClientId(loc?: string) {
// TODO: Implement...
throw new Error("stub");
function createFakeClientId(loc?: string) {
// TODO: Implement...
throw new Error("stub");
}
function handleFetchEvent(
partialFakeEvent: FakeEventPartial,
reqDest = ""
partialFakeEvent: FakeEventPartial,
reqDest = ""
): Response | false {
let nonDefaultResp: Response | false = false;
let nonDefaultResp: Response | false = false;
// @ts-ignore
partialFakeEvent.destination = reqDest;
// @ts-ignore
partialFakeEvent.destination = reqDest;
let isReload = false;
let isReload = false;
if ("navigation" in window) {
const latestEntry =
window.performance.getEntriesByType("navigation")[0];
if (latestEntry) {
if ("type" in latestEntry)
isReload = latestEntry.type === "redirect";
}
}
if ("navigation" in window) {
const latestEntry =
window.performance.getEntriesByType("navigation")[0];
if (latestEntry) {
if ("type" in latestEntry)
isReload = latestEntry.type === "redirect";
}
}
// @ts-ignore
const fakeEvent: FetchEvent = {
...partialFakeEvent,
handled: async () => true, // TODO: I don't know how to implement this
isReload,
clientId: genFakeClientId(location.href),
replacesClientId: () =>
document.referrer ? genFakeClientId(document.referrer) : "",
resultingClientId: () =>
document.referrer !== document.referrer
? genFakeClientId(document.referrer)
: "",
// preloadResponse is processed in handleFetchInHTML only
respondWith: async func => {
nonDefaultResp = func(...arguments);
}
};
// @ts-ignore
const fakeEvent: FetchEvent = {
...partialFakeEvent,
handled: async () => true, // TODO: I don't know how to implement this
isReload,
clientId: createFakeClientId(location.href),
replacesClientId: () =>
document.referrer ? createFakeClientId(document.referrer) : "",
resultingClientId: () =>
document.referrer !== document.referrer
? createFakeClientId(document.referrer)
: "",
// preloadResponse is processed in handleFetchInHTML only
respondWith: async func => {
nonDefaultResp = func(...arguments);
}
};
const possibleResp = $aero.sandbox.swless.fetchhandler(fakeEvent);
if (possibleResp) nonDefaultResp = possibleResp;
const possibleResp = $aero.sandbox.swless.fetchhandler(fakeEvent);
if (possibleResp) nonDefaultResp = possibleResp;
return nonDefaultResp;
return nonDefaultResp;
}
// This will basically extend the handleFetchEvent class, but with the request destination provide
// tagname, request destination
const fetchInHTMLMap = new Map<string, string>();
// This abstracts a bit
function handleHTML(el: Element) {
if (el.preload) {
}
if (el.preload) {
}
}
export { handleFetchEvent, handleHTML };
Expand Down
2 changes: 1 addition & 1 deletion AeroSandbox/types/apiInterceptors.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export type APIInterceptorInitForAPI = {
export type APIInterceptorForProxyObjects = APIInterceptorGeneric & ({
proxyHandler: ProxyHandler<any>;
} | {
genProxyHandler: (ctx: GeneratorCtxTypeShared) => ProxyHandler<any>;
createProxyHandler: (ctx: GeneratorCtxTypeShared) => ProxyHandler<any>;
}) & ({
escapeFixes: GenericProxyHandler;
} | {
Expand Down

0 comments on commit 61d883d

Please sign in to comment.