How to use the cuid.isCuid function in cuid

To help you get started, we’ve selected a few cuid examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github eventespresso / event-espresso-core / assets / src / data / eventespresso / core / actions / persist-relations-generators.js View on Github external
) {
	modelName = singularModelName( modelName );
	relationName = singularModelName( relationName );
	relationState = yield resolveDispatch(
		CORE_REDUCER_KEY,
		'getRelationState',
		modelName,
		addRelation,
		relationState
	);
	let entityIdChanged = false;
	if ( isEmpty( relationState ) ) {
		return 0;
	}
	// is the entityId a cuid?  If so, then let's persist.
	if ( cuid.isCuid( entityId ) ) {
		entityId = yield resolveDispatch(
			CORE_REDUCER_KEY,
			'persistNewEntityAndRemoveDirtyRelations',
			relationName,
			relationId,
			modelName,
			entityId,
			addRelation,
			[ modelName, entityId ],
		);
		// if entityId is 0 bail because it didn't get persisted so relations
		// can't be persisted either.
		if ( entityId === 0 ) {
			return entityId;
		}
		entityIdChanged = true;
github eventespresso / event-espresso-core / assets / src / data / eventespresso / core / reducers / dirty-relations.js View on Github external
);
			return state.set(
				'add',
				updateRelationState(
					Map( state.get( 'add' ) ),
					action,
					relationMap
				)
			);
		case types.RECEIVE_DIRTY_RELATION_DELETION:
		case types.REMOVE_DIRTY_RELATION_DELETION:
			// if the relation or entity id is a cuid, then we skip this because
			// the relation has never been persisted anyways.
			if (
				cuid.isCuid( action.relationEntityId ) ||
				cuid.isCuid( action.entityId )
			) {
				return state;
			}
			state = state.set(
				'index',
				indexRelations(
					Map( state.get( 'index' ) ),
					action,
					relationMap
				)
			);
			return state.set(
				'delete',
				updateRelationState(
					Map( state.get( 'delete' ) ),
					action,
github eventespresso / event-espresso-core / assets / ZZZ / editor / events / tickets / editor-ticket / edit-form / edit-ticket-form.js View on Github external
prefix,
		updateField,
		touchField
	});
	// entity properties we don't want to be editable
	const exclude = [
		'TKT_ID',
		'sold',
		'reserved',
		'order',
		'parent',
		'wpUser',
		'status'
	];

	const isNewTicket = cuid.isCuid(ticketEntity.TKT_ID);

	if (isNewTicket) {
		exclude.push('deleted');
	}

	const formRows = useEditEntityFormInputs(
		ticketEntity,
		inputConfig,
		prefix,
		currentValues,
		exclude
	);

	return useMemo(() => {
		// edit forms for existing objects must have initial values
		return !(!newObject && isEmpty(initialValues)) ? (
github eventespresso / event-espresso-core / assets / src / editor / events / tickets / editor-ticket / edit-form / edit-ticket-form.js View on Github external
prefix,
		updateField,
		touchField,
	} );
	// entity properties we don't want to be editable
	const exclude = [
		'TKT_ID',
		'sold',
		'reserved',
		'order',
		'parent',
		'wpUser',
		'status',
	];

	const isNewTicket = cuid.isCuid( ticketEntity.TKT_ID );

	if ( isNewTicket ) {
		exclude.push( 'deleted' );
	}

	const formRows = useEditEntityFormInputs(
		ticketEntity,
		inputConfig,
		prefix,
		currentValues,
		exclude
	);

	return useMemo(
		() => {
			// edit forms for existing objects must have initial values
github eventespresso / event-espresso-core / assets / src / data / eventespresso / core / reducers / dirty-relations.js View on Github external
)
			);
			return state.set(
				'add',
				updateRelationState(
					Map( state.get( 'add' ) ),
					action,
					relationMap
				)
			);
		case types.RECEIVE_DIRTY_RELATION_DELETION:
		case types.REMOVE_DIRTY_RELATION_DELETION:
			// if the relation or entity id is a cuid, then we skip this because
			// the relation has never been persisted anyways.
			if (
				cuid.isCuid( action.relationEntityId ) ||
				cuid.isCuid( action.entityId )
			) {
				return state;
			}
			state = state.set(
				'index',
				indexRelations(
					Map( state.get( 'index' ) ),
					action,
					relationMap
				)
			);
			return state.set(
				'delete',
				updateRelationState(
					Map( state.get( 'delete' ) ),
github eventespresso / event-espresso-core / assets / src / data / eventespresso / core / actions / persist-relations-generators.js View on Github external
relationId,
			modelName,
			entityId,
			addRelation,
			[ modelName, entityId ],
		);
		// if entityId is 0 bail because it didn't get persisted so relations
		// can't be persisted either.
		if ( entityId === 0 ) {
			return entityId;
		}
		entityIdChanged = true;
	}

	// is the relationId a cuid? If so, then let's persist
	if ( cuid.isCuid( relationId ) ) {
		relationId = yield resolveDispatch(
			CORE_REDUCER_KEY,
			'persistNewEntityAndRemoveDirtyRelations',
			relationName,
			relationId,
			modelName,
			entityId,
			addRelation,
			[ relationName, relationId ],
			! entityIdChanged,
		);
		// if relationId is 0, bail because it didn't get persisted so relations
		// can't be persisted either.
		if ( relationId === 0 ) {
			return relationId;
		}
github eventespresso / event-espresso-core / assets / src / data / helpers / normalize-entity-id.js View on Github external
export const normalizeEntityId = ( id ) => cuid.isCuid( id ) ?
	id :
	toInteger( id );

cuid

Collision-resistant ids optimized for horizontal scaling and performance. For node and browsers.

MIT
Latest version published 2 years ago

Package Health Score

61 / 100
Full package analysis