Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Use nanonid/non-secure instead of cuid #1912

Merged
merged 7 commits into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/toolpad-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
"cors": "^2.8.5",
"crypto-js": "^4.1.1",
"csstype": "^3.1.2",
"cuid": "^3.0.0",
"dayjs": "^1.11.7",
"dotenv": "^16.0.3",
"esbuild": "0.17.16",
Expand All @@ -85,6 +84,7 @@
"markdown-to-jsx": "^7.2.0",
"monaco-editor": "0.37.1",
"mysql2": "^3.2.2",
"nanoid": "^4.0.2",
"next": "^13.3.0",
"node-fetch": "^2.6.9",
"node-fetch-har": "^1.0.1",
Expand Down
6 changes: 3 additions & 3 deletions packages/toolpad-app/src/appDom/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { nanoid } from 'nanoid/non-secure';
import { generateKeyBetween } from 'fractional-indexing';
import cuid from 'cuid';
import {
NodeId,
NodeReference,
Expand Down Expand Up @@ -234,8 +234,8 @@ function assertIsType<T extends AppDomNode>(node: AppDomNode, type: T['type']):
invariant(isType(node, type), `Expected node type "${type}" but got "${node.type}"`);
}

function createId(): NodeId {
return cuid.slug() as NodeId;
export function createId(): NodeId {
return nanoid(7) as NodeId;
}

export function createConst<V>(value: V): ConstantAttrValue<V> {
Expand Down
4 changes: 2 additions & 2 deletions packages/toolpad-app/src/components/MonacoEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as React from 'react';
import * as monaco from 'monaco-editor';
import { styled, SxProps } from '@mui/material';
import clsx from 'clsx';
import cuid from 'cuid';
import { nanoid } from 'nanoid/non-secure';
import invariant from 'invariant';
import {
conf as jsonBasicConf,
Expand Down Expand Up @@ -370,7 +370,7 @@ export default React.forwardRef<MonacoEditorHandle, MonacoEditorProps>(function
}
}
} else {
const pathUri = monaco.Uri.parse(`./scripts/${cuid()}${getExtension(language)}`);
const pathUri = monaco.Uri.parse(`./scripts/${nanoid(7)}${getExtension(language)}`);
const model = monaco.editor.createModel(value || '', language, pathUri);

instance = monaco.editor.create(rootRef.current, {
Expand Down
3 changes: 1 addition & 2 deletions packages/toolpad-app/src/server/localMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { fromZodError } from 'zod-validation-error';
import { glob } from 'glob';
import * as chokidar from 'chokidar';
import { debounce } from 'lodash-es';
import cuid from 'cuid';
import config from '../config';
import * as appDom from '../appDom';
import { errorFrom } from '../utils/errors';
Expand Down Expand Up @@ -1077,7 +1076,7 @@ async function initToolpadFolder(root: string) {
apiVersion: 'v1',
kind: 'page',
spec: {
id: cuid.slug(),
id: appDom.createId(),
title: 'Default page',
},
};
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4754,11 +4754,6 @@ csstype@^3.0.2, csstype@^3.1.2:
resolved "https://registry.yarnpkg.com/csstype/-/csstype-3.1.2.tgz#1d4bf9d572f11c14031f0436e1c10bc1f571f50b"
integrity sha512-I7K1Uu0MBPzaFKg4nI5Q7Vs2t+3gWWW648spaF+Rg7pI9ds18Ugn+lvg4SHczUdKlHI5LWBXyqfS8+DufyBsgQ==

cuid@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/cuid/-/cuid-3.0.0.tgz#8cef32136e3c48e4a94aec42025996b888cbae82"
integrity sha512-WZYYkHdIDnaxdeP8Misq3Lah5vFjJwGuItJuV+tvMafosMzw0nF297T7mrm8IOWiPJkV6gc7sa8pzx27+w25Zg==

damerau-levenshtein@^1.0.8:
version "1.0.8"
resolved "https://registry.yarnpkg.com/damerau-levenshtein/-/damerau-levenshtein-1.0.8.tgz#b43d286ccbd36bc5b2f7ed41caf2d0aba1f8a6e7"
Expand Down Expand Up @@ -9206,6 +9201,11 @@ nanoid@^3.3.4:
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.4.tgz#730b67e3cd09e2deacf03c027c81c9d9dbc5e8ab"
integrity sha512-MqBkQh/OHTS2egovRtLk45wEyNXwF+cokD+1YPf9u5VfJiRdAiRwB2froX5Co9Rh20xs4siNPm8naNotSD6RBw==

nanoid@^4.0.2:
version "4.0.2"
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-4.0.2.tgz#140b3c5003959adbebf521c170f282c5e7f9fb9e"
integrity sha512-7ZtY5KTCNheRGfEFxnedV5zFiORN1+Y1N6zvPTnHQd8ENUvfaDBeuJDZb2bN/oXwXxu3qkTXDzy57W5vAmDTBw==

natural-compare-lite@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/natural-compare-lite/-/natural-compare-lite-1.4.0.tgz#17b09581988979fddafe0201e931ba933c96cbb4"
Expand Down