Socket
Socket
Sign inDemoInstall

@glimmer/validator

Package Overview
Dependencies
Maintainers
13
Versions
143
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@glimmer/validator - npm Package Compare versions

Comparing version 0.85.5 to 0.85.6

679

dist/prod/index.js

@@ -1,679 +0,2 @@

import { assert, scheduleRevalidate } from '@glimmer/global-context';
import { getLast, asPresentArray } from '@glimmer/util';
function indexable(input) {
return input;
}
function getGlobal() {
// eslint-disable-next-line n/no-unsupported-features/es-builtins
if (typeof globalThis !== 'undefined') return indexable(globalThis);
if (typeof self !== 'undefined') return indexable(self);
if (typeof window !== 'undefined') return indexable(window);
if (typeof global !== 'undefined') return indexable(global);
throw new Error('unable to locate global object');
}
function unwrap(val) {
if (val === null || val === undefined) throw new Error(`Expected value to be present`);
return val;
}
const debug = {};
{
let CONSUMED_TAGS = null;
const TRANSACTION_STACK = [];
/////////
const TRANSACTION_ENV = {
debugMessage(obj, keyName) {
let objName;
if (typeof obj === 'function') {
objName = obj.name;
} else if (typeof obj === 'object' && obj !== null) {
let className = obj.constructor && obj.constructor.name || '(unknown class)';
objName = `(an instance of ${className})`;
} else if (obj === undefined) {
objName = '(an unknown tag)';
} else {
objName = String(obj);
}
let dirtyString = keyName ? `\`${keyName}\` on \`${objName}\`` : `\`${objName}\``;
return `You attempted to update ${dirtyString}, but it had already been used previously in the same computation. Attempting to update a value after using it in a computation can cause logical errors, infinite revalidation bugs, and performance issues, and is not supported.`;
}
};
debug.setTrackingTransactionEnv = env => Object.assign(TRANSACTION_ENV, env);
debug.beginTrackingTransaction = _debugLabel => {
CONSUMED_TAGS = CONSUMED_TAGS || new WeakMap();
let debugLabel = _debugLabel || undefined;
let parent = TRANSACTION_STACK[TRANSACTION_STACK.length - 1] ?? null;
TRANSACTION_STACK.push({
parent,
debugLabel
});
};
debug.endTrackingTransaction = () => {
if (TRANSACTION_STACK.length === 0) {
throw new Error('attempted to close a tracking transaction, but one was not open');
}
TRANSACTION_STACK.pop();
if (TRANSACTION_STACK.length === 0) {
CONSUMED_TAGS = null;
}
};
debug.resetTrackingTransaction = () => {
let stack = '';
if (TRANSACTION_STACK.length > 0) {
stack = debug.logTrackingStack(TRANSACTION_STACK[TRANSACTION_STACK.length - 1]);
}
TRANSACTION_STACK.splice(0, TRANSACTION_STACK.length);
CONSUMED_TAGS = null;
return stack;
};
/**
* Creates a global autotracking transaction. This will prevent any backflow
* in any `track` calls within the transaction, even if they are not
* externally consumed.
*
* `runInAutotrackingTransaction` can be called within itself, and it will add
* onto the existing transaction if one exists.
*
* TODO: Only throw an error if the `track` is consumed.
*/
debug.runInTrackingTransaction = (fn, debugLabel) => {
debug.beginTrackingTransaction(debugLabel);
let didError = true;
try {
let value = fn();
didError = false;
return value;
} finally {
if (didError !== true) {
debug.endTrackingTransaction();
}
// if (id !== TRANSACTION_STACK.length) {
// throw new Error(
// `attempted to close a tracking transaction (${id}), but it was not the last transaction (${TRANSACTION_STACK.length})`
// );
// }
}
};
let nthIndex = function (str, pattern, n) {
let startingPos = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : -1;
let i = startingPos;
while (n-- > 0 && i++ < str.length) {
i = str.indexOf(pattern, i);
if (i < 0) break;
}
return i;
};
let makeTrackingErrorMessage = (transaction, obj, keyName) => {
let message = [TRANSACTION_ENV.debugMessage(obj, keyName && String(keyName))];
message.push(`\`${String(keyName)}\` was first used:`);
message.push(debug.logTrackingStack(transaction));
message.push(`Stack trace for the update:`);
return message.join('\n\n');
};
debug.logTrackingStack = transaction => {
let trackingStack = [];
let current = transaction || TRANSACTION_STACK[TRANSACTION_STACK.length - 1];
if (current === undefined) return '';
while (current) {
if (current.debugLabel) {
trackingStack.unshift(current.debugLabel);
}
current = current.parent;
}
// TODO: Use String.prototype.repeat here once we can drop support for IE11
return trackingStack.map((label, index) => Array(2 * index + 1).join(' ') + label).join('\n');
};
debug.markTagAsConsumed = _tag => {
if (!CONSUMED_TAGS || CONSUMED_TAGS.has(_tag)) return;
CONSUMED_TAGS.set(_tag, getLast(asPresentArray(TRANSACTION_STACK)));
// We need to mark the tag and all of its subtags as consumed, so we need to
// cast it and access its internals. In the future this shouldn't be necessary,
// this is only for computed properties.
let subtag = _tag.subtag;
if (!subtag || !debug.markTagAsConsumed) return;
if (Array.isArray(subtag)) {
subtag.forEach(debug.markTagAsConsumed);
} else {
debug.markTagAsConsumed(subtag);
}
};
debug.assertTagNotConsumed = (tag, obj, keyName) => {
if (CONSUMED_TAGS === null) return;
let transaction = CONSUMED_TAGS.get(tag);
if (!transaction) return;
// This hack makes the assertion message nicer, we can cut off the first
// few lines of the stack trace and let users know where the actual error
// occurred.
try {
assert(false, makeTrackingErrorMessage(transaction, obj, keyName));
} catch (e) {
if (hasStack(e)) {
let updateStackBegin = e.stack.indexOf('Stack trace for the update:');
if (updateStackBegin !== -1) {
let start = nthIndex(e.stack, '\n', 1, updateStackBegin);
let end = nthIndex(e.stack, '\n', 4, updateStackBegin);
e.stack = e.stack.substr(0, start) + e.stack.substr(end);
}
}
throw e;
}
};
}
function hasStack(error) {
return typeof error === 'object' && error !== null && 'stack' in error && typeof error.stack === 'string';
}
//////////
const CONSTANT = 0;
const INITIAL = 1;
const VOLATILE = NaN;
let $REVISION = INITIAL;
function bump() {
$REVISION++;
}
//////////
const DIRYTABLE_TAG_ID = 0;
const UPDATABLE_TAG_ID = 1;
const COMBINATOR_TAG_ID = 2;
const CONSTANT_TAG_ID = 3;
//////////
const COMPUTE = Symbol('TAG_COMPUTE');
//////////
/**
* `value` receives a tag and returns an opaque Revision based on that tag. This
* snapshot can then later be passed to `validate` with the same tag to
* determine if the tag has changed at all since the time that `value` was
* called.
*
* @param tag
*/
function valueForTag(tag) {
return tag[COMPUTE]();
}
/**
* `validate` receives a tag and a snapshot from a previous call to `value` with
* the same tag, and determines if the tag is still valid compared to the
* snapshot. If the tag's state has changed at all since then, `validate` will
* return false, otherwise it will return true. This is used to determine if a
* calculation related to the tags should be rerun.
*
* @param tag
* @param snapshot
*/
function validateTag(tag, snapshot) {
return snapshot >= tag[COMPUTE]();
}
//////////
const TYPE = Symbol('TAG_TYPE');
// this is basically a const
let ALLOW_CYCLES;
{
ALLOW_CYCLES = new WeakMap();
}
function allowsCycles(tag) {
if (ALLOW_CYCLES === undefined) {
return true;
} else {
return ALLOW_CYCLES.has(tag);
}
}
class MonomorphicTagImpl {
static combine(tags) {
switch (tags.length) {
case 0:
return CONSTANT_TAG;
case 1:
return tags[0];
default:
{
let tag = new MonomorphicTagImpl(COMBINATOR_TAG_ID);
tag.subtag = tags;
return tag;
}
}
}
revision = INITIAL;
lastChecked = INITIAL;
lastValue = INITIAL;
isUpdating = false;
subtag = null;
subtagBufferCache = null;
[TYPE];
constructor(type) {
this[TYPE] = type;
}
[COMPUTE]() {
let {
lastChecked
} = this;
if (this.isUpdating === true) {
if (!allowsCycles(this)) {
throw new Error('Cycles in tags are not allowed');
}
this.lastChecked = ++$REVISION;
} else if (lastChecked !== $REVISION) {
this.isUpdating = true;
this.lastChecked = $REVISION;
try {
let {
subtag,
revision
} = this;
if (subtag !== null) {
if (Array.isArray(subtag)) {
for (const tag of subtag) {
let value = tag[COMPUTE]();
revision = Math.max(value, revision);
}
} else {
let subtagValue = subtag[COMPUTE]();
if (subtagValue === this.subtagBufferCache) {
revision = Math.max(revision, this.lastValue);
} else {
// Clear the temporary buffer cache
this.subtagBufferCache = null;
revision = Math.max(revision, subtagValue);
}
}
}
this.lastValue = revision;
} finally {
this.isUpdating = false;
}
}
return this.lastValue;
}
static updateTag(_tag, _subtag) {
if (_tag[TYPE] !== UPDATABLE_TAG_ID) {
throw new Error('Attempted to update a tag that was not updatable');
}
// TODO: TS 3.7 should allow us to do this via assertion
let tag = _tag;
let subtag = _subtag;
if (subtag === CONSTANT_TAG) {
tag.subtag = null;
} else {
// There are two different possibilities when updating a subtag:
//
// 1. subtag[COMPUTE]() <= tag[COMPUTE]();
// 2. subtag[COMPUTE]() > tag[COMPUTE]();
//
// The first possibility is completely fine within our caching model, but
// the second possibility presents a problem. If the parent tag has
// already been read, then it's value is cached and will not update to
// reflect the subtag's greater value. Next time the cache is busted, the
// subtag's value _will_ be read, and it's value will be _greater_ than
// the saved snapshot of the parent, causing the resulting calculation to
// be rerun erroneously.
//
// In order to prevent this, when we first update to a new subtag we store
// its computed value, and then check against that computed value on
// subsequent updates. If its value hasn't changed, then we return the
// parent's previous value. Once the subtag changes for the first time,
// we clear the cache and everything is finally in sync with the parent.
tag.subtagBufferCache = subtag[COMPUTE]();
tag.subtag = subtag;
}
}
static dirtyTag(tag, disableConsumptionAssertion) {
if (!(tag[TYPE] === UPDATABLE_TAG_ID || tag[TYPE] === DIRYTABLE_TAG_ID)) {
throw new Error('Attempted to dirty a tag that was not dirtyable');
}
if (disableConsumptionAssertion !== true) {
// Usually by this point, we've already asserted with better error information,
// but this is our last line of defense.
unwrap(debug.assertTagNotConsumed)(tag);
}
tag.revision = ++$REVISION;
scheduleRevalidate();
}
}
const DIRTY_TAG = MonomorphicTagImpl.dirtyTag;
const UPDATE_TAG = MonomorphicTagImpl.updateTag;
//////////
function createTag() {
return new MonomorphicTagImpl(DIRYTABLE_TAG_ID);
}
function createUpdatableTag() {
return new MonomorphicTagImpl(UPDATABLE_TAG_ID);
}
//////////
const CONSTANT_TAG = new MonomorphicTagImpl(CONSTANT_TAG_ID);
function isConstTag(tag) {
return tag === CONSTANT_TAG;
}
//////////
const VOLATILE_TAG_ID = 100;
class VolatileTag {
[TYPE] = VOLATILE_TAG_ID;
[COMPUTE]() {
return VOLATILE;
}
}
const VOLATILE_TAG = new VolatileTag();
//////////
const CURRENT_TAG_ID = 101;
class CurrentTag {
[TYPE] = CURRENT_TAG_ID;
[COMPUTE]() {
return $REVISION;
}
}
const CURRENT_TAG = new CurrentTag();
//////////
const combine = MonomorphicTagImpl.combine;
// Warm
let tag1 = createUpdatableTag();
let tag2 = createUpdatableTag();
let tag3 = createUpdatableTag();
valueForTag(tag1);
DIRTY_TAG(tag1);
valueForTag(tag1);
UPDATE_TAG(tag1, combine([tag2, tag3]));
valueForTag(tag1);
DIRTY_TAG(tag2);
valueForTag(tag1);
DIRTY_TAG(tag3);
valueForTag(tag1);
UPDATE_TAG(tag1, tag3);
valueForTag(tag1);
DIRTY_TAG(tag3);
valueForTag(tag1);
function isObjectLike(u) {
return typeof u === 'object' && u !== null || typeof u === 'function';
}
///////////
const TRACKED_TAGS = new WeakMap();
function dirtyTagFor(obj, key, meta) {
if (!isObjectLike(obj)) {
throw new Error(`BUG: Can't update a tag for a primitive`);
}
let tags = meta === undefined ? TRACKED_TAGS.get(obj) : meta;
// No tags have been setup for this object yet, return
if (tags === undefined) return;
// Dirty the tag for the specific property if it exists
let propertyTag = tags.get(key);
if (propertyTag !== undefined) {
{
unwrap(debug.assertTagNotConsumed)(propertyTag, obj, key);
}
DIRTY_TAG(propertyTag, true);
}
}
function tagMetaFor(obj) {
let tags = TRACKED_TAGS.get(obj);
if (tags === undefined) {
tags = new Map();
TRACKED_TAGS.set(obj, tags);
}
return tags;
}
function tagFor(obj, key, meta) {
let tags = meta === undefined ? tagMetaFor(obj) : meta;
let tag = tags.get(key);
if (tag === undefined) {
tag = createUpdatableTag();
tags.set(key, tag);
}
return tag;
}
/**
* An object that that tracks @tracked properties that were consumed.
*/
class Tracker {
tags = new Set();
last = null;
add(tag) {
if (tag === CONSTANT_TAG) return;
this.tags.add(tag);
{
unwrap(debug.markTagAsConsumed)(tag);
}
this.last = tag;
}
combine() {
let {
tags
} = this;
if (tags.size === 0) {
return CONSTANT_TAG;
} else if (tags.size === 1) {
return this.last;
} else {
let tagsArr = [];
tags.forEach(tag => tagsArr.push(tag));
return combine(tagsArr);
}
}
}
/**
* Whenever a tracked computed property is entered, the current tracker is
* saved off and a new tracker is replaced.
*
* Any tracked properties consumed are added to the current tracker.
*
* When a tracked computed property is exited, the tracker's tags are
* combined and added to the parent tracker.
*
* The consequence is that each tracked computed property has a tag
* that corresponds to the tracked properties consumed inside of
* itself, including child tracked computed properties.
*/
let CURRENT_TRACKER = null;
const OPEN_TRACK_FRAMES = [];
function beginTrackFrame(debuggingContext) {
OPEN_TRACK_FRAMES.push(CURRENT_TRACKER);
CURRENT_TRACKER = new Tracker();
{
unwrap(debug.beginTrackingTransaction)(debuggingContext);
}
}
function endTrackFrame() {
let current = CURRENT_TRACKER;
{
if (OPEN_TRACK_FRAMES.length === 0) {
throw new Error('attempted to close a tracking frame, but one was not open');
}
unwrap(debug.endTrackingTransaction)();
}
CURRENT_TRACKER = OPEN_TRACK_FRAMES.pop() || null;
return unwrap(current).combine();
}
function beginUntrackFrame() {
OPEN_TRACK_FRAMES.push(CURRENT_TRACKER);
CURRENT_TRACKER = null;
}
function endUntrackFrame() {
if (OPEN_TRACK_FRAMES.length === 0) {
throw new Error('attempted to close a tracking frame, but one was not open');
}
CURRENT_TRACKER = OPEN_TRACK_FRAMES.pop() || null;
}
// This function is only for handling errors and resetting to a valid state
function resetTracking() {
while (OPEN_TRACK_FRAMES.length > 0) {
OPEN_TRACK_FRAMES.pop();
}
CURRENT_TRACKER = null;
{
return unwrap(debug.resetTrackingTransaction)();
}
}
function isTracking() {
return CURRENT_TRACKER !== null;
}
function consumeTag(tag) {
if (CURRENT_TRACKER !== null) {
CURRENT_TRACKER.add(tag);
}
}
// public interface
const FN = Symbol('FN');
const LAST_VALUE = Symbol('LAST_VALUE');
const TAG = Symbol('TAG');
const SNAPSHOT = Symbol('SNAPSHOT');
const DEBUG_LABEL = Symbol('DEBUG_LABEL');
function createCache(fn, debuggingLabel) {
if (!(typeof fn === 'function')) {
throw new Error(`createCache() must be passed a function as its first parameter. Called with: ${String(fn)}`);
}
let cache = {
[FN]: fn,
[LAST_VALUE]: undefined,
[TAG]: undefined,
[SNAPSHOT]: -1
};
{
cache[DEBUG_LABEL] = debuggingLabel;
}
return cache;
}
function getValue(cache) {
assertCache(cache, 'getValue');
let fn = cache[FN];
let tag = cache[TAG];
let snapshot = cache[SNAPSHOT];
if (tag === undefined || !validateTag(tag, snapshot)) {
beginTrackFrame();
try {
cache[LAST_VALUE] = fn();
} finally {
tag = endTrackFrame();
cache[TAG] = tag;
cache[SNAPSHOT] = valueForTag(tag);
consumeTag(tag);
}
} else {
consumeTag(tag);
}
return cache[LAST_VALUE];
}
function isConst(cache) {
assertCache(cache, 'isConst');
let tag = cache[TAG];
assertTag(tag, cache);
return isConstTag(tag);
}
function assertCache(value, fnName) {
if (!(typeof value === 'object' && value !== null && FN in value)) {
throw new Error(`${fnName}() can only be used on an instance of a cache created with createCache(). Called with: ${String(value)}`);
}
}
// replace this with `expect` when we can
function assertTag(tag, cache) {
if (tag === undefined) {
throw new Error(`isConst() can only be used on a cache once getValue() has been called at least once. Called with cache function:\n\n${String(cache[FN])}`);
}
}
//////////
// Legacy tracking APIs
// track() shouldn't be necessary at all in the VM once the autotracking
// refactors are merged, and we should generally be moving away from it. It may
// be necessary in Ember for a while longer, but I think we'll be able to drop
// it in favor of cache sooner rather than later.
function track(block, debugLabel) {
beginTrackFrame(debugLabel);
let tag;
try {
block();
} finally {
tag = endTrackFrame();
}
return tag;
}
// untrack() is currently mainly used to handle places that were previously not
// tracked, and that tracking now would cause backtracking rerender assertions.
// I think once we move everyone forward onto modern APIs, we'll probably be
// able to remove it, but I'm not sure yet.
function untrack(callback) {
beginUntrackFrame();
try {
return callback();
} finally {
endUntrackFrame();
}
}
function trackedData(key, initializer) {
let values = new WeakMap();
let hasInitializer = typeof initializer === 'function';
function getter(self) {
consumeTag(tagFor(self, key));
let value;
// If the field has never been initialized, we should initialize it
if (hasInitializer && !values.has(self)) {
value = initializer.call(self);
values.set(self, value);
} else {
value = values.get(self);
}
return value;
}
function setter(self, value) {
dirtyTagFor(self, key);
values.set(self, value);
}
return {
getter,
setter
};
}
const GLIMMER_VALIDATOR_REGISTRATION = Symbol('GLIMMER_VALIDATOR_REGISTRATION');
const globalObj = getGlobal();
if (globalObj[GLIMMER_VALIDATOR_REGISTRATION] === true) {
throw new Error('The `@glimmer/validator` library has been included twice in this application. It could be different versions of the package, or the same version included twice by mistake. `@glimmer/validator` depends on having a single copy of the package in use at any time in an application, even if they are the same version. You must dedupe your build to remove the duplicate packages in order to prevent this error.');
}
globalObj[GLIMMER_VALIDATOR_REGISTRATION] = true;
export { ALLOW_CYCLES, COMPUTE, CONSTANT, CONSTANT_TAG, CURRENT_TAG, CurrentTag, INITIAL, VOLATILE, VOLATILE_TAG, VolatileTag, beginTrackFrame, beginUntrackFrame, bump, combine, consumeTag, createCache, createTag, createUpdatableTag, debug, DIRTY_TAG as dirtyTag, dirtyTagFor, endTrackFrame, endUntrackFrame, getValue, isConst, isConstTag, isTracking, resetTracking, tagFor, tagMetaFor, track, trackedData, untrack, UPDATE_TAG as updateTag, validateTag, valueForTag };
import{assert as t,scheduleRevalidate as e}from"@glimmer/global-context";import{getLast as n,asPresentArray as a}from"@glimmer/util";function r(t){if(null==t)throw new Error("Expected value to be present");return t}const i={};{let e=null;const r=[],o={debugMessage(t,e){let n;if("function"==typeof t)n=t.name;else if("object"==typeof t&&null!==t){n=`(an instance of ${t.constructor&&t.constructor.name||"(unknown class)"})`}else n=void 0===t?"(an unknown tag)":String(t);return`You attempted to update ${e?`\`${e}\` on \`${n}\``:`\`${n}\``}, but it had already been used previously in the same computation. Attempting to update a value after using it in a computation can cause logical errors, infinite revalidation bugs, and performance issues, and is not supported.`}};i.setTrackingTransactionEnv=t=>Object.assign(o,t),i.beginTrackingTransaction=t=>{e=e||new WeakMap;let n=t||void 0,a=r[r.length-1]??null;r.push({parent:a,debugLabel:n})},i.endTrackingTransaction=()=>{if(0===r.length)throw new Error("attempted to close a tracking transaction, but one was not open");r.pop(),0===r.length&&(e=null)},i.resetTrackingTransaction=()=>{let t="";return r.length>0&&(t=i.logTrackingStack(r[r.length-1])),r.splice(0,r.length),e=null,t},i.runInTrackingTransaction=(t,e)=>{i.beginTrackingTransaction(e);let n=!0;try{let e=t();return n=!1,e}finally{!0!==n&&i.endTrackingTransaction()}};let s=function(t,e,n){let a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:-1;for(;n-- >0&&a++<t.length&&(a=t.indexOf(e,a),!(a<0)););return a},l=(t,e,n)=>{let a=[o.debugMessage(e,n&&String(n))];return a.push(`\`${String(n)}\` was first used:`),a.push(i.logTrackingStack(t)),a.push("Stack trace for the update:"),a.join("\n\n")};i.logTrackingStack=t=>{let e=[],n=t||r[r.length-1];if(void 0===n)return"";for(;n;)n.debugLabel&&e.unshift(n.debugLabel),n=n.parent;return e.map(((t,e)=>Array(2*e+1).join(" ")+t)).join("\n")},i.markTagAsConsumed=t=>{if(!e||e.has(t))return;e.set(t,n(a(r)));let o=t.subtag;o&&i.markTagAsConsumed&&(Array.isArray(o)?o.forEach(i.markTagAsConsumed):i.markTagAsConsumed(o))},i.assertTagNotConsumed=(n,a,r)=>{if(null===e)return;let i=e.get(n);var o;if(i)try{t(!1,l(i,a,r))}catch(t){if("object"==typeof(o=t)&&null!==o&&"stack"in o&&"string"==typeof o.stack){let e=t.stack.indexOf("Stack trace for the update:");if(-1!==e){let n=s(t.stack,"\n",1,e),a=s(t.stack,"\n",4,e);t.stack=t.stack.substr(0,n)+t.stack.substr(a)}}throw t}}}const o=0,s=1,l=NaN;let u=1;function c(){u++}const f=1,g=Symbol("TAG_COMPUTE");function d(t){return t[g]()}function h(t,e){return e>=t[g]()}const p=Symbol("TAG_TYPE");let b;b=new WeakMap;class m{static combine(t){switch(t.length){case 0:return v;case 1:return t[0];default:{let e=new m(2);return e.subtag=t,e}}}revision=1;lastChecked=1;lastValue=1;isUpdating=!1;subtag=null;subtagBufferCache=null;[p];constructor(t){this[p]=t}[g](){let{lastChecked:t}=this;if(!0===this.isUpdating){if(e=this,void 0!==b&&!b.has(e))throw new Error("Cycles in tags are not allowed");this.lastChecked=++u}else if(t!==u){this.isUpdating=!0,this.lastChecked=u;try{let{subtag:t,revision:e}=this;if(null!==t)if(Array.isArray(t))for(const n of t){let t=n[g]();e=Math.max(t,e)}else{let n=t[g]();n===this.subtagBufferCache?e=Math.max(e,this.lastValue):(this.subtagBufferCache=null,e=Math.max(e,n))}this.lastValue=e}finally{this.isUpdating=!1}}var e;return this.lastValue}static updateTag(t,e){if(t[p]!==f)throw new Error("Attempted to update a tag that was not updatable");let n=t,a=e;a===v?n.subtag=null:(n.subtagBufferCache=a[g](),n.subtag=a)}static dirtyTag(t,n){if(t[p]!==f&&0!==t[p])throw new Error("Attempted to dirty a tag that was not dirtyable");!0!==n&&r(i.assertTagNotConsumed)(t),t.revision=++u,e()}}const w=m.dirtyTag,y=m.updateTag;function T(){return new m(0)}function k(){return new m(f)}const v=new m(3);function C(t){return t===v}class E{[p]=100;[g](){return NaN}}const S=new E;class A{[p]=101;[g](){return u}}const M=new A,N=m.combine;let $=k(),j=k(),L=k();d($),w($),d($),y($,N([j,L])),d($),w(j),d($),w(L),d($),y($,L),d($),w(L),d($);const x=new WeakMap;function U(t,e,n){if(("object"!=typeof(a=t)||null===a)&&"function"!=typeof a)throw new Error("BUG: Can't update a tag for a primitive");var a;let o=void 0===n?x.get(t):n;if(void 0===o)return;let s=o.get(e);void 0!==s&&(r(i.assertTagNotConsumed)(s,t,e),w(s,!0))}function V(t){let e=x.get(t);return void 0===e&&(e=new Map,x.set(t,e)),e}function B(t,e,n){let a=void 0===n?V(t):n,r=a.get(e);return void 0===r&&(r=k(),a.set(e,r)),r}class G{tags=new Set;last=null;add(t){t!==v&&(this.tags.add(t),r(i.markTagAsConsumed)(t),this.last=t)}combine(){let{tags:t}=this;if(0===t.size)return v;if(1===t.size)return this.last;{let e=[];return t.forEach((t=>e.push(t))),N(e)}}}let O=null;const I=[];function _(t){I.push(O),O=new G,r(i.beginTrackingTransaction)(t)}function R(){let t=O;if(0===I.length)throw new Error("attempted to close a tracking frame, but one was not open");return r(i.endTrackingTransaction)(),O=I.pop()||null,r(t).combine()}function W(){I.push(O),O=null}function P(){if(0===I.length)throw new Error("attempted to close a tracking frame, but one was not open");O=I.pop()||null}function Y(){for(;I.length>0;)I.pop();return O=null,r(i.resetTrackingTransaction)()}function z(){return null!==O}function D(t){null!==O&&O.add(t)}const F=Symbol("FN"),H=Symbol("LAST_VALUE"),q=Symbol("TAG"),J=Symbol("SNAPSHOT"),K=Symbol("DEBUG_LABEL");function Q(t,e){if("function"!=typeof t)throw new Error(`createCache() must be passed a function as its first parameter. Called with: ${String(t)}`);let n={[F]:t,[H]:void 0,[q]:void 0,[J]:-1};return n[K]=e,n}function X(t){tt(t,"getValue");let e=t[F],n=t[q],a=t[J];if(void 0!==n&&h(n,a))D(n);else{_();try{t[H]=e()}finally{n=R(),t[q]=n,t[J]=d(n),D(n)}}return t[H]}function Z(t){tt(t,"isConst");let e=t[q];return function(t,e){if(void 0===t)throw new Error(`isConst() can only be used on a cache once getValue() has been called at least once. Called with cache function:\n\n${String(e[F])}`)}(e,t),C(e)}function tt(t,e){if("object"!=typeof t||null===t||!(F in t))throw new Error(`${e}() can only be used on an instance of a cache created with createCache(). Called with: ${String(t)}`)}function et(t,e){let n;_(e);try{t()}finally{n=R()}return n}function nt(t){W();try{return t()}finally{P()}}function at(t,e){let n=new WeakMap,a="function"==typeof e;return{getter:function(r){let i;return D(B(r,t)),a&&!n.has(r)?(i=e.call(r),n.set(r,i)):i=n.get(r),i},setter:function(e,a){U(e,t),n.set(e,a)}}}const rt=Symbol("GLIMMER_VALIDATOR_REGISTRATION"),it=function(){if("undefined"!=typeof globalThis)return globalThis;if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if("undefined"!=typeof global)return global;throw new Error("unable to locate global object")}();if(!0===it[rt])throw new Error("The `@glimmer/validator` library has been included twice in this application. It could be different versions of the package, or the same version included twice by mistake. `@glimmer/validator` depends on having a single copy of the package in use at any time in an application, even if they are the same version. You must dedupe your build to remove the duplicate packages in order to prevent this error.");it[rt]=!0;export{b as ALLOW_CYCLES,g as COMPUTE,o as CONSTANT,v as CONSTANT_TAG,M as CURRENT_TAG,A as CurrentTag,s as INITIAL,l as VOLATILE,S as VOLATILE_TAG,E as VolatileTag,_ as beginTrackFrame,W as beginUntrackFrame,c as bump,N as combine,D as consumeTag,Q as createCache,T as createTag,k as createUpdatableTag,i as debug,w as dirtyTag,U as dirtyTagFor,R as endTrackFrame,P as endUntrackFrame,X as getValue,Z as isConst,C as isConstTag,z as isTracking,Y as resetTracking,B as tagFor,V as tagMetaFor,et as track,at as trackedData,nt as untrack,y as updateTag,h as validateTag,d as valueForTag};
//# sourceMappingURL=index.js.map

10

package.json
{
"name": "@glimmer/validator",
"type": "module",
"version": "0.85.5",
"version": "0.85.6",
"description": "Objects used to track values and their dirtiness in Glimmer",

@@ -17,5 +17,5 @@ "license": "MIT",

"@glimmer/env": "^0.1.7",
"@glimmer/global-context": "^0.85.5",
"@glimmer/interfaces": "^0.85.5",
"@glimmer/util": "^0.85.5"
"@glimmer/global-context": "^0.85.6",
"@glimmer/interfaces": "^0.85.6",
"@glimmer/util": "^0.85.6"
},

@@ -26,3 +26,3 @@ "devDependencies": {

"publint": "^0.2.5",
"@glimmer/local-debug-flags": "^0.85.5",
"@glimmer/local-debug-flags": "^0.85.6",
"@glimmer-workspace/build-support": "^1.0.0"

@@ -29,0 +29,0 @@ },

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc