diff --git a/bun.config.ts b/bun.config.ts index e14caea..2a685e7 100644 --- a/bun.config.ts +++ b/bun.config.ts @@ -22,4 +22,12 @@ for (const store of storeList) { target: 'browser', dts: true, }) -} \ No newline at end of file +} + +await buildWithBun({ + naming: 'utils-node', + entry: 'query/utils/index.ts', + meta: import.meta, + target: 'node', + dts: true, +}) \ No newline at end of file diff --git a/package.json b/package.json index 7620528..1512cc0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kevisual/api", - "version": "0.0.50", + "version": "0.0.51", "description": "", "main": "mod.ts", "scripts": { @@ -39,6 +39,7 @@ "@kevisual/context": "^0.0.6", "@kevisual/js-filter": "^0.0.5", "@kevisual/load": "^0.0.6", + "@paralleldrive/cuid2": "^3.3.0", "es-toolkit": "^1.44.0", "eventemitter3": "^5.0.4", "fuse.js": "^7.1.0", @@ -56,6 +57,7 @@ "./proxy": "./query/query-proxy/index.ts", "./secret": "./query/query-secret/index.ts", "./resources": "./query/query-resources/index.ts", + "./utils-node": "./dist/utils-node.js", "./utils": "./dist/utils.js", "./query-secret": "./dist/query-secret.js", "./query-mark": "./dist/query-mark.js", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 86d3694..53b7784 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -17,6 +17,9 @@ importers: '@kevisual/load': specifier: ^0.0.6 version: 0.0.6 + '@paralleldrive/cuid2': + specifier: ^3.3.0 + version: 3.3.0 es-toolkit: specifier: ^1.44.0 version: 1.44.0 @@ -150,6 +153,10 @@ packages: resolution: {integrity: sha512-jLsL80wBBKkrJZrfk3SQpJ9JA/zREdlUROj7eCkmzqduAWKSI0wVcXuCKf+mLFCHB0Q0Tkh2rgzjSlurt3JQgw==} engines: {node: '>=10.0.0'} + '@noble/hashes@2.0.1': + resolution: {integrity: sha512-XlOlEbQcE9fmuXxrVTXCTlG2nlRXa9Rj3rr5Ue/+tX+nmkgbX720YHh0VR3hBF9xDvwnb8D2shVGOwNx+ulArw==} + engines: {node: '>= 20.19.0'} + '@nodelib/fs.scandir@2.1.5': resolution: {integrity: sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==} engines: {node: '>= 8'} @@ -162,6 +169,10 @@ packages: resolution: {integrity: sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==} engines: {node: '>= 8'} + '@paralleldrive/cuid2@3.3.0': + resolution: {integrity: sha512-OqiFvSOF0dBSesELYY2CAMa4YINvlLpvKOz/rv6NeZEqiyttlHgv98Juwv4Ch+GrEV7IZ8jfI2VcEoYUjXXCjw==} + hasBin: true + '@types/bun@1.3.9': resolution: {integrity: sha512-KQ571yULOdWJiMH+RIWIOZ7B2RXQGpL1YQrBtLIV3FqDcCu6FsbFUBwhdKUlCKUpS3PJDsHlJ1QKlpxoVR+xtw==} @@ -194,6 +205,9 @@ packages: asynckit@0.4.0: resolution: {integrity: sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==} + bignumber.js@9.3.1: + resolution: {integrity: sha512-Ko0uX15oIUS7wJ3Rb30Fs6SkVbLmPBAKdlm7q9+ak9bbIeFf0MwuBsQV6z7+X768/cHsfg+WlysDWJcmthjsjQ==} + braces@3.0.3: resolution: {integrity: sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==} engines: {node: '>=8'} @@ -221,6 +235,9 @@ packages: resolution: {integrity: sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==} engines: {node: '>= 0.4'} + error-causes@3.0.2: + resolution: {integrity: sha512-i0B8zq1dHL6mM85FGoxaJnVtx6LD5nL2v0hlpGdntg5FOSyzQ46c9lmz5qx0xRS2+PWHGOHcYxGIBC5Le2dRMw==} + es-define-property@1.0.1: resolution: {integrity: sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==} engines: {node: '>= 0.4'} @@ -529,6 +546,8 @@ snapshots: '@kevisual/ws@8.19.0': {} + '@noble/hashes@2.0.1': {} + '@nodelib/fs.scandir@2.1.5': dependencies: '@nodelib/fs.stat': 2.0.5 @@ -541,6 +560,12 @@ snapshots: '@nodelib/fs.scandir': 2.1.5 fastq: 1.19.1 + '@paralleldrive/cuid2@3.3.0': + dependencies: + '@noble/hashes': 2.0.1 + bignumber.js: 9.3.1 + error-causes: 3.0.2 + '@types/bun@1.3.9': dependencies: bun-types: 1.3.9 @@ -578,6 +603,8 @@ snapshots: asynckit@0.4.0: {} + bignumber.js@9.3.1: {} + braces@3.0.3: dependencies: fill-range: 7.1.1 @@ -605,6 +632,8 @@ snapshots: es-errors: 1.3.0 gopd: 1.2.0 + error-causes@3.0.2: {} + es-define-property@1.0.1: {} es-errors@1.3.0: {} diff --git a/query/utils/random.ts b/query/utils/random.ts index 1fe8925..ef3f607 100644 --- a/query/utils/random.ts +++ b/query/utils/random.ts @@ -1,9 +1,12 @@ import { customAlphabet } from 'nanoid'; +import { createId } from '@paralleldrive/cuid2'; export const letter = 'abcdefghijklmnopqrstuvwxyz'; export const number = '0123456789'; const alphanumeric = `${letter}${number}`; export const alphanumericWithDash = `${alphanumeric}-`; + +export const cuid2 = createId; /** * 创建一个随机的字母字符串 */ @@ -12,12 +15,12 @@ export const uuid = customAlphabet(letter); /** * 创建一个随机的 id,包含字母和数字 */ -export const nanoid = customAlphabet(alphanumeric, 10); +export const nanoid = customAlphabet(alphanumeric, 16); /** * 创建一个随机的 id,包含字母、数字和短横线 */ -export const nanoidWithDash = customAlphabet(alphanumericWithDash, 10); +export const nanoidWithDash = customAlphabet(alphanumericWithDash, 16); /** * 创建一个随机的 id,以字母开头的字符串