Skip to content

Commit

Permalink
refactor(hub-sites): move getSiteById and supporting functions to hub…
Browse files Browse the repository at this point in the history
…-common

affects: @esri/hub-common, @esri/hub-sites
  • Loading branch information
drewdaemon committed Jul 22, 2021
1 parent 5669082 commit 8f00d39
Show file tree
Hide file tree
Showing 33 changed files with 559 additions and 546 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { IModel, getProp, cloneObject } from "@esri/hub-common";
import { getProp } from "../objects";
import { IModel } from "../types";
import { cloneObject } from "../util";

/**
* Apply the first schema version to the item
Expand All @@ -11,7 +13,7 @@ export function _applySiteSchema(model: IModel) {

const clone = cloneObject(model);
// proactively purge old properties
["groupId", "title"].forEach(prop => {
["groupId", "title"].forEach((prop) => {
delete clone.data.values[prop];
});
// ensure item.properties
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IModel, getProp, cloneObject } from "@esri/hub-common";
import { IModel, getProp, cloneObject } from "..";

/**
* Enforce lowercase domains
Expand All @@ -16,8 +16,8 @@ export function _enforceLowercaseDomains(model: IModel) {
"defaultHostname",
"internalUrl",
"customHostname",
"externalUrl"
].forEach(prop => {
"externalUrl",
].forEach((prop) => {
if (
clone.data.values[prop] &&
typeof clone.data.values[prop] === "string"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IModel, getProp, cloneObject } from "@esri/hub-common";
import { IModel, getProp, cloneObject } from "..";

/**
* Move the data.values.groups array into the
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import {
IModel,
getProp,
setProp,
deleteProp,
cloneObject,
IDraft
} from "@esri/hub-common";
import { IModel, IDraft, getProp, cloneObject, deleteProp, setProp } from "..";

/**
* Add telemetry config object
Expand All @@ -21,16 +14,16 @@ export function _ensureTelemetry<T extends IModel | IDraft>(model: T): T {
consentNotice: {
isTheme: true,
consentText: "",
policyURL: ""
policyURL: "",
},
customAnalytics: {
ga: {
customerTracker: {
enabled: Boolean(gacode),
id: gacode
}
}
}
id: gacode,
},
},
},
};
deleteProp(clone, "data.values.gacode");

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IModel, getProp, cloneObject, isGuid } from "@esri/hub-common";
import { IModel, getProp, cloneObject, isGuid } from "..";

/**
* Remove any non-guid entries from the data catalog groups array
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mergeObjects, IModel, IDraft } from "@esri/hub-common";
import { IModel, IDraft, mergeObjects } from "../..";

/**
* Builds a draft with a subset of the model properties
Expand Down
1 change: 1 addition & 0 deletions packages/common/src/sites/drafts/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./build-draft";
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IHubRequestOptions, getModel } from "@esri/hub-common";
import { upgradeSiteSchema } from "./upgrade-site-schema";
import { upgradeSiteSchema } from ".";
import { IHubRequestOptions, getModel } from "..";

/**
* Get a Site Model by it's Item Id, and apply schema upgrades
Expand Down
5 changes: 5 additions & 0 deletions packages/common/src/sites/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
export * from "./domains";
export * from "./drafts";
export * from "./_ensure-telemetry";
export * from "./get-site-by-id";
export * from "./site-schema-version";
export * from "./upgrade-site-schema";
1 change: 1 addition & 0 deletions packages/common/src/sites/site-schema-version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const SITE_SCHEMA_VERSION = 1.4;
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { IModel, getProp } from "@esri/hub-common";
import { IModel } from "../types";
import { getProp } from "../objects";
import { SITE_SCHEMA_VERSION } from "./site-schema-version";
import { _applySiteSchema } from "./_apply-site-schema";
import { _enforceLowercaseDomains } from "./_enforce-lowercase-domains";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { _applySiteSchema } from "../src";
import { IModel } from "@esri/hub-common";
import { IModel } from "../../src";
import { _applySiteSchema } from "../../src/sites/_apply-site-schema";

describe("_applySiteSchema", () => {
it("fixes groups array", function() {
const model = ({
it("fixes groups array", function () {
const model = {
item: {
id: "3ef",
properties: {}
properties: {},
},
data: {
values: {
groupId: "shouldberemoved",
title: "should also be remnoved",
groups: ["4bc", { id: "fromObj" }, "54b", { id: "secondObj" }]
}
}
} as unknown) as IModel;
groups: ["4bc", { id: "fromObj" }, "54b", { id: "secondObj" }],
},
},
} as unknown as IModel;
const chk = _applySiteSchema(model);
expect(chk.item.properties.schemaVersion).toBe(
1,
Expand All @@ -32,41 +32,41 @@ describe("_applySiteSchema", () => {
);
});

it("doesnt blow up with no groups or properties", function() {
const model = ({
it("doesnt blow up with no groups or properties", function () {
const model = {
item: {
id: "3ef"
id: "3ef",
},
data: {
values: {
groupId: "shouldberemoved",
title: "should also be remnoved"
}
}
} as unknown) as IModel;
title: "should also be remnoved",
},
},
} as unknown as IModel;
const chk = _applySiteSchema(model);
expect(chk.item.properties.schemaVersion).toBe(
1,
"should apply a schema version"
);
});

it("does nothing if schema >= 1", function() {
const model = ({
it("does nothing if schema >= 1", function () {
const model = {
item: {
id: "3ef",
properties: {
schemaVersion: 1
}
schemaVersion: 1,
},
},
data: {
values: {
groupId: "shouldberemoved",
title: "should also be remnoved",
groups: ["4bc", { id: "fromObj" }, "54b", { id: "secondObj" }]
}
}
} as unknown) as IModel;
groups: ["4bc", { id: "fromObj" }, "54b", { id: "secondObj" }],
},
},
} as unknown as IModel;
const chk = _applySiteSchema(model);
expect(chk).toEqual(model);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { _enforceLowercaseDomains } from "../src";
import { IModel } from "@esri/hub-common";
import { IModel } from "../../src";
import { _enforceLowercaseDomains } from "../../src/sites/_enforce-lowercase-domains";

describe("_enforceLowercaseDomains", () => {
it("enforces lowercase domains", async () => {
const model = ({
const model = {
item: {
properties: {
schemaVersion: 1.0
}
schemaVersion: 1.0,
},
},
data: {
values: {
subdomain: "Capitalized",
defaultHostname: "CaPitaliZed",
internalUrl: {} // not a string
}
}
} as unknown) as IModel;
internalUrl: {}, // not a string
},
},
} as unknown as IModel;

const chk = _enforceLowercaseDomains(model);

Expand All @@ -27,20 +27,20 @@ describe("_enforceLowercaseDomains", () => {
});

it("does nothing if schema >= 1.1", async () => {
const model = ({
const model = {
item: {
properties: {
schemaVersion: 1.1
}
schemaVersion: 1.1,
},
},
data: {
values: {
subdomain: "Capitalized",
defaultHostname: "CaPitaliZed",
internalUrl: {} // not a string
}
}
} as unknown) as IModel;
internalUrl: {}, // not a string
},
},
} as unknown as IModel;

const chk = _enforceLowercaseDomains(model);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { _ensureCatalog } from "../src";
import { IModel } from "@esri/hub-common";
import { IModel } from "../../src";
import { _ensureCatalog } from "../../src/sites/_ensure-catalog";

describe("_ensureCatalog", () => {
it("ensureCatalog adds data.catalog", function() {
const model = ({
it("ensureCatalog adds data.catalog", function () {
const model = {
item: {
id: "3ef",
properties: {}
properties: {},
},
data: {
values: {
groups: ["4bc", { id: "fromObj" }, "54b", { id: "secondObj" }]
}
}
} as unknown) as IModel;
groups: ["4bc", { id: "fromObj" }, "54b", { id: "secondObj" }],
},
},
} as unknown as IModel;
const chk = _ensureCatalog(model);
expect(chk.data.catalog).toBeTruthy("catalog should exist");
expect(Array.isArray(chk.data.catalog.groups)).toBeTruthy(
Expand All @@ -26,18 +26,18 @@ describe("_ensureCatalog", () => {
);
});

it("doesnt blow up with non-existant catalog", function() {
const model = ({
it("doesnt blow up with non-existant catalog", function () {
const model = {
item: {
id: "3ef",
properties: {
schemaVersion: 1
}
schemaVersion: 1,
},
},
data: {
// no catalog
}
} as unknown) as IModel;
},
} as unknown as IModel;
try {
const chk = _ensureCatalog(model);
expect(chk).toBeDefined();
Expand All @@ -46,20 +46,20 @@ describe("_ensureCatalog", () => {
}
});

it("skips templates greater than 1.2 schema version", function() {
const model = ({
it("skips templates greater than 1.2 schema version", function () {
const model = {
item: {
id: "3ef",
properties: {
schemaVersion: 2
}
schemaVersion: 2,
},
},
data: {
values: {
groups: ["4bc", { id: "fromObj" }, "54b", { id: "secondObj" }]
}
}
} as unknown) as IModel;
groups: ["4bc", { id: "fromObj" }, "54b", { id: "secondObj" }],
},
},
} as unknown as IModel;
const chk = _ensureCatalog(model);
expect(chk).toEqual(model);
});
Expand Down
Loading

0 comments on commit 8f00d39

Please sign in to comment.