@tstdl/base 0.93.76 → 0.93.78

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.
Files changed (103) hide show
  1. package/ai/prompts/instructions-formatter.d.ts +68 -5
  2. package/ai/prompts/instructions-formatter.js +11 -3
  3. package/authentication/client/http-client.middleware.js +2 -2
  4. package/authentication/models/authentication-credentials.model.d.ts +2 -2
  5. package/authentication/models/authentication-credentials.model.js +5 -3
  6. package/authentication/models/authentication-session.model.d.ts +2 -2
  7. package/authentication/models/authentication-session.model.js +5 -3
  8. package/authentication/models/index.d.ts +4 -0
  9. package/authentication/models/index.js +4 -0
  10. package/authentication/models/service-account.model.d.ts +7 -0
  11. package/authentication/models/service-account.model.js +31 -0
  12. package/authentication/models/subject.model.d.ts +16 -0
  13. package/authentication/models/subject.model.js +59 -0
  14. package/authentication/models/system-account.model.d.ts +5 -0
  15. package/authentication/models/system-account.model.js +25 -0
  16. package/authentication/models/user.model.d.ts +15 -0
  17. package/authentication/models/user.model.js +47 -0
  18. package/authentication/server/drizzle/0001_condemned_pretty_boy.sql +70 -0
  19. package/authentication/server/drizzle/meta/0001_snapshot.json +651 -0
  20. package/authentication/server/drizzle/meta/_journal.json +7 -0
  21. package/authentication/server/index.d.ts +1 -0
  22. package/authentication/server/index.js +1 -0
  23. package/authentication/server/schemas.d.ts +16 -1
  24. package/authentication/server/schemas.js +7 -1
  25. package/authentication/server/subject.service.d.ts +6 -0
  26. package/authentication/server/subject.service.js +44 -0
  27. package/circuit-breaker/circuit-breaker.d.ts +32 -0
  28. package/circuit-breaker/circuit-breaker.js +9 -0
  29. package/circuit-breaker/index.d.ts +2 -0
  30. package/circuit-breaker/index.js +2 -0
  31. package/circuit-breaker/postgres/circuit-breaker.d.ts +7 -0
  32. package/circuit-breaker/postgres/circuit-breaker.js +78 -0
  33. package/circuit-breaker/postgres/drizzle/0000_hard_shocker.sql +9 -0
  34. package/circuit-breaker/postgres/drizzle/meta/0000_snapshot.json +82 -0
  35. package/circuit-breaker/postgres/drizzle/meta/_journal.json +13 -0
  36. package/circuit-breaker/postgres/drizzle.config.d.ts +2 -0
  37. package/circuit-breaker/postgres/drizzle.config.js +11 -0
  38. package/circuit-breaker/postgres/index.d.ts +5 -0
  39. package/circuit-breaker/postgres/index.js +5 -0
  40. package/circuit-breaker/postgres/model.d.ts +9 -0
  41. package/circuit-breaker/postgres/model.js +40 -0
  42. package/circuit-breaker/postgres/module.d.ts +6 -0
  43. package/circuit-breaker/postgres/module.js +25 -0
  44. package/circuit-breaker/postgres/provider.d.ts +6 -0
  45. package/circuit-breaker/postgres/provider.js +21 -0
  46. package/circuit-breaker/postgres/schemas.d.ts +8 -0
  47. package/circuit-breaker/postgres/schemas.js +6 -0
  48. package/circuit-breaker/provider.d.ts +4 -0
  49. package/circuit-breaker/provider.js +2 -0
  50. package/circuit-breaker/tests/circuit-breaker.test.js +113 -0
  51. package/document-management/models/document.model.d.ts +0 -1
  52. package/document-management/models/document.model.js +0 -5
  53. package/document-management/server/api/document-management.api.js +1 -2
  54. package/document-management/server/drizzle/0002_round_warbird.sql +1 -0
  55. package/document-management/server/drizzle/meta/0002_snapshot.json +2722 -0
  56. package/document-management/server/drizzle/meta/_journal.json +7 -0
  57. package/document-management/server/services/document-collection.service.js +3 -3
  58. package/document-management/server/services/document-management-ancillary.service.d.ts +1 -1
  59. package/document-management/server/services/document-management.service.js +1 -1
  60. package/document-management/server/services/document-workflow.service.js +5 -5
  61. package/document-management/server/services/document.service.d.ts +0 -2
  62. package/document-management/server/services/document.service.js +1 -2
  63. package/document-management/service-models/enriched/enriched-document.view.d.ts +1 -1
  64. package/examples/document-management/main.d.ts +1 -1
  65. package/examples/document-management/main.js +1 -1
  66. package/logger/transports/console.d.ts +1 -1
  67. package/logger/transports/console.js +4 -1
  68. package/message-bus/message-bus-base.js +1 -1
  69. package/package.json +8 -5
  70. package/queue/enqueue-batch.d.ts +11 -11
  71. package/queue/enqueue-batch.js +2 -3
  72. package/queue/index.d.ts +1 -0
  73. package/queue/index.js +1 -0
  74. package/queue/postgres/drizzle/0003_tricky_venom.sql +30 -0
  75. package/queue/postgres/drizzle/meta/0003_snapshot.json +288 -0
  76. package/queue/postgres/drizzle/meta/_journal.json +7 -0
  77. package/queue/postgres/drizzle.config.js +2 -2
  78. package/queue/postgres/index.d.ts +1 -1
  79. package/queue/postgres/index.js +1 -1
  80. package/queue/postgres/module.d.ts +1 -1
  81. package/queue/postgres/module.js +1 -1
  82. package/queue/postgres/queue.d.ts +52 -23
  83. package/queue/postgres/queue.js +582 -64
  84. package/queue/postgres/queue.provider.d.ts +1 -1
  85. package/queue/postgres/schemas.d.ts +13 -2
  86. package/queue/postgres/schemas.js +4 -2
  87. package/queue/postgres/task.model.d.ts +24 -0
  88. package/queue/postgres/task.model.js +115 -0
  89. package/queue/provider.d.ts +1 -1
  90. package/queue/queue.d.ts +158 -37
  91. package/queue/queue.js +97 -19
  92. package/queue/task-context.d.ts +38 -0
  93. package/queue/task-context.js +102 -0
  94. package/queue/tests/queue.test.d.ts +1 -0
  95. package/queue/tests/queue.test.js +623 -0
  96. package/test4.d.ts +1 -1
  97. package/test4.js +1 -1
  98. package/utils/format-error.d.ts +17 -20
  99. package/utils/format-error.js +105 -47
  100. package/queue/postgres/job.model.d.ts +0 -12
  101. package/queue/postgres/job.model.js +0 -53
  102. package/test6.js +0 -33
  103. /package/{test6.d.ts → circuit-breaker/tests/circuit-breaker.test.d.ts} +0 -0
@@ -1,31 +1,28 @@
1
- import type { UndefinableJson } from '../types/index.js';
1
+ import type { Record, UndefinableJson } from '../types/index.js';
2
2
  export type FormatErrorOptions = {
3
- /**
4
- * Include error name in message
5
- */
3
+ /** Include error name in message */
6
4
  includeName?: boolean;
7
- /**
8
- * Include all error properties beside name and message
9
- */
5
+ /** Include all error properties beside name and message */
10
6
  includeRest?: boolean | 'if-no-extra-info';
11
- /**
12
- * Include extraInfo from errors implementing {@link ErrorExtraInfo}
13
- */
7
+ /** Include extraInfo from errors implementing {@link ErrorExtraInfo} */
14
8
  includeExtraInfo?: boolean;
15
- /**
16
- * Include stack trace
17
- */
9
+ /** Include stack trace */
18
10
  includeStack?: boolean;
19
- /**
20
- * Maximum recursion depth for nested causes and aggregate errors (default: 5)
21
- */
11
+ /** Maximum recursion depth for nested causes and aggregate errors (default: 5) */
22
12
  depth?: number;
23
13
  };
14
+ export type SerializedError = {
15
+ name?: string;
16
+ message: string;
17
+ rest?: Record;
18
+ extraInfo?: UndefinableJson;
19
+ stack?: string;
20
+ cause?: SerializedError;
21
+ aggregateErrors?: SerializedError[];
22
+ };
24
23
  export interface ErrorExtraInfo {
25
24
  /** Format extra data (without message and stack) as JSON */
26
25
  getExtraInfo(): UndefinableJson | undefined;
27
26
  }
28
- /**
29
- * Enhanced error formatting
30
- */
31
- export declare function formatError(error: any, options?: FormatErrorOptions): string;
27
+ export declare function serializeError(error: unknown, options?: FormatErrorOptions): SerializedError;
28
+ export declare function formatError(error: unknown, options?: FormatErrorOptions): string;
@@ -2,76 +2,134 @@ import { unwrapError } from '../errors/utils.js';
2
2
  import { decycle } from './object/decycle.js';
3
3
  import { objectKeys } from './object/object.js';
4
4
  import { tryChain } from './try-chain.js';
5
- import { isArray, isDefined, isFunction, isObject, isUndefined } from './type-guards.js';
6
- /**
7
- * Enhanced error formatting
8
- */
9
- export function formatError(error, options = {}) {
5
+ import { isArray, isDefined, isFunction, isObject, isString, isUndefined } from './type-guards.js';
6
+ export function serializeError(error, options = {}) {
10
7
  const { includeName = true, includeRest = 'if-no-extra-info', includeExtraInfo = true, includeStack = true, depth = 5, } = options;
11
8
  if (depth <= 0) {
12
- return '[Max recursion depth reached]';
9
+ return { message: '[Max recursion depth reached]' };
13
10
  }
14
11
  const actualError = unwrapError(error);
12
+ // 1. Initial Property Extraction
15
13
  let name;
16
14
  let message;
17
15
  let stack;
18
- let rest;
19
- let extraInfo;
20
16
  let cause;
21
17
  let aggregateErrors;
18
+ let extraInfo;
19
+ let rest;
20
+ // Track if we treat this as a raw object (affects default name logic)
21
+ let isRawObjectFallback = false;
22
22
  if (isObject(actualError)) {
23
- if (actualError instanceof Error) {
24
- ({ name, message, stack, cause, ...rest } = actualError);
25
- if (actualError instanceof AggregateError) {
26
- aggregateErrors = actualError.errors;
27
- }
23
+ const errObj = actualError;
24
+ // Extract standard properties
25
+ name = isString(errObj.name) ? errObj.name : undefined;
26
+ message = isString(errObj.message) ? errObj.message : undefined;
27
+ stack = isString(errObj.stack) ? errObj.stack : undefined;
28
+ cause = errObj.cause;
29
+ if (actualError instanceof AggregateError) {
30
+ aggregateErrors = actualError.errors;
28
31
  }
29
- else {
30
- // Handle plain objects that might have error-like properties
31
- ({ name, message, stack, cause, ...rest } = actualError);
32
- }
33
- // Check for extra info (duck-typing)
34
- if (includeExtraInfo && isFunction(actualError.getExtraInfo)) { // eslint-disable-line @typescript-eslint/unbound-method
32
+ // Extract Extra Info
33
+ if (includeExtraInfo && isFunction(actualError.getExtraInfo)) {
35
34
  extraInfo = actualError.getExtraInfo();
36
35
  }
36
+ // Isolate 'rest' properties via destructuring
37
+ const { name: _n, message: _m, stack: _s, cause: _c, errors: _agg, ...restObj } = errObj;
38
+ rest = restObj;
37
39
  }
38
- // If no message, serialize the whole object as a fallback
39
- if (isUndefined(message) || (String(message).trim().length == 0)) { // eslint-disable-line @typescript-eslint/no-unnecessary-type-conversion
40
- // Handle primitives directly
41
- if (!isObject(actualError)) {
42
- message = String(actualError);
40
+ else {
41
+ // Primitive types (string, number, etc.)
42
+ message = String(actualError);
43
+ }
44
+ // 2. Message Normalization & Fallback Logic
45
+ const hasEmptyMessage = isUndefined(message) || (String(message).trim().length == 0);
46
+ if (hasEmptyMessage) {
47
+ if (actualError instanceof Error) {
48
+ // Standard Error with empty message: keep name, keep rest, ensure message is string
49
+ message = '';
43
50
  }
44
- else {
51
+ else if (isObject(actualError)) {
52
+ // Plain Object (e.g. { code: 500 }): Serialize entire object into message
45
53
  message = tryChain([
46
- () => JSON.stringify(actualError, null, 2), // Try normal serialization first
47
- () => {
48
- // Fallback with decycle for objects with circular references
49
- const decycledError = decycle(actualError);
50
- return JSON.stringify(decycledError, null, 2);
51
- },
54
+ () => JSON.stringify(actualError, null, 2),
55
+ () => JSON.stringify(decycle(actualError), null, 2),
52
56
  // eslint-disable-next-line @typescript-eslint/no-base-to-string
53
- () => `[Unstringifiable object: ${String(actualError)}]`, // Safe fallback if JSON.stringify still fails
57
+ () => `[Unstringifiable object: ${String(actualError)}]`,
54
58
  ]);
59
+ // Clear rest to avoid duplication since the whole object is now the message
60
+ rest = undefined;
61
+ // Flag as fallback to prevent defaulting name to "Error"
62
+ isRawObjectFallback = true;
63
+ }
64
+ else {
65
+ // Fallback for weird primitive edge cases (should be covered by initial String() conversion)
66
+ message = String(actualError);
55
67
  }
56
68
  }
57
- // --- String Assembly ---
58
- const nameString = includeName ? `${name ?? 'Error'}: ` : '';
59
- let restString = '';
60
- const shouldIncludeRest = (includeRest == true) || (includeRest == 'if-no-extra-info' && isUndefined(extraInfo));
61
- if (shouldIncludeRest && isDefined(rest) && objectKeys(rest).length > 0) {
62
- restString = `\n${JSON.stringify(decycle(rest), null, 2)}`;
69
+ // 3. Finalize Optional Properties
70
+ const shouldIncludeRest = includeRest === true || (includeRest === 'if-no-extra-info' && isUndefined(extraInfo));
71
+ const hasRest = isDefined(rest) && objectKeys(rest).length > 0;
72
+ // Determine Final Name
73
+ // If fallback (raw object) and no name exists, return undefined. Otherwise default to 'Error'.
74
+ const defaultName = isRawObjectFallback ? undefined : 'Error';
75
+ const finalName = includeName ? (name ?? defaultName) : undefined;
76
+ const nextOptions = { ...options, depth: depth - 1 };
77
+ return {
78
+ name: finalName,
79
+ message: message ?? '',
80
+ extraInfo: isDefined(extraInfo) ? extraInfo : undefined,
81
+ rest: shouldIncludeRest && hasRest ? decycle(rest) : undefined,
82
+ stack: (includeStack && isDefined(stack)) ? stack : undefined,
83
+ cause: (includeStack && cause)
84
+ ? serializeError(cause, nextOptions)
85
+ : undefined,
86
+ aggregateErrors: (isArray(aggregateErrors))
87
+ ? aggregateErrors.map((err) => serializeError(err, nextOptions))
88
+ : undefined,
89
+ };
90
+ }
91
+ export function formatError(error, options = {}) {
92
+ const serialized = serializeError(error, options);
93
+ return formatSerializedError(serialized, options);
94
+ }
95
+ function formatSerializedError(serialized, options) {
96
+ const { name, message, rest, extraInfo, stack, cause, aggregateErrors, } = serialized;
97
+ const { includeName = true, includeStack = true, depth = 5 } = options;
98
+ // 1. Header (Name: Message)
99
+ const prefix = includeName && name ? `${name}: ` : '';
100
+ const header = `${prefix}${message}`;
101
+ // 2. Body (Rest / Extra Info)
102
+ let body = '';
103
+ if (rest) {
104
+ body += `\n${JSON.stringify(rest, null, 2)}`;
105
+ }
106
+ if (extraInfo) {
107
+ body += `\n${JSON.stringify(extraInfo, null, 2)}`;
108
+ }
109
+ // 3. Stack Trace
110
+ let stackString = '';
111
+ if (includeStack && stack) {
112
+ // Deduplicate header if stack already starts with it (standard Node.js behavior)
113
+ if (stack.startsWith(header)) {
114
+ stackString = stack.slice(header.length);
115
+ }
116
+ else {
117
+ stackString = `\n${stack}`;
118
+ }
63
119
  }
64
- const extraInfoString = isDefined(extraInfo) ? `\n${JSON.stringify(extraInfo, null, 2)}` : '';
65
- const stackString = (includeStack && isDefined(stack)) ? `\n${stack}` : '';
66
- const causeString = includeStack && cause
67
- ? formatNestedError('Caused by:', cause, { ...options, depth: depth - 1 })
120
+ // 4. Recursion (Causes and Aggregate Errors)
121
+ const nextOptions = { ...options, depth: depth - 1 };
122
+ const causeString = (includeStack && cause)
123
+ ? formatNestedError('Caused by:', cause, nextOptions)
68
124
  : '';
69
- const aggregateErrorsString = isArray(aggregateErrors)
70
- ? aggregateErrors.map((err, i) => formatNestedError(`Sub-error #${i + 1}:`, err, { ...options, depth: depth - 1 })).join('')
125
+ const aggregateErrorsString = aggregateErrors
126
+ ? aggregateErrors
127
+ .map((err, i) => formatNestedError(`Sub-error #${i + 1}:`, err, nextOptions))
128
+ .join('')
71
129
  : '';
72
- return `${nameString}${message}${restString}${extraInfoString}${stackString}${causeString}${aggregateErrorsString}`;
130
+ return `${header}${body}${stackString}${causeString}${aggregateErrorsString}`;
73
131
  }
74
- function formatNestedError(prefix, error, options) {
75
- const formatted = formatError(error, options).replace(/\n/g, '\n ');
132
+ function formatNestedError(prefix, serializedError, options) {
133
+ const formatted = formatSerializedError(serializedError, options).replace(/\n/g, '\n ');
76
134
  return `\n\n${prefix}\n ${formatted}`;
77
135
  }
@@ -1,12 +0,0 @@
1
- import { BaseEntity, type Json, type Timestamp } from '../../orm/index.js';
2
- import type { ObjectLiteral } from '../../types/index.js';
3
- import type { Job } from '../queue.js';
4
- export declare class PostgresJob<T extends ObjectLiteral = ObjectLiteral> extends BaseEntity implements Job<T> {
5
- queue: string;
6
- tag: string | null;
7
- priority: number;
8
- enqueueTimestamp: Timestamp;
9
- tries: number;
10
- lastDequeueTimestamp: Timestamp | null;
11
- data: Json<T>;
12
- }
@@ -1,53 +0,0 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- var __metadata = (this && this.__metadata) || function (k, v) {
8
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
- };
10
- import { BaseEntity, JsonProperty, Table, TimestampProperty, Unique } from '../../orm/index.js';
11
- import { Integer, StringProperty } from '../../schema/index.js';
12
- let PostgresJob = class PostgresJob extends BaseEntity {
13
- queue;
14
- tag;
15
- priority;
16
- enqueueTimestamp;
17
- tries;
18
- lastDequeueTimestamp;
19
- data;
20
- };
21
- __decorate([
22
- StringProperty(),
23
- __metadata("design:type", String)
24
- ], PostgresJob.prototype, "queue", void 0);
25
- __decorate([
26
- StringProperty({ nullable: true }),
27
- __metadata("design:type", Object)
28
- ], PostgresJob.prototype, "tag", void 0);
29
- __decorate([
30
- Integer(),
31
- __metadata("design:type", Number)
32
- ], PostgresJob.prototype, "priority", void 0);
33
- __decorate([
34
- TimestampProperty(),
35
- __metadata("design:type", Number)
36
- ], PostgresJob.prototype, "enqueueTimestamp", void 0);
37
- __decorate([
38
- Integer(),
39
- __metadata("design:type", Number)
40
- ], PostgresJob.prototype, "tries", void 0);
41
- __decorate([
42
- TimestampProperty({ nullable: true }),
43
- __metadata("design:type", Object)
44
- ], PostgresJob.prototype, "lastDequeueTimestamp", void 0);
45
- __decorate([
46
- JsonProperty(),
47
- __metadata("design:type", Object)
48
- ], PostgresJob.prototype, "data", void 0);
49
- PostgresJob = __decorate([
50
- Table('job', { schema: 'queue' }),
51
- Unique(['queue', 'tag'])
52
- ], PostgresJob);
53
- export { PostgresJob };
package/test6.js DELETED
@@ -1,33 +0,0 @@
1
- import { benchmark } from './utils/benchmark.js';
2
- import { isDefined } from './utils/type-guards.js';
3
- const numberFormatterMap = new Map();
4
- function getNumberFormatter1(locale, options) {
5
- const key = JSON.stringify({ locale, ...options });
6
- const existing = numberFormatterMap.get(key);
7
- if (isDefined(existing)) {
8
- return existing;
9
- }
10
- const formatter = new Intl.NumberFormat(locale, options);
11
- numberFormatterMap.set(key, formatter);
12
- return formatter;
13
- }
14
- function getNumberFormatter2(locale, options) {
15
- const key = JSON.stringify({ locale, options });
16
- const existing = numberFormatterMap.get(key);
17
- if (isDefined(existing)) {
18
- return existing;
19
- }
20
- const formatter = new Intl.NumberFormat(locale, options);
21
- numberFormatterMap.set(key, formatter);
22
- return formatter;
23
- }
24
- function format1(value, locale, format) {
25
- return getNumberFormatter1(locale, format).format(value);
26
- }
27
- function format2(value, locale, format) {
28
- return getNumberFormatter2(locale, format).format(value);
29
- }
30
- const result1 = benchmark(200000, (run) => format1(run, 'en-US', { maximumFractionDigits: 2 }));
31
- const result2 = benchmark(200000, (run) => format2(run, 'en-US', { maximumFractionDigits: 2 }));
32
- console.log(`format: ${result1.operationsPerMillisecond.toFixed(2)} ops/ms`);
33
- console.log(`formatCached: ${result2.operationsPerMillisecond.toFixed(2)} ops/ms`);