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 +1 -1
- package/dist/concerns/id.js +0 -24
- package/dist/core/resource-id-generator.class.js +1 -1
- package/dist/core/resource-persistence.class.js +3 -1
- package/dist/lite.js +1 -1
- package/dist/s3db-lite.cjs +267 -286
- package/dist/s3db-lite.d.ts +1 -2
- package/dist/s3db-lite.es.js +268 -286
- package/dist/s3db.cjs +342 -368
- package/dist/s3db.d.ts +1 -3
- package/dist/s3db.es.js +343 -367
- package/dist/tasks/tasks-pool.class.js +3 -3
- package/dist/tasks/tasks-runner.class.js +2 -2
- package/dist/types/concerns/id.d.ts +0 -2
- package/dist/types/core/resource-persistence.class.d.ts +2 -0
- package/dist/types/lite.d.ts +1 -1
- package/package.json +1 -2
- package/src/concerns/id.ts +0 -42
- package/src/core/resource-id-generator.class.ts +1 -1
- package/src/core/resource-persistence.class.ts +5 -1
- package/src/lite.ts +1 -1
- package/src/plugins/tfstate/README.md +3 -3
- package/src/tasks/tasks-pool.class.ts +3 -3
- package/src/tasks/tasks-runner.class.ts +2 -2
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { EventEmitter } from 'events';
|
|
2
2
|
import { cpus } from 'os';
|
|
3
3
|
import { setTimeout as delay } from 'timers/promises';
|
|
4
|
-
import { nanoid } from 'nanoid';
|
|
5
4
|
import { AdaptiveTuning } from '../concerns/adaptive-tuning.js';
|
|
5
|
+
import { idGenerator } from '../concerns/id.js';
|
|
6
6
|
import { SignatureStats } from './concerns/signature-stats.js';
|
|
7
7
|
import { FifoTaskQueue } from './concerns/fifo-task-queue.js';
|
|
8
8
|
import { PriorityTaskQueue } from './concerns/priority-task-queue.js';
|
|
@@ -361,7 +361,7 @@ export class TasksPool extends EventEmitter {
|
|
|
361
361
|
...(options.metadata || {})
|
|
362
362
|
};
|
|
363
363
|
const task = {
|
|
364
|
-
id:
|
|
364
|
+
id: idGenerator(),
|
|
365
365
|
fn: fn,
|
|
366
366
|
priority: options.priority || 0,
|
|
367
367
|
retries: options.retries ?? this.retries,
|
|
@@ -417,7 +417,7 @@ export class TasksPool extends EventEmitter {
|
|
|
417
417
|
async addBatch(fns, options = {}) {
|
|
418
418
|
const results = [];
|
|
419
419
|
const errors = [];
|
|
420
|
-
const batchId =
|
|
420
|
+
const batchId = idGenerator();
|
|
421
421
|
const promises = fns.map((fn, index) => {
|
|
422
422
|
const taskOptions = {
|
|
423
423
|
priority: options.priority,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EventEmitter } from 'events';
|
|
2
|
-
import { nanoid } from 'nanoid';
|
|
3
2
|
import { AdaptiveTuning } from '../concerns/adaptive-tuning.js';
|
|
3
|
+
import { idGenerator } from '../concerns/id.js';
|
|
4
4
|
import { FifoTaskQueue } from './concerns/fifo-task-queue.js';
|
|
5
5
|
import { PriorityTaskQueue } from './concerns/priority-task-queue.js';
|
|
6
6
|
import { extractLengthHint, deriveSignature } from './concerns/task-signature.js';
|
|
@@ -143,7 +143,7 @@ export class TasksRunner extends EventEmitter {
|
|
|
143
143
|
...(options.metadata || {})
|
|
144
144
|
};
|
|
145
145
|
const task = {
|
|
146
|
-
id:
|
|
146
|
+
id: idGenerator(),
|
|
147
147
|
fn,
|
|
148
148
|
priority: options.priority || 0,
|
|
149
149
|
retries: options.retries ?? this.retries,
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
export declare function initializeNanoid(): Promise<void>;
|
|
2
|
-
export declare function getNanoidInitializationError(): Error | null;
|
|
3
1
|
export declare const idGenerator: (size?: number) => string;
|
|
4
2
|
export declare const passwordGenerator: (size?: number) => string;
|
|
5
3
|
export declare const getUrlAlphabet: () => string;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { StringRecord } from '../types/common.types.js';
|
|
2
|
+
import type { IdGeneratorConfig } from './resource-id-generator.class.js';
|
|
2
3
|
export interface ResourceData extends StringRecord {
|
|
3
4
|
id?: string;
|
|
4
5
|
_contentLength?: number;
|
|
@@ -127,6 +128,7 @@ export interface Resource {
|
|
|
127
128
|
hooks: HooksCollection;
|
|
128
129
|
logger: Logger;
|
|
129
130
|
idGenerator: (data?: unknown) => string | Promise<string>;
|
|
131
|
+
idGeneratorType?: IdGeneratorConfig;
|
|
130
132
|
versioningEnabled: boolean;
|
|
131
133
|
observers: Observer[];
|
|
132
134
|
executeHooks(hookName: string, data: unknown): Promise<unknown>;
|
package/dist/types/lite.d.ts
CHANGED
|
@@ -40,7 +40,7 @@ export * from './errors.js';
|
|
|
40
40
|
export { createLogger, type LogLevel } from './concerns/logger.js';
|
|
41
41
|
export { tryFn, tryFnSync, type TryResult } from './concerns/try-fn.js';
|
|
42
42
|
export { encrypt, decrypt } from './concerns/crypto.js';
|
|
43
|
-
export { idGenerator, passwordGenerator, createCustomGenerator
|
|
43
|
+
export { idGenerator, passwordGenerator, createCustomGenerator } from './concerns/id.js';
|
|
44
44
|
export { encode, decode, encodeDecimal, decodeDecimal } from './concerns/base62.js';
|
|
45
45
|
export { encodeBuffer, decodeBuffer, encodeBits, decodeBits } from './concerns/binary.js';
|
|
46
46
|
export { ProcessManager, getProcessManager, resetProcessManager } from './concerns/process-manager.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "s3db.js",
|
|
3
|
-
"version": "19.3.
|
|
3
|
+
"version": "19.3.23",
|
|
4
4
|
"description": "Use AWS S3, the world's most reliable document storage, as a database with this ORM.",
|
|
5
5
|
"main": "dist/s3db.cjs",
|
|
6
6
|
"module": "dist/s3db.es.js",
|
|
@@ -92,7 +92,6 @@
|
|
|
92
92
|
"fastest-validator": "^1.19.1",
|
|
93
93
|
"json-stable-stringify": "^1.3.0",
|
|
94
94
|
"lodash-es": "^4.17.22",
|
|
95
|
-
"nanoid": "5.1.6",
|
|
96
95
|
"pino": "^10.2.0",
|
|
97
96
|
"pino-pretty": "^13.1.3",
|
|
98
97
|
"recker": "1.0.68"
|
package/src/concerns/id.ts
CHANGED
|
@@ -1,14 +1,4 @@
|
|
|
1
1
|
import { randomFillSync } from 'node:crypto';
|
|
2
|
-
import { createLogger } from './logger.js';
|
|
3
|
-
|
|
4
|
-
interface Logger {
|
|
5
|
-
warn(obj: Record<string, unknown>, msg: string): void;
|
|
6
|
-
info(obj: Record<string, unknown>, msg: string): void;
|
|
7
|
-
error(obj: Record<string, unknown>, msg: string): void;
|
|
8
|
-
debug(obj: Record<string, unknown>, msg: string): void;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const logger = createLogger({ name: 'IdGenerator', level: 'info' }) as Logger;
|
|
12
2
|
|
|
13
3
|
const FALLBACK_URL_ALPHABET =
|
|
14
4
|
'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict';
|
|
@@ -71,38 +61,6 @@ let activeCustomAlphabet: CustomAlphabetFunction = customAlphabetFallback;
|
|
|
71
61
|
let activeUrlAlphabet: string = FALLBACK_URL_ALPHABET;
|
|
72
62
|
let idGeneratorImpl: (size?: number) => string = activeCustomAlphabet(activeUrlAlphabet, 22);
|
|
73
63
|
let passwordGeneratorImpl: (size?: number) => string = activeCustomAlphabet(PASSWORD_ALPHABET, 16);
|
|
74
|
-
let nanoidInitializationError: Error | null = null;
|
|
75
|
-
|
|
76
|
-
interface NanoidModule {
|
|
77
|
-
customAlphabet?: CustomAlphabetFunction;
|
|
78
|
-
urlAlphabet?: string;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const nanoidReadyPromise: Promise<void> = import('nanoid')
|
|
82
|
-
.then((mod: NanoidModule) => {
|
|
83
|
-
const resolvedCustomAlphabet = mod?.customAlphabet ?? activeCustomAlphabet;
|
|
84
|
-
const resolvedUrlAlphabet = mod?.urlAlphabet ?? activeUrlAlphabet;
|
|
85
|
-
|
|
86
|
-
activeCustomAlphabet = resolvedCustomAlphabet;
|
|
87
|
-
activeUrlAlphabet = resolvedUrlAlphabet;
|
|
88
|
-
idGeneratorImpl = activeCustomAlphabet(activeUrlAlphabet, 22);
|
|
89
|
-
passwordGeneratorImpl = activeCustomAlphabet(PASSWORD_ALPHABET, 16);
|
|
90
|
-
})
|
|
91
|
-
.catch((error: Error) => {
|
|
92
|
-
nanoidInitializationError = error;
|
|
93
|
-
if (typeof process !== 'undefined' && process?.env?.S3DB_DEBUG) {
|
|
94
|
-
logger.warn({ error: error.message }, 'Failed to dynamically import "nanoid". Using fallback implementation.');
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
export function initializeNanoid(): Promise<void> {
|
|
99
|
-
return nanoidReadyPromise;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export function getNanoidInitializationError(): Error | null {
|
|
103
|
-
return nanoidInitializationError;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
64
|
export const idGenerator = (size?: number): string => idGeneratorImpl(size);
|
|
107
65
|
|
|
108
66
|
export const passwordGenerator = (size?: number): string => passwordGeneratorImpl(size);
|
|
@@ -7,6 +7,7 @@ import { calculateTotalSize, calculateEffectiveLimit } from '../concerns/calcula
|
|
|
7
7
|
import { mapAwsError, InvalidResourceItem, ResourceError, ValidationError } from '../errors.js';
|
|
8
8
|
import { streamToString } from '../stream/index.js';
|
|
9
9
|
import type { StringRecord, JSONValue } from '../types/common.types.js';
|
|
10
|
+
import type { IdGeneratorConfig } from './resource-id-generator.class.js';
|
|
10
11
|
|
|
11
12
|
export interface ResourceData extends StringRecord {
|
|
12
13
|
id?: string;
|
|
@@ -147,6 +148,7 @@ export interface Resource {
|
|
|
147
148
|
hooks: HooksCollection;
|
|
148
149
|
logger: Logger;
|
|
149
150
|
idGenerator: (data?: unknown) => string | Promise<string>;
|
|
151
|
+
idGeneratorType?: IdGeneratorConfig;
|
|
150
152
|
versioningEnabled: boolean;
|
|
151
153
|
observers: Observer[];
|
|
152
154
|
|
|
@@ -273,7 +275,9 @@ export class ResourcePersistence {
|
|
|
273
275
|
|
|
274
276
|
let finalId = validatedId || preProcessedData.id || id;
|
|
275
277
|
if (!finalId) {
|
|
276
|
-
|
|
278
|
+
const shouldUseData = this.resource.idGeneratorType === 'custom';
|
|
279
|
+
const generatedId = shouldUseData ? this.idGenerator(preProcessedData) : this.idGenerator();
|
|
280
|
+
finalId = await Promise.resolve(generatedId);
|
|
277
281
|
if (!finalId || String(finalId).trim() === '') {
|
|
278
282
|
const { idGenerator } = await import('#src/concerns/id.js');
|
|
279
283
|
finalId = idGenerator();
|
package/src/lite.ts
CHANGED
|
@@ -67,7 +67,7 @@ export { tryFn, tryFnSync, type TryResult } from './concerns/try-fn.js';
|
|
|
67
67
|
export { encrypt, decrypt } from './concerns/crypto.js';
|
|
68
68
|
|
|
69
69
|
// ID generation
|
|
70
|
-
export { idGenerator, passwordGenerator, createCustomGenerator
|
|
70
|
+
export { idGenerator, passwordGenerator, createCustomGenerator } from './concerns/id.js';
|
|
71
71
|
|
|
72
72
|
// Base62 encoding
|
|
73
73
|
export { encode, decode, encodeDecimal, decodeDecimal } from './concerns/base62.js';
|
|
@@ -28,7 +28,7 @@ Stores metadata about each imported `.tfstate`.
|
|
|
28
28
|
**Complete Schema:**
|
|
29
29
|
```javascript
|
|
30
30
|
{
|
|
31
|
-
id: 'string|required', // generated
|
|
31
|
+
id: 'string|required', // generated ID
|
|
32
32
|
sourceFile: 'string|required', // 'prod/terraform.tfstate'
|
|
33
33
|
serial: 'number|required', // State serial
|
|
34
34
|
lineage: 'string', // Terraform lineage
|
|
@@ -74,7 +74,7 @@ The main resource containing all infrastructure resources extracted from states.
|
|
|
74
74
|
**Complete Schema:**
|
|
75
75
|
```javascript
|
|
76
76
|
{
|
|
77
|
-
id: 'string|required', // generated
|
|
77
|
+
id: 'string|required', // generated ID
|
|
78
78
|
stateFileId: 'string|required', // FK to states resource
|
|
79
79
|
|
|
80
80
|
// Denormalized for queries
|
|
@@ -179,7 +179,7 @@ Tracks changes between state versions.
|
|
|
179
179
|
**Complete Schema:**
|
|
180
180
|
```javascript
|
|
181
181
|
{
|
|
182
|
-
id: 'string|required', // generated
|
|
182
|
+
id: 'string|required', // generated ID
|
|
183
183
|
sourceFile: 'string|required', // Which state
|
|
184
184
|
oldSerial: 'number|required', // Old version
|
|
185
185
|
newSerial: 'number|required', // New version
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { EventEmitter } from 'events';
|
|
2
2
|
import { cpus } from 'os';
|
|
3
3
|
import { setTimeout as delay } from 'timers/promises';
|
|
4
|
-
import { nanoid } from 'nanoid';
|
|
5
4
|
import type { TaskExecutor } from '../concurrency/task-executor.interface.js';
|
|
6
5
|
import { AdaptiveTuning } from '../concerns/adaptive-tuning.js';
|
|
6
|
+
import { idGenerator } from '../concerns/id.js';
|
|
7
7
|
import { SignatureStats } from './concerns/signature-stats.js';
|
|
8
8
|
import { FifoTaskQueue } from './concerns/fifo-task-queue.js';
|
|
9
9
|
import { PriorityTaskQueue } from './concerns/priority-task-queue.js';
|
|
@@ -625,7 +625,7 @@ export class TasksPool extends EventEmitter implements TaskExecutor {
|
|
|
625
625
|
};
|
|
626
626
|
|
|
627
627
|
const task: PoolTask<T> = {
|
|
628
|
-
id:
|
|
628
|
+
id: idGenerator(),
|
|
629
629
|
fn: fn as TaskFunction<T>,
|
|
630
630
|
priority: options.priority || 0,
|
|
631
631
|
retries: options.retries ?? this.retries,
|
|
@@ -687,7 +687,7 @@ export class TasksPool extends EventEmitter implements TaskExecutor {
|
|
|
687
687
|
async addBatch<T = unknown>(fns: Array<TaskFunction<T>>, options: BatchOptions = {}): Promise<BatchResult<T>> {
|
|
688
688
|
const results: (T | null)[] = [];
|
|
689
689
|
const errors: Array<{ error: Error; index: number }> = [];
|
|
690
|
-
const batchId =
|
|
690
|
+
const batchId = idGenerator();
|
|
691
691
|
|
|
692
692
|
const promises = fns.map((fn, index) => {
|
|
693
693
|
const taskOptions: EnqueueOptions = {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EventEmitter } from 'events';
|
|
2
|
-
import { nanoid } from 'nanoid';
|
|
3
2
|
import type { TaskExecutor } from '../concurrency/task-executor.interface.js';
|
|
4
3
|
import { AdaptiveTuning, type AdaptiveTuningOptions } from '../concerns/adaptive-tuning.js';
|
|
4
|
+
import { idGenerator } from '../concerns/id.js';
|
|
5
5
|
import { FifoTaskQueue } from './concerns/fifo-task-queue.js';
|
|
6
6
|
import { PriorityTaskQueue } from './concerns/priority-task-queue.js';
|
|
7
7
|
import { extractLengthHint, deriveSignature } from './concerns/task-signature.js';
|
|
@@ -343,7 +343,7 @@ export class TasksRunner extends EventEmitter implements TaskExecutor {
|
|
|
343
343
|
...(options.metadata || {})
|
|
344
344
|
};
|
|
345
345
|
const task: RunnerTask<T> = {
|
|
346
|
-
id:
|
|
346
|
+
id: idGenerator(),
|
|
347
347
|
fn,
|
|
348
348
|
priority: options.priority || 0,
|
|
349
349
|
retries: options.retries ?? this.retries,
|