Initial Sample.

This commit is contained in:
2024-06-03 20:23:50 +05:30
parent ef2b65f673
commit 5269ec3c66
2575 changed files with 282312 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
declare global {
interface Window {
__DEV__?: boolean;
}
}
declare const _default: typeof globalThis & Window;
export default _default;
//# sourceMappingURL=global.d.ts.map

View File

@@ -0,0 +1,14 @@
import { maybe } from "./maybe.js";
export default (maybe(function () { return globalThis; }) ||
maybe(function () { return window; }) ||
maybe(function () { return self; }) ||
maybe(function () { return global; }) || // We don't expect the Function constructor ever to be invoked at runtime, as
// long as at least one of globalThis, window, self, or global is defined, so
// we are under no obligation to make it easy for static analysis tools to
// detect syntactic usage of the Function constructor. If you think you can
// improve your static analysis to detect this obfuscation, think again. This
// is an arms race you cannot win, at least not in JavaScript.
maybe(function () {
return maybe.constructor("return this")();
}));
//# sourceMappingURL=global.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"global.js","sourceRoot":"","sources":["../../../src/utilities/globals/global.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AASnC,eAAe,CAAC,KAAK,CAAC,cAAM,OAAA,UAAU,EAAV,CAAU,CAAC;IACrC,KAAK,CAAC,cAAM,OAAA,MAAM,EAAN,CAAM,CAAC;IACnB,KAAK,CAAC,cAAM,OAAA,IAAI,EAAJ,CAAI,CAAC;IACjB,KAAK,CAAC,cAAM,OAAA,MAAM,EAAN,CAAM,CAAC;IACnB,6EAA6E;IAC7E,6EAA6E;IAC7E,0EAA0E;IAC1E,2EAA2E;IAC3E,6EAA6E;IAC7E,8DAA8D;IAC9D,KAAK,CAAC;QACJ,OAAO,KAAK,CAAC,WAAW,CAAC,aAAa,CAAC,EAAE,CAAC;IAC5C,CAAC,CAAC,CAA+B,CAAC","sourcesContent":["import { maybe } from \"./maybe.js\";\n\ndeclare global {\n const __DEV__: boolean; // will be removed in `dist` by the `postprocessDist` script\n interface Window {\n __DEV__?: boolean;\n }\n}\n\nexport default (maybe(() => globalThis) ||\n maybe(() => window) ||\n maybe(() => self) ||\n maybe(() => global) ||\n // We don't expect the Function constructor ever to be invoked at runtime, as\n // long as at least one of globalThis, window, self, or global is defined, so\n // we are under no obligation to make it easy for static analysis tools to\n // detect syntactic usage of the Function constructor. If you think you can\n // improve your static analysis to detect this obfuscation, think again. This\n // is an arms race you cannot win, at least not in JavaScript.\n maybe(function () {\n return maybe.constructor(\"return this\")();\n })) as typeof globalThis & Window;\n"]}

View File

@@ -0,0 +1,111 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var tsInvariant = require('ts-invariant');
var version = "3.9.5";
function maybe(thunk) {
try {
return thunk();
}
catch (_a) { }
}
var global$1 = (maybe(function () { return globalThis; }) ||
maybe(function () { return window; }) ||
maybe(function () { return self; }) ||
maybe(function () { return global; }) ||
maybe(function () {
return maybe.constructor("return this")();
}));
var prefixCounts = new Map();
function makeUniqueId(prefix) {
var count = prefixCounts.get(prefix) || 1;
prefixCounts.set(prefix, count + 1);
return "".concat(prefix, ":").concat(count, ":").concat(Math.random().toString(36).slice(2));
}
function stringifyForDisplay(value, space) {
if (space === void 0) { space = 0; }
var undefId = makeUniqueId("stringifyForDisplay");
return JSON.stringify(value, function (key, value) {
return value === void 0 ? undefId : value;
}, space)
.split(JSON.stringify(undefId))
.join("<undefined>");
}
function wrap(fn) {
return function (message) {
var args = [];
for (var _i = 1; _i < arguments.length; _i++) {
args[_i - 1] = arguments[_i];
}
if (typeof message === "number") {
var arg0 = message;
message = getHandledErrorMsg(arg0);
if (!message) {
message = getFallbackErrorMsg(arg0, args);
args = [];
}
}
fn.apply(void 0, [message].concat(args));
};
}
var invariant = Object.assign(function invariant(condition, message) {
var args = [];
for (var _i = 2; _i < arguments.length; _i++) {
args[_i - 2] = arguments[_i];
}
if (!condition) {
tsInvariant.invariant(condition, getHandledErrorMsg(message, args) || getFallbackErrorMsg(message, args));
}
}, {
debug: wrap(tsInvariant.invariant.debug),
log: wrap(tsInvariant.invariant.log),
warn: wrap(tsInvariant.invariant.warn),
error: wrap(tsInvariant.invariant.error),
});
function newInvariantError(message) {
var optionalParams = [];
for (var _i = 1; _i < arguments.length; _i++) {
optionalParams[_i - 1] = arguments[_i];
}
return new tsInvariant.InvariantError(getHandledErrorMsg(message, optionalParams) ||
getFallbackErrorMsg(message, optionalParams));
}
var ApolloErrorMessageHandler = Symbol.for("ApolloErrorMessageHandler_" + version);
function stringify(arg) {
return typeof arg == "string" ? arg : (stringifyForDisplay(arg, 2).slice(0, 1000));
}
function getHandledErrorMsg(message, messageArgs) {
if (messageArgs === void 0) { messageArgs = []; }
if (!message)
return;
return (global$1[ApolloErrorMessageHandler] &&
global$1[ApolloErrorMessageHandler](message, messageArgs.map(stringify)));
}
function getFallbackErrorMsg(message, messageArgs) {
if (messageArgs === void 0) { messageArgs = []; }
if (!message)
return;
return "An error occurred! For more details, see the full error text at https://go.apollo.dev/c/err#".concat(encodeURIComponent(JSON.stringify({
version: version,
message: message,
args: messageArgs.map(stringify),
})));
}
var DEV = globalThis.__DEV__ !== false;
exports.InvariantError = tsInvariant.InvariantError;
exports.DEV = DEV;
exports.__DEV__ = DEV;
exports.global = global$1;
exports.invariant = invariant;
exports.maybe = maybe;
exports.newInvariantError = newInvariantError;
//# sourceMappingURL=globals.cjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,111 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var tsInvariant = require('ts-invariant');
var version = "3.9.5";
function maybe(thunk) {
try {
return thunk();
}
catch (_a) { }
}
var global$1 = (maybe(function () { return globalThis; }) ||
maybe(function () { return window; }) ||
maybe(function () { return self; }) ||
maybe(function () { return global; }) ||
maybe(function () {
return maybe.constructor("return this")();
}));
var prefixCounts = new Map();
function makeUniqueId(prefix) {
var count = prefixCounts.get(prefix) || 1;
prefixCounts.set(prefix, count + 1);
return "".concat(prefix, ":").concat(count, ":").concat(Math.random().toString(36).slice(2));
}
function stringifyForDisplay(value, space) {
if (space === void 0) { space = 0; }
var undefId = makeUniqueId("stringifyForDisplay");
return JSON.stringify(value, function (key, value) {
return value === void 0 ? undefId : value;
}, space)
.split(JSON.stringify(undefId))
.join("<undefined>");
}
function wrap(fn) {
return function (message) {
var args = [];
for (var _i = 1; _i < arguments.length; _i++) {
args[_i - 1] = arguments[_i];
}
if (typeof message === "number") {
var arg0 = message;
message = getHandledErrorMsg(arg0);
if (!message) {
message = getFallbackErrorMsg(arg0, args);
args = [];
}
}
fn.apply(void 0, [message].concat(args));
};
}
var invariant = Object.assign(function invariant(condition, message) {
var args = [];
for (var _i = 2; _i < arguments.length; _i++) {
args[_i - 2] = arguments[_i];
}
if (!condition) {
tsInvariant.invariant(condition, getHandledErrorMsg(message, args) || getFallbackErrorMsg(message, args));
}
}, {
debug: wrap(tsInvariant.invariant.debug),
log: wrap(tsInvariant.invariant.log),
warn: wrap(tsInvariant.invariant.warn),
error: wrap(tsInvariant.invariant.error),
});
function newInvariantError(message) {
var optionalParams = [];
for (var _i = 1; _i < arguments.length; _i++) {
optionalParams[_i - 1] = arguments[_i];
}
return new tsInvariant.InvariantError(getHandledErrorMsg(message, optionalParams) ||
getFallbackErrorMsg(message, optionalParams));
}
var ApolloErrorMessageHandler = Symbol.for("ApolloErrorMessageHandler_" + version);
function stringify(arg) {
return typeof arg == "string" ? arg : (stringifyForDisplay(arg, 2).slice(0, 1000));
}
function getHandledErrorMsg(message, messageArgs) {
if (messageArgs === void 0) { messageArgs = []; }
if (!message)
return;
return (global$1[ApolloErrorMessageHandler] &&
global$1[ApolloErrorMessageHandler](message, messageArgs.map(stringify)));
}
function getFallbackErrorMsg(message, messageArgs) {
if (messageArgs === void 0) { messageArgs = []; }
if (!message)
return;
return "An error occurred! For more details, see the full error text at https://go.apollo.dev/c/err#".concat(encodeURIComponent(JSON.stringify({
version: version,
message: message,
args: messageArgs.map(stringify),
})));
}
var DEV = globalThis.__DEV__ !== false;
exports.InvariantError = tsInvariant.InvariantError;
exports.DEV = DEV;
exports.__DEV__ = DEV;
exports.global = global$1;
exports.invariant = invariant;
exports.maybe = maybe;
exports.newInvariantError = newInvariantError;
//# sourceMappingURL=globals.cjs.map

View File

@@ -0,0 +1,11 @@
import { invariant, newInvariantError, InvariantError } from "./invariantWrappers.js";
export { maybe } from "./maybe.js";
export { default as global } from "./global.js";
export { invariant, newInvariantError, InvariantError };
/**
* @deprecated we do not use this internally anymore,
* it is just exported for backwards compatibility
*/
export declare const DEV: boolean;
export { DEV as __DEV__ };
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1,14 @@
import { invariant, newInvariantError, InvariantError, } from "./invariantWrappers.js";
export { maybe } from "./maybe.js";
export { default as global } from "./global.js";
export { invariant, newInvariantError, InvariantError };
/**
* @deprecated we do not use this internally anymore,
* it is just exported for backwards compatibility
*/
// this file is extempt from automatic `__DEV__` replacement
// so we have to write it out here
// @ts-ignore
export var DEV = globalThis.__DEV__ !== false;
export { DEV as __DEV__ };
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utilities/globals/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,iBAAiB,EACjB,cAAc,GACf,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,cAAc,EAAE,CAAC;AAExD;;;GAGG;AACH,4DAA4D;AAC5D,kCAAkC;AAClC,aAAa;AACb,MAAM,CAAC,IAAM,GAAG,GAAG,UAAU,CAAC,OAAO,KAAK,KAAK,CAAC;AAChD,OAAO,EAAE,GAAG,IAAI,OAAO,EAAE,CAAC","sourcesContent":["import {\n invariant,\n newInvariantError,\n InvariantError,\n} from \"./invariantWrappers.js\";\n\nexport { maybe } from \"./maybe.js\";\nexport { default as global } from \"./global.js\";\nexport { invariant, newInvariantError, InvariantError };\n\n/**\n * @deprecated we do not use this internally anymore,\n * it is just exported for backwards compatibility\n */\n// this file is extempt from automatic `__DEV__` replacement\n// so we have to write it out here\n// @ts-ignore\nexport const DEV = globalThis.__DEV__ !== false;\nexport { DEV as __DEV__ };\n"]}

View File

@@ -0,0 +1,64 @@
import { InvariantError } from "ts-invariant";
import type { ErrorCodes } from "../../invariantErrorCodes.js";
type LogFunction = {
/**
* Logs a `$level` message if the user used `ts-invariant`'s `setVerbosity` to set
* a verbosity level of `$level` or lower. (defaults to `"log"`).
*
* The user will either be presented with a link to the documentation for the message,
* or they can use the `loadDevMessages` to add the message strings to the bundle.
* The documentation will display the message without argument substitution.
* Instead, the arguments will be printed on the console after the link.
*
* `message` can only be a string, a concatenation of strings, or a ternary statement
* that results in a string. This will be enforced on build, where the message will
* be replaced with a message number.
*
* String substitutions like %s, %o, %d or %f are supported.
*/
(message?: any, ...optionalParams: unknown[]): void;
};
type WrappedInvariant = {
/**
* Throws and InvariantError with the given message if the condition is false.
*
* `message` can only be a string, a concatenation of strings, or a ternary statement
* that results in a string. This will be enforced on build, where the message will
* be replaced with a message number.
*
* The user will either be presented with a link to the documentation for the message,
* or they can use the `loadErrorMessages` to add the message strings to the bundle.
* The documentation will display the message with the arguments substituted.
*
* String substitutions with %s are supported and will also return
* pretty-stringified objects.
* Excess `optionalParams` will be swallowed.
*/
(condition: any, message?: string | number, ...optionalParams: unknown[]): asserts condition;
debug: LogFunction;
log: LogFunction;
warn: LogFunction;
error: LogFunction;
};
declare const invariant: WrappedInvariant;
/**
* Returns an InvariantError.
*
* `message` can only be a string, a concatenation of strings, or a ternary statement
* that results in a string. This will be enforced on build, where the message will
* be replaced with a message number.
* String substitutions with %s are supported and will also return
* pretty-stringified objects.
* Excess `optionalParams` will be swallowed.
*/
declare function newInvariantError(message?: string | number, ...optionalParams: unknown[]): InvariantError;
declare const ApolloErrorMessageHandler: unique symbol;
declare global {
interface Window {
[ApolloErrorMessageHandler]?: {
(message: string | number, args: unknown[]): string | undefined;
} & ErrorCodes;
}
}
export { invariant, InvariantError, newInvariantError, ApolloErrorMessageHandler, };
//# sourceMappingURL=invariantWrappers.d.ts.map

View File

@@ -0,0 +1,76 @@
import { invariant as originalInvariant, InvariantError } from "ts-invariant";
import { version } from "../../version.js";
import global from "./global.js";
import { stringifyForDisplay } from "../common/stringifyForDisplay.js";
function wrap(fn) {
return function (message) {
var args = [];
for (var _i = 1; _i < arguments.length; _i++) {
args[_i - 1] = arguments[_i];
}
if (typeof message === "number") {
var arg0 = message;
message = getHandledErrorMsg(arg0);
if (!message) {
message = getFallbackErrorMsg(arg0, args);
args = [];
}
}
fn.apply(void 0, [message].concat(args));
};
}
var invariant = Object.assign(function invariant(condition, message) {
var args = [];
for (var _i = 2; _i < arguments.length; _i++) {
args[_i - 2] = arguments[_i];
}
if (!condition) {
originalInvariant(condition, getHandledErrorMsg(message, args) || getFallbackErrorMsg(message, args));
}
}, {
debug: wrap(originalInvariant.debug),
log: wrap(originalInvariant.log),
warn: wrap(originalInvariant.warn),
error: wrap(originalInvariant.error),
});
/**
* Returns an InvariantError.
*
* `message` can only be a string, a concatenation of strings, or a ternary statement
* that results in a string. This will be enforced on build, where the message will
* be replaced with a message number.
* String substitutions with %s are supported and will also return
* pretty-stringified objects.
* Excess `optionalParams` will be swallowed.
*/
function newInvariantError(message) {
var optionalParams = [];
for (var _i = 1; _i < arguments.length; _i++) {
optionalParams[_i - 1] = arguments[_i];
}
return new InvariantError(getHandledErrorMsg(message, optionalParams) ||
getFallbackErrorMsg(message, optionalParams));
}
var ApolloErrorMessageHandler = Symbol.for("ApolloErrorMessageHandler_" + version);
function stringify(arg) {
return typeof arg == "string" ? arg : (stringifyForDisplay(arg, 2).slice(0, 1000));
}
function getHandledErrorMsg(message, messageArgs) {
if (messageArgs === void 0) { messageArgs = []; }
if (!message)
return;
return (global[ApolloErrorMessageHandler] &&
global[ApolloErrorMessageHandler](message, messageArgs.map(stringify)));
}
function getFallbackErrorMsg(message, messageArgs) {
if (messageArgs === void 0) { messageArgs = []; }
if (!message)
return;
return "An error occurred! For more details, see the full error text at https://go.apollo.dev/c/err#".concat(encodeURIComponent(JSON.stringify({
version: version,
message: message,
args: messageArgs.map(stringify),
})));
}
export { invariant, InvariantError, newInvariantError, ApolloErrorMessageHandler, };
//# sourceMappingURL=invariantWrappers.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,2 @@
export declare function maybe<T>(thunk: () => T): T | undefined;
//# sourceMappingURL=maybe.d.ts.map

View File

@@ -0,0 +1,7 @@
export function maybe(thunk) {
try {
return thunk();
}
catch (_a) { }
}
//# sourceMappingURL=maybe.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"maybe.js","sourceRoot":"","sources":["../../../src/utilities/globals/maybe.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,KAAK,CAAI,KAAc;IACrC,IAAI,CAAC;QACH,OAAO,KAAK,EAAE,CAAC;IACjB,CAAC;IAAC,WAAM,CAAC,CAAA,CAAC;AACZ,CAAC","sourcesContent":["export function maybe<T>(thunk: () => T): T | undefined {\n try {\n return thunk();\n } catch {}\n}\n"]}

View File

@@ -0,0 +1,8 @@
{
"name": "@apollo/client/utilities/globals",
"type": "module",
"main": "globals.cjs",
"module": "index.js",
"types": "index.d.ts",
"sideEffects": true
}