s3db.js 19.3.21 → 19.3.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2425,7 +2425,7 @@ This project is licensed under the [Unlicense](LICENSE) - see the LICENSE file f
2425
2425
 
2426
2426
  - Built with [AWS SDK for JavaScript](https://aws.amazon.com/sdk-for-javascript/)
2427
2427
  - Validation powered by [@icebob/fastest-validator](https://github.com/icebob/fastest-validator)
2428
- - ID generation using [nanoid](https://github.com/ai/nanoid)
2428
+ - ID generation using the built-in generator
2429
2429
 
2430
2430
  ---
2431
2431
 
@@ -1,6 +1,4 @@
1
1
  import { randomFillSync } from 'node:crypto';
2
- import { createLogger } from './logger.js';
3
- const logger = createLogger({ name: 'IdGenerator', level: 'info' });
4
2
  const FALLBACK_URL_ALPHABET = 'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict';
5
3
  const PASSWORD_ALPHABET = 'ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz23456789';
6
4
  const POOL_SIZE_MULTIPLIER = 128;
@@ -48,28 +46,6 @@ let activeCustomAlphabet = customAlphabetFallback;
48
46
  let activeUrlAlphabet = FALLBACK_URL_ALPHABET;
49
47
  let idGeneratorImpl = activeCustomAlphabet(activeUrlAlphabet, 22);
50
48
  let passwordGeneratorImpl = activeCustomAlphabet(PASSWORD_ALPHABET, 16);
51
- let nanoidInitializationError = null;
52
- const nanoidReadyPromise = import('nanoid')
53
- .then((mod) => {
54
- const resolvedCustomAlphabet = mod?.customAlphabet ?? activeCustomAlphabet;
55
- const resolvedUrlAlphabet = mod?.urlAlphabet ?? activeUrlAlphabet;
56
- activeCustomAlphabet = resolvedCustomAlphabet;
57
- activeUrlAlphabet = resolvedUrlAlphabet;
58
- idGeneratorImpl = activeCustomAlphabet(activeUrlAlphabet, 22);
59
- passwordGeneratorImpl = activeCustomAlphabet(PASSWORD_ALPHABET, 16);
60
- })
61
- .catch((error) => {
62
- nanoidInitializationError = error;
63
- if (typeof process !== 'undefined' && process?.env?.S3DB_DEBUG) {
64
- logger.warn({ error: error.message }, 'Failed to dynamically import "nanoid". Using fallback implementation.');
65
- }
66
- });
67
- export function initializeNanoid() {
68
- return nanoidReadyPromise;
69
- }
70
- export function getNanoidInitializationError() {
71
- return nanoidInitializationError;
72
- }
73
49
  export const idGenerator = (size) => idGeneratorImpl(size);
74
50
  export const passwordGenerator = (size) => passwordGeneratorImpl(size);
75
51
  export const getUrlAlphabet = () => activeUrlAlphabet;
@@ -76,7 +76,7 @@ export class ResourceIdGenerator {
76
76
  if (this._incrementalConfig) {
77
77
  return 'incremental';
78
78
  }
79
- return 'nanoid';
79
+ return 'default';
80
80
  }
81
81
  async getSequenceValue(fieldName = 'id') {
82
82
  if (!this._generator?._sequence) {
@@ -54,7 +54,9 @@ export class ResourcePersistence {
54
54
  Object.assign(validatedAttributes, extraData);
55
55
  let finalId = validatedId || preProcessedData.id || id;
56
56
  if (!finalId) {
57
- finalId = await Promise.resolve(this.idGenerator(preProcessedData));
57
+ const shouldUseData = this.resource.idGeneratorType === 'custom';
58
+ const generatedId = shouldUseData ? this.idGenerator(preProcessedData) : this.idGenerator();
59
+ finalId = await Promise.resolve(generatedId);
58
60
  if (!finalId || String(finalId).trim() === '') {
59
61
  const { idGenerator } = await import('#src/concerns/id.js');
60
62
  finalId = idGenerator();
package/dist/lite.js CHANGED
@@ -56,7 +56,7 @@ export { tryFn, tryFnSync } from './concerns/try-fn.js';
56
56
  // Crypto
57
57
  export { encrypt, decrypt } from './concerns/crypto.js';
58
58
  // ID generation
59
- export { idGenerator, passwordGenerator, createCustomGenerator, initializeNanoid } from './concerns/id.js';
59
+ export { idGenerator, passwordGenerator, createCustomGenerator } from './concerns/id.js';
60
60
  // Base62 encoding
61
61
  export { encode, decode, encodeDecimal, decodeDecimal } from './concerns/base62.js';
62
62
  // Binary encoding