Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const getClientId = () => {
const existing = store.get(ANONYMOUS_ANALYTICS_CLIENT_ID);
if (existing) {
return existing;
}
try {
return nanoid();
} catch (error) {
// The Web Crypto API is probably not supported
// Return a LEGACY-TIMESTAMP id
return `LEGACY-${(new Date()).getTime()}`;
}
};
ctx: FixSnapshotIdsContext
): AnyModel {
const { type, id } = sn[modelMetadataKey]
if (!id) {
throw failure(
`a model a snapshot must contain an id (${modelMetadataKey}.id) key, but none was found`
)
}
const modelInfo = getModelInfoForName(type)
if (!modelInfo) {
throw failure(`model with name "${type}" not found in the registry`)
}
const newId = nanoid()
ctx.idMap.set(id, newId)
const modelSn: any = {
[modelMetadataKey]: {
id: newId,
type,
},
}
const snKeys = Object.keys(sn)
const snKeysLen = snKeys.length
for (let i = 0; i < snKeysLen; i++) {
const k = snKeys[i]
if (!isReservedModelKey(k)) {
const v = sn[k]
modelSn[k] = internalFixSnapshotIds(v, ctx)
export function generateId(id) {
return id || nanoid(7);
}
function getId (prefix = '') {
return prefix + nanoid(7)
}