init commit

This commit is contained in:
rxliuli
2025-11-04 05:03:50 +08:00
commit bce557cc2d
1396 changed files with 172991 additions and 0 deletions

View File

@@ -0,0 +1,64 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ActionDispatcher = void 0;
const optional_1 = require("@jet/environment/types/optional");
class ActionDispatcher {
constructor(metricsPipeline) {
this.implementations = {};
this.metricsPipeline = metricsPipeline;
}
register(type, implementation) {
if (type in this.implementations) {
console.error(`An implementation is already registered for ${type}`);
}
this.implementations[type] = implementation;
}
async perform(action, metricsBehavior) {
if (!(action.$kind in this.implementations)) {
// 1. If there is no implementation registered for the type of action
// we were passed, we check for a chained dispatcher to forward to.
// If one is found, we forward this call without doing any work.
// If none is found, we give up.
if (optional_1.isSome(this.next)) {
return await this.next.perform(action, metricsBehavior);
}
else {
return "unsupported";
}
}
// 2. We have an implementation for the action we were given.
// We are responsible for processing metrics for that action.
this.processMetrics(action, metricsBehavior);
if (optional_1.isSome(this.next)) {
// 3a. If we have another dispatcher we are chained to, we forward to it
// if the implementation we have for the given action decides it cannot
// support performing it.
const outcome = await this.implementations[action.$kind](action);
if (outcome === "unsupported") {
return await this.next.perform(action, { behavior: "notProcessed" });
}
else {
return outcome;
}
}
else {
// 3b. We hand off control to the implementation we have for the given action type.
// If the implementation cannot perform the action, we give up.
return await this.implementations[action.$kind](action);
}
}
processMetrics(action, metricsBehavior) {
if (metricsBehavior.behavior === "notProcessed") {
return;
}
const actionMetrics = action.actionMetrics;
const context = {
customMetrics: actionMetrics.custom,
pageFields: metricsBehavior.context.pageFields,
};
action.actionMetrics.data.forEach((data) => {
void this.metricsPipeline.process(data, context);
});
}
}
exports.ActionDispatcher = ActionDispatcher;

13
node_modules/@jet/engine/lib/actions/index.js generated vendored Normal file
View File

@@ -0,0 +1,13 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./action-dispatcher"), exports);

17
node_modules/@jet/engine/lib/dependencies/index.js generated vendored Normal file
View File

@@ -0,0 +1,17 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./jet-bag"), exports);
__exportStar(require("./jet-host"), exports);
__exportStar(require("./jet-network-fetch"), exports);
__exportStar(require("./localized-strings-bundle"), exports);
__exportStar(require("./localized-strings-json-object"), exports);

40
node_modules/@jet/engine/lib/dependencies/jet-bag.js generated vendored Normal file
View File

@@ -0,0 +1,40 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.JetBag = void 0;
class JetBag {
constructor(backing) {
this.backing = backing;
}
registerBagKeys() {
// do nothing.
}
string(key) {
const value = this.backing[key];
return typeof value === "string" || value === null ? value : undefined;
}
double(key) {
const value = this.backing[key];
return typeof value === "number" || value === null ? value : undefined;
}
integer(key) {
const value = this.backing[key];
return typeof value === "number" || value === null ? value : undefined;
}
boolean(key) {
const value = this.backing[key];
return typeof value === "boolean" || value === null ? value : undefined;
}
array(key) {
const value = this.backing[key];
return Array.isArray(value) || value === null ? value : undefined;
}
dictionary(key) {
const value = this.backing[key];
return typeof value === "object" ? value : undefined;
}
url(key) {
const value = this.backing[key];
return typeof value === "string" ? value : undefined;
}
}
exports.JetBag = JetBag;

19
node_modules/@jet/engine/lib/dependencies/jet-host.js generated vendored Normal file
View File

@@ -0,0 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.JetHost = void 0;
class JetHost {
constructor(options) {
this.osBuild = "unknown";
this.deviceModel = "unknown";
this.deviceModelFamily = "unknown";
this.devicePhysicalModel = "unknown";
this.deviceLocalizedModel = "unknown";
this.clientIdentifier = "unknown";
this.clientVersion = "unknown";
this.platform = options.platform;
}
isOSAtLeast() {
return false;
}
}
exports.JetHost = JetHost;

View File

@@ -0,0 +1,39 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.JetNetworkFetch = void 0;
const optional_1 = require("@jet/environment/types/optional");
class JetNetworkFetch {
async fetch(request) {
var _a, _b, _c;
if (optional_1.isNothing(process === null || process === void 0 ? void 0 : process.env.MEDIA_API_TOKEN)) {
return await Promise.reject(new Error("process.env.MEDIA_API_TOKEN must be specified"));
}
const headers = {
...((_a = request.headers) !== null && _a !== void 0 ? _a : {}),
authorization: `Bearer ${process === null || process === void 0 ? void 0 : process.env.MEDIA_API_TOKEN}`,
};
const response = await fetch(request.url, {
body: request.body,
method: (_b = request.method) !== null && _b !== void 0 ? _b : undefined,
cache: (_c = request.cache) !== null && _c !== void 0 ? _c : undefined,
headers: headers,
});
return {
ok: response.ok,
headers: Array.from(response.headers.keys()).reduce((previous, key) => {
const value = response.headers.get(key);
if (optional_1.isSome(value)) {
previous[key] = value;
}
return previous;
}, {}),
redirected: response.redirected,
status: response.status,
statusText: response.statusText,
url: response.url,
body: await response.text(),
metrics: [],
};
}
}
exports.JetNetworkFetch = JetNetworkFetch;

View File

@@ -0,0 +1,68 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LocalizedStringsBundle = void 0;
const environment_1 = require("@jet/environment");
const localized_strings_json_object_1 = require("./localized-strings-json-object");
/**
* A localized string data source which loads strings from the application bundle.
*
* The bundle used by this data source can be a web app webpack bundle
* or a native app bundle bridged over to JS code.
*/
class LocalizedStringsBundle {
// MARK: - Initialization
/**
* Create localized strings bundle with all required attributes.
*
* @param bundle - The app bundle object.
*/
constructor(bundle) {
this.bundle = bundle;
}
// MARK: - LocalizedStringsDataSource
async fetchStrings(language) {
var _a;
// Load the strings from bundle and cache them.
const localizations = this.bundle.localizationsProperty;
if (environment_1.isNothing(localizations)) {
throw new Error("Localized strings bundle index file is missing 'localizations' property");
}
let strings;
const format = (_a = localizations.format) !== null && _a !== void 0 ? _a : "json/inline" /* jsonInline */;
if (format === "json/inline" /* jsonInline */) {
const inlineLocalizations = localizations;
strings = inlineLocalizations[language];
}
else {
const externalLocalizations = localizations;
switch (externalLocalizations.format) {
case "json/multi-file" /* jsonMultiFile */:
{
// The path points to directory where JSON files are located.
// We don't even have to list a directory, just construct a final path.
// The path is also not an OS path but a bundle (e.g. JetPack) path.
// Bundle APIs always use "/" in the path, same as the paths used in the
// index.json (manifest) files.
const jsonPath = `${externalLocalizations.path}/${language}.json`;
strings = (await this.bundle.loadResource(jsonPath));
}
break;
case "json/single-file" /* jsonSingleFile */:
// The bundle contains single JSON file with all strings dictionary in it.
strings = (await this.bundle.loadResource(externalLocalizations.path))[language];
break;
case "loctable" /* loctable */:
throw new Error("Loctable format not supported in JS implementation");
case "js" /* js */:
throw new Error("Not yet implemented");
default:
throw new Error(`Unknown localization format: ${JSON.stringify(format)}`);
}
}
if (environment_1.isNothing(strings)) {
throw new Error(`Missing strings for ${language}`);
}
return new localized_strings_json_object_1.LocalizedStringsJSONObject(strings);
}
}
exports.LocalizedStringsBundle = LocalizedStringsBundle;

View File

@@ -0,0 +1,21 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LocalizedStringsJSONObject = void 0;
/**
* A type providing access to underlying localized strings JSON object.
*/
class LocalizedStringsJSONObject {
/**
* Create localized strings JSON object.
*
* @param strings - A dictionary containing localized strings.
*/
constructor(strings) {
this.strings = strings;
}
// MARK: - Localized Strings
string(key) {
return this.strings[key];
}
}
exports.LocalizedStringsJSONObject = LocalizedStringsJSONObject;

15
node_modules/@jet/engine/lib/index.js generated vendored Normal file
View File

@@ -0,0 +1,15 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./actions"), exports);
__exportStar(require("./dependencies"), exports);
__exportStar(require("./metrics"), exports);

View File

@@ -0,0 +1,16 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./metrics-fields-aggregator"), exports);
__exportStar(require("./metrics-fields-builder"), exports);
__exportStar(require("./metrics-fields-context"), exports);
__exportStar(require("./metrics-fields-provider"), exports);

View File

@@ -0,0 +1,45 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MetricsFieldsAggregator = void 0;
const optional_1 = require("@jet/environment/types/optional");
const page_metrics_fields_provider_1 = require("../field-providers/page-metrics-fields-provider");
class MetricsFieldsAggregator {
constructor() {
this.optInProviders = new Map();
this.optOutProviders = new Map();
}
static makeDefaultAggregator() {
const aggregator = new MetricsFieldsAggregator();
aggregator.addOptInProvider(new page_metrics_fields_provider_1.PageMetricsFieldsProvider(), "pageFields");
return aggregator;
}
addOptInProvider(provider, request) {
this.optInProviders.set(request, provider);
}
addOptOutProvider(provider, request) {
this.optOutProviders.set(request, provider);
}
removeOptInProvider(request) {
this.optInProviders.delete(request);
}
removeOptOutProvider(request) {
this.optOutProviders.delete(request);
}
addMetricsFields(options) {
options.including.forEach((request) => {
const provider = this.optInProviders.get(request);
if (optional_1.isNothing(provider)) {
// No provider registered
return;
}
provider.addMetricsFields(options.builder, options.context);
});
this.optOutProviders.forEach((provider, request) => {
if (optional_1.isNothing(provider) || options.excluding.includes(request)) {
return;
}
provider.addMetricsFields(options.builder, options.context);
});
}
}
exports.MetricsFieldsAggregator = MetricsFieldsAggregator;

View File

@@ -0,0 +1,15 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SimpleMetricsFieldsBuilder = void 0;
class SimpleMetricsFieldsBuilder {
constructor(baseFields) {
this.fields = baseFields;
}
addValue(value, field) {
this.fields[field] = value;
}
get allMetricsFields() {
return this.fields;
}
}
exports.SimpleMetricsFieldsBuilder = SimpleMetricsFieldsBuilder;

View File

@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View File

@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View File

@@ -0,0 +1,13 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./page-metrics-fields-provider"), exports);

View File

@@ -0,0 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PageMetricsFieldsProvider = void 0;
const optional_1 = require("@jet/environment/types/optional");
class PageMetricsFieldsProvider {
addMetricsFields(builder, context) {
const pageFields = context.pageFields;
if (optional_1.isNothing(pageFields)) {
// No page fields
return;
}
for (const field in pageFields) {
if (Object.prototype.hasOwnProperty.call(pageFields, field)) {
builder.addValue(pageFields[field], field);
}
}
}
}
exports.PageMetricsFieldsProvider = PageMetricsFieldsProvider;

18
node_modules/@jet/engine/lib/metrics/index.js generated vendored Normal file
View File

@@ -0,0 +1,18 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./aggregating"), exports);
__exportStar(require("./field-providers"), exports);
__exportStar(require("./linting"), exports);
__exportStar(require("./presenters"), exports);
__exportStar(require("./metrics-pipeline"), exports);
__exportStar(require("./recording"), exports);

13
node_modules/@jet/engine/lib/metrics/linting/index.js generated vendored Normal file
View File

@@ -0,0 +1,13 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./metrics-event-linter"), exports);

View File

@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View File

@@ -0,0 +1,34 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MetricsPipeline = exports.FlushBehavior = void 0;
const metrics_fields_builder_1 = require("./aggregating/metrics-fields-builder");
var FlushBehavior;
(function (FlushBehavior) {
FlushBehavior[FlushBehavior["automatic"] = 0] = "automatic";
FlushBehavior[FlushBehavior["never"] = 1] = "never";
})(FlushBehavior = exports.FlushBehavior || (exports.FlushBehavior = {}));
class MetricsPipeline {
constructor(options) {
var _a;
this.aggregator = options.aggregator;
this.linter = options.linter;
this.recorder = options.recorder;
this.flushBehavior = (_a = options.flushBehavior) !== null && _a !== void 0 ? _a : FlushBehavior.automatic;
}
async process(data, context) {
const builder = new metrics_fields_builder_1.SimpleMetricsFieldsBuilder(data.fields);
this.aggregator.addMetricsFields({
including: data.includingFields,
excluding: data.excludingFields,
builder: builder,
context: context,
});
const lintedEvent = await this.linter.processEvent(builder.allMetricsFields);
this.recorder.record(lintedEvent, data.topic);
if (data.shouldFlush && this.flushBehavior === FlushBehavior.automatic) {
void this.recorder.flush();
}
return lintedEvent;
}
}
exports.MetricsPipeline = MetricsPipeline;

View File

@@ -0,0 +1,13 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./page-metrics-presenter"), exports);

View File

@@ -0,0 +1,52 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PageMetricsPresenter = void 0;
const optional_1 = require("@jet/environment/types/optional");
class PageMetricsPresenter {
constructor(metricsPipeline) {
this.metricsPipeline = metricsPipeline;
this.isViewAppeared = false;
}
set pageMetrics(pageMetrics) {
this.pageMetricsStore = pageMetrics;
if (optional_1.isSome(pageMetrics) && this.isViewAppeared) {
void this.processInstructions("pageEnter");
}
}
get pageMetrics() {
return this.pageMetricsStore;
}
async processInstructions(invocationPoint) {
var _a, _b, _c;
if (optional_1.isNothing(this.pageMetrics)) {
return;
}
// istanbul ignore next
const invocationContext = {
customMetrics: (_a = this.baseContext) === null || _a === void 0 ? void 0 : _a.customMetrics,
pageFields: {
...(_b = this.baseContext) === null || _b === void 0 ? void 0 : _b.pageFields,
...(_c = this.pageMetrics) === null || _c === void 0 ? void 0 : _c.pageFields,
},
};
await Promise.all(this.pageMetrics.instructions.map((instruction) => {
const { invocationPoints } = instruction;
if (invocationPoints.length === 0 || !invocationPoints.includes(invocationPoint)) {
return;
}
// eslint-disable-next-line @typescript-eslint/no-floating-promises
return this.metricsPipeline.process(instruction.data, invocationContext);
}));
}
async didEnterPage() {
this.isViewAppeared = true;
if (optional_1.isSome(this.pageMetrics)) {
await this.processInstructions("pageEnter");
}
}
async didLeavePage() {
await this.processInstructions("pageExit");
this.isViewAppeared = false;
}
}
exports.PageMetricsPresenter = PageMetricsPresenter;

View File

@@ -0,0 +1,14 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./logging-event-recorder"), exports);
__exportStar(require("./metrics-event-recorder"), exports);

View File

@@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LoggingEventRecorder = void 0;
class LoggingEventRecorder {
record(event) {
console.log(`Record Event [${String(event.fields.eventType)}]`, event);
}
async flush() {
console.log("Flushing");
return 0;
}
}
exports.LoggingEventRecorder = LoggingEventRecorder;

View File

@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View File

@@ -0,0 +1,23 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./models"), exports);
__exportStar(require("./types/globals"), exports);
__exportStar(require("./types/javascriptcore"), exports);
__exportStar(require("./types/metrics"), exports);
__exportStar(require("./types/models"), exports);
__exportStar(require("./types/optional"), exports);
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1,250 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.unexpectedNull = exports.catchingContext = exports.context = exports.recordValidationIncidents = exports.endContext = exports.getContextNames = exports.beginContext = exports.messageForRecoveryAction = exports.isValidatable = exports.unexpectedType = exports.extendedTypeof = void 0;
const optional_1 = require("../types/optional");
/**
* Returns a string containing the type of a given value.
* This function augments the built in `typeof` operator
* to return sensible values for arrays and null values.
*
* @privateRemarks
* This function is exported for testing.
*
* @param value - The value to find the type of.
* @returns A string containing the type of `value`.
*/
function extendedTypeof(value) {
if (Array.isArray(value)) {
return "array";
}
else if (value === null) {
return "null";
}
else {
return typeof value;
}
}
exports.extendedTypeof = extendedTypeof;
/**
* Reports a non-fatal validation failure, logging a message to the console.
* @param recovery - The recovery action taken when the bad type was found.
* @param expected - The expected type of the value.
* @param actual - The actual value.
* @param pathString - A string containing the path to the value on the object which failed type validation.
*/
function unexpectedType(recovery, expected, actual, pathString) {
const actualType = extendedTypeof(actual);
const prettyPath = (0, optional_1.isSome)(pathString) && pathString.length > 0 ? pathString : "<this>";
trackIncident({
type: "badType",
expected: expected,
// Our test assertions are matching the string interpolation of ${actual} value.
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
actual: `${actualType} (${actual})`,
objectPath: prettyPath,
contextNames: getContextNames(),
recoveryAction: recovery,
stack: new Error().stack,
});
}
exports.unexpectedType = unexpectedType;
// endregion
/**
* Determines if a given object conforms to the Validatable interface
* @param possibleValidatable - An object that might be considered validatable
*
* @returns `true` if it is an instance of Validatable, `false` if not
*/
function isValidatable(possibleValidatable) {
if ((0, optional_1.isNothing)(possibleValidatable)) {
return false;
}
// MAINTAINER'S NOTE: We must check for either the existence of a pre-existing incidents
// property *or* the ability to add one. Failure to do so will cause
// problems for clients that either a) use interfaces to define their
// view models; or b) return collections from their service routes.
return (Object.prototype.hasOwnProperty.call(possibleValidatable, "$incidents") ||
Object.isExtensible(possibleValidatable));
}
exports.isValidatable = isValidatable;
/**
* Returns a developer-readable diagnostic message for a given recovery action.
* @param action - The recovery action to get the message for.
* @returns The message for `action`.
*/
function messageForRecoveryAction(action) {
switch (action) {
case "coercedValue":
return "Coerced format";
case "defaultValue":
return "Default value used";
case "ignoredValue":
return "Ignored value";
default:
return "Unknown";
}
}
exports.messageForRecoveryAction = messageForRecoveryAction;
// region Contexts
/**
* Shared validation context "stack".
*
* Because validation incidents propagate up the context stack,
* the representation used here is optimized for memory usage.
* A more literal representation of this would be a singly linked
* list describing a basic stack, but that will produce a large
* amount of unnecessary garbage and require copying `incidents`
* arrays backwards.
*/
const contextState = {
/// The names of each validation context on the stack.
nameStack: Array(),
/// All incidents reported so far. Cleared when the
/// context stack is emptied.
incidents: Array(),
// TODO: Removal of this is being tracked here:
// <rdar://problem/35015460> Intro Pricing: Un-suppress missing parent 'offers' error when server address missing key
/// The paths for incidents we wish to forgo tracking.
suppressedIncidentPaths: Array(),
};
/**
* Begin a new validation context with a given name,
* pushing it onto the validation context stack.
* @param name - The name for the validation context.
*/
function beginContext(name) {
contextState.nameStack.push(name);
}
exports.beginContext = beginContext;
/**
* Traverses the validation context stack and collects all of the context names.
* @returns The names of all validation contexts on the stack, from oldest to newest.
*/
function getContextNames() {
if (contextState.nameStack.length === 0) {
return ["<empty stack>"];
}
return contextState.nameStack.slice(0);
}
exports.getContextNames = getContextNames;
/**
* Ends the current validation context
*/
function endContext() {
if (contextState.nameStack.length === 0) {
console.warn("endContext() called without active validation context, ignoring");
}
contextState.nameStack.pop();
}
exports.endContext = endContext;
/**
* Records validation incidents back into an object that implements Validatable.
*
* Note: This method has a side-effect that the incident queue and name stack are cleared
* to prepare for the next thread's invocation.
*
* @param possibleValidatable - An object that may conform to Validatable, onto which we
* want to stash our validation incidents
*/
function recordValidationIncidents(possibleValidatable) {
if (isValidatable(possibleValidatable)) {
possibleValidatable.$incidents = contextState.incidents;
}
contextState.incidents = [];
contextState.nameStack = [];
contextState.suppressedIncidentPaths = [];
}
exports.recordValidationIncidents = recordValidationIncidents;
/**
* Create a transient validation context, and call a function that will return a value.
*
* Prefer this function over manually calling begin/endContext,
* it is exception safe.
*
* @param name - The name of the context
* @param producer - A function that produces a result
* @returns <Result> The resulting type
*/
function context(name, producer, suppressingPath) {
let suppressingName = null;
if ((0, optional_1.isSome)(suppressingPath) && suppressingPath.length > 0) {
suppressingName = name;
contextState.suppressedIncidentPaths.push(suppressingPath);
}
let result;
try {
beginContext(name);
result = producer();
}
catch (e) {
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
if (!e.hasThrown) {
unexpectedType("defaultValue", "no exception", e.message);
e.hasThrown = true;
}
throw e;
}
finally {
if (name === suppressingName) {
contextState.suppressedIncidentPaths.pop();
}
endContext();
}
return result;
}
exports.context = context;
/**
* Create a transient validation context, that catches errors and returns null
*
* @param name - The name of the context
* @param producer - A function that produces a result
* @param caught - An optional handler to provide a value when an error is caught
* @returns <Result> The resulting type
*/
function catchingContext(name, producer, caught) {
let result = null;
try {
result = context(name, producer);
}
catch (e) {
result = null;
if ((0, optional_1.isSome)(caught)) {
result = caught(e);
}
}
return result;
}
exports.catchingContext = catchingContext;
/**
* Track an incident within the current validation context.
* @param incident - An incident object describing the problem.
*/
function trackIncident(incident) {
if (contextState.suppressedIncidentPaths.includes(incident.objectPath)) {
return;
}
contextState.incidents.push(incident);
}
// endregion
// region Nullability
/**
* Reports a non-fatal error indicating a value was unexpectedly null.
* @param recovery - The recovery action taken when the null value was found.
* @param expected - The expected type of the value.
* @param pathString - A string containing the path to the value on the object which was null.
*/
function unexpectedNull(recovery, expected, pathString) {
const prettyPath = (0, optional_1.isSome)(pathString) && pathString.length > 0 ? pathString : "<this>";
trackIncident({
type: "nullValue",
expected: expected,
actual: "null",
objectPath: prettyPath,
contextNames: getContextNames(),
recoveryAction: recovery,
stack: new Error().stack,
});
}
exports.unexpectedNull = unexpectedNull;
// endregion
//# sourceMappingURL=validation.js.map

View File

@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=alert-action.js.map

View File

@@ -0,0 +1,22 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.makeCompoundAction = exports.isCompoundAction = void 0;
/**
* Custom type guard to determine if an action is a CompoundAction.
*/
function isCompoundAction(action) {
return (action === null || action === void 0 ? void 0 : action.$kind) === "compoundAction";
}
exports.isCompoundAction = isCompoundAction;
/**
* Helper that returns a CompoundAction, given an ActionMetrics and ActionModel[] of subactions.
*/
function makeCompoundAction(actionMetrics, subactions) {
return {
$kind: "compoundAction",
subactions,
actionMetrics,
};
}
exports.makeCompoundAction = makeCompoundAction;
//# sourceMappingURL=compound-action.js.map

View File

@@ -0,0 +1,21 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.makeEmptyAction = exports.isEmptyAction = void 0;
/**
* Custom type guard to determine if an action is an EmptyAction.
*/
function isEmptyAction(action) {
return (action === null || action === void 0 ? void 0 : action.$kind) === "emptyAction";
}
exports.isEmptyAction = isEmptyAction;
/**
* Helper that returns an EmptyAction, given an ActionMetrics.
*/
function makeEmptyAction(actionMetrics) {
return {
$kind: "emptyAction",
actionMetrics,
};
}
exports.makeEmptyAction = makeEmptyAction;
//# sourceMappingURL=empty-action.js.map

View File

@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=external-url-action.js.map

View File

@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=flow-action.js.map

View File

@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=flow-back-action.js.map

View File

@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=http-action.js.map

View File

@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=http-template-action.js.map

View File

@@ -0,0 +1,26 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./alert-action"), exports);
__exportStar(require("./compound-action"), exports);
__exportStar(require("./empty-action"), exports);
__exportStar(require("./external-url-action"), exports);
__exportStar(require("./flow-action"), exports);
__exportStar(require("./flow-back-action"), exports);
__exportStar(require("./http-action"), exports);
__exportStar(require("./http-template-action"), exports);
__exportStar(require("./toast-action"), exports);
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=toast-action.js.map

View File

@@ -0,0 +1,39 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.makeArtworkURLTemplate = void 0;
const validation = require("../json/validation");
const optional_1 = require("../types/optional");
const urls_1 = require("../util/urls");
/**
* Regex to parse artwork URL template string.
*/
const URL_TEMPLATE_PARSER = new RegExp("^({w}|[0-9]+(?:.[0-9]*)?)x({h}|[0-9]+(?:.[0-9]*)?)({c}|[a-z]{2}).({f}|[a-z]+)$");
/**
* Create an instance of artwork URL template from string.
* @param fromString - String to create artwork URL template from.
* @returns A new artwork URL template or `null` if string
* does not represent a valid artwork URL template.
*/
function makeArtworkURLTemplate(fromString) {
// A valid URL that ends with '{w}x{h}{c}.{f}'
// with any of placeholders possibly resolved to an actual value.
const url = new urls_1.URL(fromString);
if (url.pathname === undefined) {
validation.context("makeArtworkURLTemplate", () => {
validation.unexpectedType("ignoredValue", "A valid URL string", fromString);
});
return null;
}
// Expecting 5 matches: whole string + width, height, crop code and format.
const lastPathComponent = fromString.substring(fromString.lastIndexOf("/") + 1);
const matches = URL_TEMPLATE_PARSER.exec(lastPathComponent);
if ((0, optional_1.isNothing)(matches) || matches.length !== 5) {
validation.context("makeArtworkURLTemplate", () => {
validation.unexpectedType("ignoredValue", "A valid artwork URL template ending with {w}x{h}{c}.{f} format", lastPathComponent);
});
return null;
}
return fromString;
}
exports.makeArtworkURLTemplate = makeArtworkURLTemplate;
//# sourceMappingURL=artwork.js.map

View File

@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=button.js.map

View File

@@ -0,0 +1,196 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.areEqual = exports.luminanceFrom = exports.dynamicWith = exports.named = exports.rgbWith = exports.htmlWith = exports.Color = void 0;
const optional_1 = require("../types/optional");
// endregion
// region Constructors
// eslint-disable-next-line no-redeclare, @typescript-eslint/no-redeclare
exports.Color = {
/**
* Create new `HTMLColor` from hexadecimal string representation.
*
* @param hexString - Hexadecimal string representation.
*/
fromHex(string) {
if ((0, optional_1.isNothing)(string)) {
return null;
}
return {
$kind: "html",
value: string,
};
},
/**
* Create new `RBGColor` with RGB components and opacity value.
*
* @param red - Red color value.
* @param green - Green color value.
* @param blue - Blue color value.
* @param alpha - Opacity value.
*/
fromRGB(red, green, blue, alpha = 1.0) {
const newColor = {
$kind: "rgb",
red: red,
green: green,
blue: blue,
alpha: alpha,
};
return newColor;
},
/**
* Create new named color using the color name.
*
* @param name - The name of the color.
*/
named(name) {
const newColor = {
$kind: "named",
name: name,
};
return newColor;
},
/**
* Create new dynamic color with light and dark color variants.
*
* @param lightColor - The light color variant.
* @param lightHighContrastColor - The light hight-contrast color variant.
* @param darkColor - The dark color variant.
* @param darkHighContrastColor - The dark hight-contrast color variant.
*/
dynamicWith(lightColor, lightHighContrastColor, darkColor, darkHighContrastColor) {
const newColor = {
$kind: "dynamic",
lightColor: lightColor,
lightHighContrastColor: lightHighContrastColor,
darkColor: darkColor,
darkHighContrastColor: darkHighContrastColor,
};
return newColor;
},
// endregion
// region Properties
/**
* Get the luminance of the color.
*
* @param rgbColor - The RGB color to get luminance for.
*/
luminanceFrom(rgbColor) {
// Note: This is lifted from UIColor_Private
// Using RGB color components, calculates and returns (0.2126 * r) + (0.7152 * g) + (0.0722 * b).
return rgbColor.red * 0.2126 + rgbColor.green * 0.7152 + rgbColor.blue * 0.0722;
},
// endregion
// region Identity
/**
* Compare two colors for equality.
*
* @param color1 - Left hand side color to compare.
* @param color2 - Right hand side color to compare.
* @returns A Boolean indicating whether the colors are equal.
*/
areEqual(color1, color2) {
if ((0, optional_1.isNothing)(color1)) {
return (0, optional_1.isNothing)(color2);
}
else if ((0, optional_1.isNothing)(color2)) {
return (0, optional_1.isNothing)(color1);
}
const kind1 = color1.$kind;
const kind2 = color2.$kind;
if (kind1 === "named" && kind2 === "named") {
const namedColor1 = color1;
const namedColor2 = color2;
return namedColor1.name === namedColor2.name;
}
else if (kind1 === "rgb" && kind2 === "rgb") {
const rgbColor1 = color1;
const rgbColor2 = color2;
return (rgbColor1.red === rgbColor2.red &&
rgbColor1.green === rgbColor2.green &&
rgbColor1.blue === rgbColor2.blue &&
rgbColor1.alpha === rgbColor2.alpha);
}
else if (kind1 === "dynamic" && kind2 === "dynamic") {
const dynamicColor1 = color1;
const dynamicColor2 = color2;
return (exports.Color.areEqual(dynamicColor1.lightColor, dynamicColor2.lightColor) &&
exports.Color.areEqual(dynamicColor1.lightHighContrastColor, dynamicColor2.lightHighContrastColor) &&
exports.Color.areEqual(dynamicColor1.darkColor, dynamicColor2.darkColor) &&
exports.Color.areEqual(dynamicColor1.darkHighContrastColor, dynamicColor2.darkHighContrastColor));
}
else {
return false;
}
},
};
/**
* Create new `HTMLColor` from hexadecimal string representation.
*
* @param hexString - Hexadecimal string representation.
*
* @deprecated This symbol has been moved to `Color.fromHex` and will be removed
* in the future.
*/
const htmlWith = exports.Color.fromHex;
exports.htmlWith = htmlWith;
/**
* Create new `RBGColor` with RGB components and opacity value.
*
* @param red - Red color value.
* @param green - Green color value.
* @param blue - Blue color value.
* @param alpha - Opacity value.
*
* @deprecated This symbol has been moved to `Color.fromRGB` and will be removed
* in the future.
*/
const rgbWith = exports.Color.fromRGB;
exports.rgbWith = rgbWith;
/**
* Create new named color using the color name.
*
* @param name - The name of the color.
*
* @deprecated This symbol has been moved to `Color.named` and will be removed
* in the future.
*/
const named = exports.Color.named;
exports.named = named;
/**
* Create new dynamic color with light and dark color variants.
*
* @param lightColor - The light color variant.
* @param lightHighContrastColor - The light hight-contrast color variant.
* @param darkColor - The dark color variant.
* @param darkHighContrastColor - The dark hight-contrast color variant.
*
* @deprecated This symbol has been moved to `Color.dynamicWith` and will be removed
* in the future.
*/
const dynamicWith = exports.Color.dynamicWith;
exports.dynamicWith = dynamicWith;
/**
* Get the luminance of the color.
*
* @param rgbColor - The RGB color to get luminance for.
*
* @deprecated This symbol has been moved to `Color.luminanceFrom` and will be removed
* in the future.
*/
const luminanceFrom = exports.Color.luminanceFrom;
exports.luminanceFrom = luminanceFrom;
/**
* Compare two colors for equality.
*
* @param color1 - Left hand side color to compare.
* @param color2 - Right hand side color to compare.
* @returns A Boolean indicating whether the colors are equal.
*
* @deprecated This symbol has been moved to `Color.areEqual` and will be removed
* in the future.
*/
const areEqual = exports.Color.areEqual;
exports.areEqual = areEqual;
// endregion
//# sourceMappingURL=color.js.map

View File

@@ -0,0 +1,25 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./actions"), exports);
__exportStar(require("./artwork"), exports);
__exportStar(require("./button"), exports);
__exportStar(require("./color"), exports);
__exportStar(require("./menu"), exports);
__exportStar(require("./paragraph"), exports);
__exportStar(require("./programmed-text"), exports);
__exportStar(require("./video"), exports);
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.menuSeparatorID = void 0;
/**
* A standard identifier for including a separator in a menu.
*/
exports.menuSeparatorID = "com.apple.JetEngine.separator";
//# sourceMappingURL=menu.js.map

View File

@@ -0,0 +1,4 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// endregion
//# sourceMappingURL=paragraph.js.map

View File

@@ -0,0 +1,5 @@
"use strict";
// region ProgrammedText
Object.defineProperty(exports, "__esModule", { value: true });
// endregion
//# sourceMappingURL=programmed-text.js.map

View File

@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=video.js.map

View File

@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=bag.js.map

View File

@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=bundle.js.map

View File

@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=cookie-provider.js.map

View File

@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=cryptography.js.map

View File

@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=host.js.map

View File

@@ -0,0 +1,55 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
/* `preprocessor` and `testContent` are normally replaced by inline literals while bundling an app's JS.
*
* If these values have not been set we want to provide defaults however
* attempting to access them can trigger a ReferenceError as the
* variables are undefined (distinct from a defined variable being set to
* `undefined`).
*
* `typeof` checks can safely test undefined variables, note that these checks will become:
* `typeof { DEBUG_BUILD: true, ... }` when webpack's DefinePlugin is used in @jet/build's webpack task.
* When these variables have not been replaced we need to use `globalThis` to set them on the global scope
* in order to avoid ReferenceErrors attempting to access them.
*/
if (typeof preprocessor === "undefined") {
globalThis.preprocessor = {
PRODUCTION_BUILD: false,
CARRY_BUILD: false,
DEBUG_BUILD: false,
INTERNAL_BUILD: false,
};
}
if (typeof testContent === "undefined") {
globalThis.testContent = {
INCLUDE_TEST_CONTENT: false,
};
}
__exportStar(require("./bag"), exports);
__exportStar(require("./bundle"), exports);
__exportStar(require("./cookie-provider"), exports);
__exportStar(require("./cryptography"), exports);
__exportStar(require("./host"), exports);
__exportStar(require("./jscookie"), exports);
__exportStar(require("./net"), exports);
__exportStar(require("./platform"), exports);
__exportStar(require("./plist"), exports);
__exportStar(require("./preprocessor"), exports);
__exportStar(require("./random"), exports);
__exportStar(require("./service"), exports);
__exportStar(require("./types"), exports);
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=jscookie.js.map

View File

@@ -0,0 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ProxiedNetwork = void 0;
/**
* `Network` object designed to wrap the bridged native network object,
* which automatically includes page intent instrumentation data in the fetch request.
*/
class ProxiedNetwork {
constructor(original, pageIntentInstrumentation) {
this.original = original;
this.pageIntentInstrumentation = pageIntentInstrumentation;
}
async fetch(request) {
request["$pageIntentInstrumentation"] = this.pageIntentInstrumentation;
return await this.original.fetch(request);
}
}
exports.ProxiedNetwork = ProxiedNetwork;
//# sourceMappingURL=net.js.map

View File

@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=platform.js.map

View File

@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=plist.js.map

View File

@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=preprocessor.js.map

View File

@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=random.js.map

View File

@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=service.js.map

View File

@@ -0,0 +1,16 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.services = exports.random = exports.plist = exports.platform = exports.net = exports.localizer = exports.host = exports.cryptography = exports.cookieProvider = exports.bundle = exports.bag = void 0;
const metatype_1 = require("../../util/metatype");
exports.bag = (0, metatype_1.makeMetatype)("jet-engine:bag");
exports.bundle = (0, metatype_1.makeMetatype)("jet-engine:bundle");
exports.cookieProvider = (0, metatype_1.makeMetatype)("jet-engine:cookieProvider");
exports.cryptography = (0, metatype_1.makeMetatype)("jet-engine:cryptography");
exports.host = (0, metatype_1.makeMetatype)("jet-engine:host");
exports.localizer = (0, metatype_1.makeMetatype)("jet-engine:localizer");
exports.net = (0, metatype_1.makeMetatype)("jet-engine:net");
exports.platform = (0, metatype_1.makeMetatype)("jet-engine:platform");
exports.plist = (0, metatype_1.makeMetatype)("jet-engine:plist");
exports.random = (0, metatype_1.makeMetatype)("jet-engine:random");
exports.services = (0, metatype_1.makeMetatype)("jet-engine:services");
//# sourceMappingURL=types.js.map

View File

@@ -0,0 +1,14 @@
"use strict";
/*
* Describes standard functionality available in JSContexts
*
* Types are defined here to allow us to match the behavior available in JSContext in the target OS
* which may not exactly match the definitions in standard TypeScript lib files, particularly on a
* pre-release OS.
*
* The living standard for the Console API is available at https://console.spec.whatwg.org
* The WebKit team has documented their interfaces at https://webkit.org/web-inspector/console-object-api/
* The equivalent interface in Node is https://nodejs.org/api/console.html
*/
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=console.js.map

View File

@@ -0,0 +1,18 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./console"), exports);
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1,57 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.notInstrumented = exports.PageInvocationPoint = exports.EMPTY_LINTED_METRICS_EVENT = void 0;
/**
* An empty linted metrics event.
*
* The empty events should be skipped from recording
* by metrics event recorders.
*/
exports.EMPTY_LINTED_METRICS_EVENT = {
fields: {},
issues: [],
};
var PageInvocationPoint;
(function (PageInvocationPoint) {
PageInvocationPoint["pageEnter"] = "pageEnter";
PageInvocationPoint["pageExit"] = "pageExit";
PageInvocationPoint["appExit"] = "appExit";
PageInvocationPoint["appEnter"] = "appEnter";
PageInvocationPoint["backButton"] = "backButton";
})(PageInvocationPoint = exports.PageInvocationPoint || (exports.PageInvocationPoint = {}));
/**
* Returns an empty metrics instance of the specified metrics type.
* @param metricsType - Type of the metrics data to return.
*
* @deprecated Do not use, all metrics events should be instrumented.
*/
function notInstrumented(metricsType) {
switch (metricsType) {
case 0 /* NotInstrumentedMetricsType.ActionMetrics */:
return {
data: [],
custom: {},
};
case 1 /* NotInstrumentedMetricsType.FetchTimingMetrics */:
return {};
case 2 /* NotInstrumentedMetricsType.PageMetrics */:
return {
instructions: [],
custom: {},
};
case 3 /* NotInstrumentedMetricsType.ImpressionMetrics */:
return {
id: {
id: "",
impressionIndex: NaN,
},
fields: {},
custom: {},
};
default:
return {};
}
}
exports.notInstrumented = notInstrumented;
// endregion
//# sourceMappingURL=metrics.js.map

View File

@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=models.js.map

View File

@@ -0,0 +1,71 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.flatMapOptional = exports.mapOptional = exports.unsafeUnwrapOptional = exports.unwrapOptional = exports.isSome = exports.isNothing = exports.unsafeUninitialized = void 0;
/**
* Bypass the protection provided by the `Optional` type
* and pretend to produce a value of `Some<T>` while
* actually returning `Nothing`.
*/
function unsafeUninitialized() {
return undefined;
}
exports.unsafeUninitialized = unsafeUninitialized;
/**
* Test whether an optional does not contain a value.
*
* @param value - An optional value to test.
*/
function isNothing(value) {
return value === undefined || value === null;
}
exports.isNothing = isNothing;
/**
* Test whether an optional contains a value.
* @param value - An optional value to test.
*/
function isSome(value) {
return value !== undefined && value !== null;
}
exports.isSome = isSome;
/**
* Unwrap the value contained in a given optional,
* throwing an error if there is no value.
*
* @param value - A value to unwrap.
*/
function unwrapOptional(value) {
if (isNothing(value)) {
throw new ReferenceError();
}
return value;
}
exports.unwrapOptional = unwrapOptional;
/**
* Unwrap the value contained in a given optional
* without checking if the value exists.
*
* @param value - A value to unwrap.
*/
function unsafeUnwrapOptional(value) {
return value;
}
exports.unsafeUnwrapOptional = unsafeUnwrapOptional;
function mapOptional(value, body) {
if (isSome(value)) {
return body(value);
}
else {
return value;
}
}
exports.mapOptional = mapOptional;
function flatMapOptional(value, body) {
if (isSome(value)) {
return body(value);
}
else {
return value;
}
}
exports.flatMapOptional = flatMapOptional;
//# sourceMappingURL=optional.js.map

View File

@@ -0,0 +1,10 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.makeMetatype = void 0;
function makeMetatype(name) {
return {
name: name,
};
}
exports.makeMetatype = makeMetatype;
//# sourceMappingURL=metatype.js.map

View File

@@ -0,0 +1,373 @@
"use strict";
// MARK: - Parsing Regular Expressions
Object.defineProperty(exports, "__esModule", { value: true });
exports.URL = void 0;
const optional_1 = require("../types/optional");
const protocolRegex = /^([a-z][a-z0-9.+-]*:)(\/\/)?([\S\s]*)/i;
const queryParamRegex = /([^=?&]+)=?([^&]*)/g;
const componentOrder = ["hash", "query", "pathname", "host"];
class URL {
constructor(url) {
var _a;
this.query = {};
if ((0, optional_1.isNothing)(url)) {
return;
}
// Split the protocol from the rest of the urls
let remainder = url;
const match = protocolRegex.exec(url);
if ((0, optional_1.isSome)(match)) {
// Pull out the protocol
let protocol = match[1];
if (protocol !== null && protocol !== undefined) {
protocol = protocol.split(":")[0];
}
this.protocol = protocol !== null && protocol !== void 0 ? protocol : undefined;
// Save the remainder
remainder = (_a = match[3]) !== null && _a !== void 0 ? _a : undefined;
}
// Then match each component in a specific order
let parse = { remainder: remainder, result: undefined };
for (const component of componentOrder) {
if (parse === undefined || parse.remainder === undefined) {
break;
}
switch (component) {
case "hash": {
parse = splitUrlComponent(parse.remainder, "#", "suffix");
this.hash = parse === null || parse === void 0 ? void 0 : parse.result;
break;
}
case "query": {
parse = splitUrlComponent(parse.remainder, "?", "suffix");
if ((parse === null || parse === void 0 ? void 0 : parse.result) !== undefined) {
this.query = URL.queryFromString(parse.result);
}
break;
}
case "pathname": {
parse = splitUrlComponent(parse.remainder, "/", "suffix");
if ((parse === null || parse === void 0 ? void 0 : parse.result) !== undefined) {
// Replace the initial /, since paths require it
this.pathname = "/" + parse.result;
}
break;
}
case "host": {
const authorityParse = splitUrlComponent(parse.remainder, "@", "prefix");
const userInfo = authorityParse === null || authorityParse === void 0 ? void 0 : authorityParse.result;
const hostPort = authorityParse === null || authorityParse === void 0 ? void 0 : authorityParse.remainder;
if (userInfo !== undefined) {
const userInfoSplit = userInfo.split(":");
this.username = decodeURIComponent(userInfoSplit[0]);
this.password = decodeURIComponent(userInfoSplit[1]);
}
if (hostPort !== undefined) {
const hostPortSplit = hostPort.split(":");
this.host = hostPortSplit[0];
this.port = hostPortSplit[1];
}
break;
}
default: {
throw new Error("Unhandled case!");
}
}
}
}
get(component) {
switch (component) {
// Exhaustive match to make sure TS property minifiers and other
// transformer plugins do not break this code.
case "protocol":
return this.protocol;
case "username":
return this.username;
case "password":
return this.password;
case "port":
return this.port;
case "pathname":
return this.pathname;
case "query":
return this.query;
case "hash":
return this.hash;
default:
// The fallback for component which is not a property of URL object.
return this[component];
}
}
set(component, value) {
if (value === undefined) {
return this;
}
if (component === "query") {
if (typeof value === "string") {
value = URL.queryFromString(value);
}
}
switch (component) {
// Exhaustive match to make sure TS property minifiers and other
// transformer plugins do not break this code.
case "protocol":
this.protocol = value;
break;
case "username":
this.username = value;
break;
case "password":
this.password = value;
break;
case "port":
this.port = value;
break;
case "pathname":
this.pathname = value;
break;
case "query":
this.query = value;
break;
case "hash":
this.hash = value;
break;
default:
// The fallback for component which is not a property of URL object.
this[component] = value;
break;
}
return this;
}
append(component, value) {
let existingValue = this.get(component);
let newValue;
if (component === "query") {
if (existingValue === undefined) {
existingValue = {};
}
if (typeof value === "string") {
value = URL.queryFromString(value);
}
if (typeof existingValue === "string") {
newValue = { existingValue, ...value };
}
else {
newValue = { ...existingValue, ...value };
}
}
else {
if (existingValue === undefined) {
existingValue = "";
}
let existingValueString = existingValue;
if (existingValueString === undefined) {
existingValueString = "";
}
let newValueString = existingValueString;
if (component === "pathname") {
const pathLength = existingValueString.length;
if (pathLength === 0 || existingValue[pathLength - 1] !== "/") {
newValueString += "/";
}
}
// The component is not "query" so we treat value as string.
// eslint-disable-next-line @typescript-eslint/no-base-to-string, @typescript-eslint/restrict-plus-operands
newValueString += value;
newValue = newValueString;
}
return this.set(component, newValue);
}
param(key, value) {
if (key === null) {
return this;
}
if (this.query === undefined) {
this.query = {};
}
if (value === undefined) {
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
delete this.query[key];
}
else {
this.query[key] = value;
}
return this;
}
removeParam(key) {
if (key === undefined || this.query === undefined) {
return this;
}
if (key in this.query) {
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
delete this.query[key];
}
return this;
}
path(value) {
return this.append("pathname", value);
}
pathExtension() {
var _a, _b;
// Extract path extension if one exists
if (this.pathname === undefined) {
return undefined;
}
const lastFilenameComponents = (_b = (_a = this.pathname
.split("/")
.filter((item) => item.length > 0) // Remove any double or trailing slashes
.pop()) === null || _a === void 0 ? void 0 : _a.split(".")) !== null && _b !== void 0 ? _b : [];
if (lastFilenameComponents.filter(function (part) {
return part !== "";
}).length < 2 // Remove any empty parts (e.g. .ssh_config -> ["ssh_config"])
) {
return undefined;
}
return lastFilenameComponents.pop();
}
/**
* Returns the path components of the URL
* @returns An array of non-empty path components from `urls`.
*/
pathComponents() {
if (this.pathname === undefined) {
return [];
}
return this.pathname.split("/").filter((component) => component.length > 0);
}
/**
* Same as toString
*
* @returns A string representation of the URL
*/
build() {
return this.toString();
}
/**
* Converts the URL to a string
*
* @returns A string representation of the URL
*/
toString() {
let url = "";
if (this.protocol !== undefined) {
url += this.protocol + "://";
}
if (this.username !== undefined) {
url += encodeURIComponent(this.username);
if (this.password !== undefined) {
url += ":" + encodeURIComponent(this.password);
}
url += "@";
}
if (this.host !== undefined) {
url += this.host;
if (this.port !== undefined) {
url += ":" + this.port;
}
}
if (this.pathname !== undefined) {
url += this.pathname;
}
if (this.query !== undefined && Object.keys(this.query).length !== 0) {
url += "?" + URL.toQueryString(this.query);
}
if (this.hash !== undefined) {
url += "#" + this.hash;
}
return url;
}
// ----------------
// Static API
// ----------------
/**
* Converts a string into a query dictionary
* @param query - The string to parse
* @returns The query dictionary containing the key-value pairs in the query string
*/
static queryFromString(query) {
const result = {};
let parseResult = queryParamRegex.exec(query);
while (parseResult !== null && parseResult.length >= 3) {
// We support the legacy query format for "application/x-www-form-urlencoded" which can represent spaces as "+" symbols.
// https://url.spec.whatwg.org/#concept-urlencoded-parser
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURIComponent#decoding_query_parameters_from_a_url
const key = decodeURIComponent(parseResult[1].replace(/\+/g, " "));
const value = decodeURIComponent(parseResult[2].replace(/\+/g, " "));
result[key] = value;
parseResult = queryParamRegex.exec(query);
}
return result;
}
/**
* Converts a query dictionary into a query string
*
* @param query - The query dictionary
* @returns The string representation of the query dictionary
*/
static toQueryString(query) {
let queryString = "";
let first = true;
for (const key of Object.keys(query)) {
if (!first) {
queryString += "&";
}
first = false;
queryString += encodeURIComponent(key);
const value = query[key];
if (value !== null && value.length > 0) {
queryString += "=" + encodeURIComponent(value);
}
}
return queryString;
}
/**
* Convenience method to instantiate a URL from a string
* @param url - The URL string to parse
* @returns The new URL object representing the URL
*/
static from(url) {
return new URL(url);
}
/**
* Convenience method to instantiate a URL from numerous (optional) components
* @param protocol - The protocol type
* @param host - The host name
* @param path - The path
* @param query - The query
* @param hash - The hash
* @returns The new URL object representing the URL
*/
static fromComponents(protocol, host, path, query, hash) {
const url = new URL();
url.protocol = protocol;
url.host = host;
url.pathname = path;
url.query = query !== null && query !== void 0 ? query : {};
url.hash = hash;
return url;
}
}
exports.URL = URL;
// MARK: - Helpers
function splitUrlComponent(input, marker, style) {
const index = input.indexOf(marker);
let result;
let remainder = input;
if (index !== -1) {
const prefix = input.slice(0, index);
const suffix = input.slice(index + marker.length, input.length);
if (style === "prefix") {
result = prefix;
remainder = suffix;
}
else {
result = suffix;
remainder = prefix;
}
}
return {
result: result,
remainder: remainder,
};
}
//# sourceMappingURL=urls.js.map