@tstdl/base 0.93.62 → 0.93.66
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/ai/genkit/helpers.d.ts +10 -0
- package/ai/genkit/helpers.js +14 -0
- package/ai/genkit/index.d.ts +2 -0
- package/ai/genkit/index.js +2 -0
- package/ai/genkit/module.d.ts +35 -0
- package/ai/genkit/module.js +56 -0
- package/ai/index.d.ts +1 -0
- package/ai/index.js +1 -0
- package/ai/prompts/format.d.ts +15 -0
- package/ai/prompts/format.js +17 -0
- package/ai/prompts/index.d.ts +3 -0
- package/ai/prompts/index.js +3 -0
- package/ai/prompts/instructions-formatter.d.ts +25 -0
- package/ai/prompts/instructions-formatter.js +166 -0
- package/ai/prompts/instructions.d.ts +3 -0
- package/ai/prompts/instructions.js +8 -0
- package/document-management/server/services/document-file.service.d.ts +2 -0
- package/document-management/server/services/document-file.service.js +10 -9
- package/document-management/server/services/document-management-ai.service.d.ts +1 -0
- package/document-management/server/services/document-management-ai.service.js +267 -133
- package/document-management/server/services/document.service.js +1 -2
- package/examples/document-management/main.js +6 -0
- package/json-path/json-path.js +1 -1
- package/orm/server/repository.js +4 -6
- package/package.json +10 -6
- package/pdf/utils.js +1 -1
- package/schema/converters/zod-converter.d.ts +1 -1
- package/schema/converters/zod-converter.js +2 -13
- package/schema/converters/zod-v3-converter.d.ts +3 -3
- package/utils/date-time.d.ts +6 -0
- package/utils/date-time.js +36 -1
- package/utils/file-reader.d.ts +0 -1
- package/utils/file-reader.js +4 -7
- package/utils/object/object.d.ts +4 -2
- package/utils/object/object.js +30 -21
- package/utils/stream/from-promise.js +2 -2
package/pdf/utils.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { match, P } from 'ts-pattern';
|
|
2
|
-
import { z } from 'zod';
|
|
2
|
+
import { z } from 'zod/v4';
|
|
3
3
|
import { NotSupportedError } from '../../errors/not-supported.error.js';
|
|
4
4
|
import { JsonPath } from '../../json-path/json-path.js';
|
|
5
5
|
import { objectEntries, objectKeys } from '../../utils/object/object.js';
|
|
6
6
|
import { isArray, isInstanceOf, isNotNull, isNumber, isString } from '../../utils/type-guards.js';
|
|
7
7
|
import { SchemaError } from '../schema.error.js';
|
|
8
|
-
import { any, AnySchema, ArraySchema, BigIntSchema, BooleanSchema, ConstraintSchema, DateSchema, DefaultSchema, DeferredSchema, EnumerationSchema,
|
|
8
|
+
import { any, AnySchema, ArraySchema, BigIntSchema, BooleanSchema, ConstraintSchema, DateSchema, DefaultSchema, DeferredSchema, EnumerationSchema, InstanceSchema, LiteralSchema, NeverSchema, NullableSchema, NumberSchema, ObjectSchema, OneOrManySchema, OptionalSchema, ReadableStreamSchema, RegExpSchema, StringSchema, SymbolSchema, TransformSchema, Uint8ArraySchema, UnionSchema, UnknownSchema } from '../schemas/index.js';
|
|
9
9
|
import { schemaTestableToSchema } from '../testable.js';
|
|
10
10
|
export function convertToZodSchema(testable, options) {
|
|
11
11
|
const schema = schemaTestableToSchema(testable);
|
|
@@ -143,17 +143,6 @@ function convertToZodSchemaBase(schema, options) {
|
|
|
143
143
|
// enumeration is either EnumerationObject or string-only EnumerationArray, both is fine for z.enum
|
|
144
144
|
// using `as`, as z.enum is overloaded and only one type per overload
|
|
145
145
|
return z.enum(s.enumeration);
|
|
146
|
-
})
|
|
147
|
-
.with(P.instanceOf(FunctionSchema), (s) => {
|
|
148
|
-
let zodSchema = z.function();
|
|
149
|
-
if (isNotNull(s.parameterSchemas)) {
|
|
150
|
-
const args = s.parameterSchemas.map((parameterSchema) => convertToZodSchemaBase(parameterSchema, options));
|
|
151
|
-
zodSchema = zodSchema.input(...args);
|
|
152
|
-
}
|
|
153
|
-
if (isNotNull(s.returnValueSchema)) {
|
|
154
|
-
zodSchema = zodSchema.output(convertToZodSchemaBase(s.returnValueSchema, options));
|
|
155
|
-
}
|
|
156
|
-
return zodSchema;
|
|
157
146
|
})
|
|
158
147
|
.with(P.instanceOf(DefaultSchema), (s) => convertToZodSchemaBase(s.schema, options).default(s.defaultValue))
|
|
159
148
|
.with(P.instanceOf(TransformSchema), (s) => convertToZodSchemaBase(s.schema, options).transform((input) => s.transformFn(input)))
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type ZodObject, type ZodType, type ZodTypeDef } from 'zod/v3';
|
|
2
2
|
import type { Record } from '../../types/types.js';
|
|
3
3
|
import type { SchemaTestable } from '../schema.js';
|
|
4
4
|
import { ObjectSchema } from '../schemas/index.js';
|
|
@@ -9,5 +9,5 @@ export type SchemaConversionOptions = {
|
|
|
9
9
|
mask?: boolean;
|
|
10
10
|
};
|
|
11
11
|
/** WARNING: *DOES NOT* cover all schemas and options. Meant for usage in schema generators like genkit, not for full schema testing in APIs etc. */
|
|
12
|
-
export declare function convertToZodV3Schema<T extends Record>(testable: ObjectSchema<T>, options?: SchemaConversionOptions):
|
|
13
|
-
export declare function convertToZodV3Schema<O, I = unknown>(testable: SchemaTestable<O>, options?: SchemaConversionOptions):
|
|
12
|
+
export declare function convertToZodV3Schema<T extends Record>(testable: ObjectSchema<T>, options?: SchemaConversionOptions): ZodObject<any, any, any, T>;
|
|
13
|
+
export declare function convertToZodV3Schema<O, I = unknown>(testable: SchemaTestable<O>, options?: SchemaConversionOptions): ZodType<O, ZodTypeDef, I>;
|
package/utils/date-time.d.ts
CHANGED
|
@@ -56,3 +56,9 @@ export declare function dateTimeToNumericDate(dateTime: DateTime): number;
|
|
|
56
56
|
export declare function numericDateToDateTime(numericDate: number, units?: DateObjectUnits, options?: DateTimeJSOptions): DateTime;
|
|
57
57
|
export declare function dateTimeToTime(dateTime: DateTime): number;
|
|
58
58
|
export declare function numericDateTimeToDateTime({ date, time }: NumericDateTime, zone?: string): DateTime;
|
|
59
|
+
/** Converts a timestamp, Date, DateTime, ISO date string, or DateObject to a numeric date */
|
|
60
|
+
export declare function toNumericDate(value: number | Date | DateTime | string | DateObject): number;
|
|
61
|
+
export declare function toNumericDate<N extends null | undefined>(value: number | Date | DateTime | string | DateObject | N): number | N;
|
|
62
|
+
/** Converts a numeric date to an ISO date string (YYYY-MM-DD) */
|
|
63
|
+
export declare function numericDateToIsoDate(numericDate: number): string;
|
|
64
|
+
export declare function numericDateToIsoDate<N extends null | undefined>(numericDate: number | N): string | N;
|
package/utils/date-time.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { NotSupportedError } from '../errors/not-supported.error.js';
|
|
2
2
|
import { DateTime } from 'luxon';
|
|
3
|
-
import {
|
|
3
|
+
import { hasOwnProperty } from './object/object.js';
|
|
4
|
+
import { isDate, isNullOrUndefined, isNumber, isString } from './type-guards.js';
|
|
4
5
|
import { typeOf } from './type-of.js';
|
|
5
6
|
import { millisecondsPerDay, millisecondsPerHour, millisecondsPerMinute, millisecondsPerSecond } from './units.js';
|
|
6
7
|
export function now() {
|
|
@@ -126,3 +127,37 @@ export function dateTimeToTime(dateTime) {
|
|
|
126
127
|
export function numericDateTimeToDateTime({ date, time }, zone) {
|
|
127
128
|
return numericDateToDateTime(date, undefined, { zone }).set({ millisecond: time });
|
|
128
129
|
}
|
|
130
|
+
export function toNumericDate(value) {
|
|
131
|
+
if (isNullOrUndefined(value)) {
|
|
132
|
+
return value;
|
|
133
|
+
}
|
|
134
|
+
if (isNumber(value)) {
|
|
135
|
+
return timestampToNumericDate(value);
|
|
136
|
+
}
|
|
137
|
+
if (isDate(value)) {
|
|
138
|
+
return dateToNumericDate(value);
|
|
139
|
+
}
|
|
140
|
+
if (DateTime.isDateTime(value)) {
|
|
141
|
+
return dateTimeToNumericDate(value);
|
|
142
|
+
}
|
|
143
|
+
if (isString(value)) {
|
|
144
|
+
const dateTime = DateTime.fromISO(value, { zone: 'UTC' });
|
|
145
|
+
if (!dateTime.isValid) {
|
|
146
|
+
throw new Error(`Invalid ISO date string "${value}": ${dateTime.invalidExplanation}`);
|
|
147
|
+
}
|
|
148
|
+
return dateTimeToNumericDate(dateTime);
|
|
149
|
+
}
|
|
150
|
+
if (hasOwnProperty(value, 'year') && hasOwnProperty(value, 'month') && hasOwnProperty(value, 'day')) {
|
|
151
|
+
return dateObjectToNumericDate(value);
|
|
152
|
+
}
|
|
153
|
+
throw new NotSupportedError(`Unsupported input type "${typeOf(value)}".`);
|
|
154
|
+
}
|
|
155
|
+
export function numericDateToIsoDate(numericDate) {
|
|
156
|
+
if (isNullOrUndefined(numericDate)) {
|
|
157
|
+
return numericDate;
|
|
158
|
+
}
|
|
159
|
+
const { year, month, day } = numericDateToDateObject(numericDate);
|
|
160
|
+
const monthString = month.toString().padStart(2, '0');
|
|
161
|
+
const dayString = day.toString().padStart(2, '0');
|
|
162
|
+
return `${year}-${monthString}-${dayString}`;
|
|
163
|
+
}
|
package/utils/file-reader.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
export declare function readAsText(blob: Blob, encoding?: string): Promise<string>;
|
|
2
2
|
export declare function readAsArrayBuffer(blob: Blob): Promise<ArrayBuffer>;
|
|
3
|
-
export declare function readAsBinaryString(blob: Blob): Promise<string>;
|
|
4
3
|
export declare function readAsDataUrl(blob: Blob): Promise<string>;
|
package/utils/file-reader.js
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
import { DetailsError } from '../errors/details.error.js';
|
|
2
2
|
export async function readAsText(blob, encoding) {
|
|
3
|
-
return setup((reader) => reader.readAsText(blob, encoding));
|
|
3
|
+
return await setup((reader) => reader.readAsText(blob, encoding));
|
|
4
4
|
}
|
|
5
5
|
export async function readAsArrayBuffer(blob) {
|
|
6
|
-
return setup((reader) => reader.readAsArrayBuffer(blob));
|
|
7
|
-
}
|
|
8
|
-
export async function readAsBinaryString(blob) {
|
|
9
|
-
return setup((reader) => reader.readAsBinaryString(blob));
|
|
6
|
+
return await setup((reader) => reader.readAsArrayBuffer(blob));
|
|
10
7
|
}
|
|
11
8
|
export async function readAsDataUrl(blob) {
|
|
12
|
-
return setup((reader) => reader.readAsDataURL(blob));
|
|
9
|
+
return await setup((reader) => reader.readAsDataURL(blob));
|
|
13
10
|
}
|
|
14
11
|
async function setup(dispatcher) {
|
|
15
|
-
return new Promise((resolve, reject) => {
|
|
12
|
+
return await new Promise((resolve, reject) => {
|
|
16
13
|
const reader = new FileReader();
|
|
17
14
|
reader.onload = () => resolve(reader.result);
|
|
18
15
|
reader.onerror = () => reject(new DetailsError(reader.error.message, reader.error));
|
package/utils/object/object.d.ts
CHANGED
|
@@ -30,6 +30,8 @@ export declare function filterNullishObjectProperties<T extends ObjectLiteral>(o
|
|
|
30
30
|
export declare function copyObjectProperties<T extends ObjectLiteral>(source: T, target: T): void;
|
|
31
31
|
export declare function getGetter<T extends ObjectLiteral, U extends keyof T>(obj: T, property: U, bind: boolean): () => T[U];
|
|
32
32
|
export declare function deepObjectEntries(object: ObjectLiteral, keepInnerObjects?: boolean, prefix?: string): [string, any][];
|
|
33
|
+
export declare function assignDeep(target: object, path: JsonPathInput, value: any): void;
|
|
34
|
+
export declare function assignDeepObjectEntries(target: object, entries: readonly (readonly [JsonPathInput, any])[]): void;
|
|
33
35
|
export declare function fromDeepObjectEntries(entries: readonly (readonly [JsonPathInput, any])[]): ObjectLiteral;
|
|
34
|
-
export declare function omit<T extends Record, K extends keyof T>(object: T,
|
|
35
|
-
export declare function pick<T extends Record, K extends keyof T>(object: T,
|
|
36
|
+
export declare function omit<T extends Record, K extends keyof T>(object: T, keys: K[]): SimplifyObject<Omit<T, K>>;
|
|
37
|
+
export declare function pick<T extends Record, K extends keyof T>(object: T, keys: K[]): SimplifyObject<Pick<T, K>>;
|
package/utils/object/object.js
CHANGED
|
@@ -3,7 +3,7 @@ import { filterAsync } from '../async-iterable-helpers/filter.js';
|
|
|
3
3
|
import { mapAsync } from '../async-iterable-helpers/map.js';
|
|
4
4
|
import { toArrayAsync } from '../async-iterable-helpers/to-array.js';
|
|
5
5
|
import { toSnakeCase } from '../string/index.js';
|
|
6
|
-
import { isArray, isDefined, isNotNullOrUndefined, isNullOrUndefined, isObject, isSymbol, isUndefined } from '../type-guards.js';
|
|
6
|
+
import { isArray, isDefined, isNotNull, isNotNullOrUndefined, isNullOrUndefined, isObject, isSymbol, isUndefined } from '../type-guards.js';
|
|
7
7
|
export function hasOwnProperty(obj, key) {
|
|
8
8
|
return Object.hasOwn(obj, key);
|
|
9
9
|
}
|
|
@@ -84,7 +84,7 @@ export function getGetter(obj, property, bind) {
|
|
|
84
84
|
throw new Error(`Property ${property} does not exist.`);
|
|
85
85
|
}
|
|
86
86
|
let objOrPrototype = obj;
|
|
87
|
-
while (!hasOwnProperty(objOrPrototype, property)) {
|
|
87
|
+
while (isNotNull(objOrPrototype) && !hasOwnProperty(objOrPrototype, property)) {
|
|
88
88
|
objOrPrototype = Object.getPrototypeOf(objOrPrototype);
|
|
89
89
|
}
|
|
90
90
|
const descriptor = Object.getOwnPropertyDescriptor(objOrPrototype, property);
|
|
@@ -123,33 +123,42 @@ export function deepObjectEntries(object, keepInnerObjects = false, prefix) {
|
|
|
123
123
|
}
|
|
124
124
|
return entries;
|
|
125
125
|
}
|
|
126
|
-
export function
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
126
|
+
export function assignDeep(target, path, value) {
|
|
127
|
+
const jsonPath = JsonPath.from(path);
|
|
128
|
+
let currentTarget = target;
|
|
129
|
+
for (let i = 0; i < jsonPath.nodes.length - 1; i++) {
|
|
130
|
+
const key = jsonPath.nodes[i];
|
|
131
|
+
if (key == '__proto__') {
|
|
132
|
+
throw new Error('Assignment to __proto__ is not allowed for security reasons.');
|
|
133
|
+
}
|
|
134
|
+
if (isDefined(currentTarget[key])) {
|
|
135
|
+
currentTarget = currentTarget[key];
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
const child = {};
|
|
139
|
+
currentTarget[key] = child;
|
|
140
|
+
currentTarget = child;
|
|
141
141
|
}
|
|
142
|
-
target[jsonPath.nodes.at(-1)] = value;
|
|
143
142
|
}
|
|
143
|
+
currentTarget[jsonPath.nodes.at(-1)] = value;
|
|
144
|
+
}
|
|
145
|
+
export function assignDeepObjectEntries(target, entries) {
|
|
146
|
+
for (const [path, value] of entries) {
|
|
147
|
+
assignDeep(target, path, value);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
export function fromDeepObjectEntries(entries) {
|
|
151
|
+
const obj = {};
|
|
152
|
+
assignDeepObjectEntries(obj, entries);
|
|
144
153
|
return obj;
|
|
145
154
|
}
|
|
146
|
-
export function omit(object,
|
|
155
|
+
export function omit(object, keys) {
|
|
147
156
|
return filterObject(object, (_, key) => !keys.includes(key));
|
|
148
157
|
}
|
|
149
|
-
export function pick(object,
|
|
158
|
+
export function pick(object, keys) {
|
|
150
159
|
const result = {};
|
|
151
160
|
for (const key of keys) {
|
|
152
|
-
if (
|
|
161
|
+
if (key in object) {
|
|
153
162
|
result[key] = object[key];
|
|
154
163
|
}
|
|
155
164
|
}
|
|
@@ -2,8 +2,8 @@ import { resolveValueOrProvider } from '../value-or-provider.js';
|
|
|
2
2
|
export function readableStreamFromPromise(promiseOrProvider) {
|
|
3
3
|
const stream = new TransformStream();
|
|
4
4
|
resolveValueOrProvider(promiseOrProvider)
|
|
5
|
-
.then(async (readable) => readable.pipeTo(stream.writable))
|
|
6
|
-
.catch(async (error) => stream.writable.abort(error).catch(() => { }));
|
|
5
|
+
.then(async (readable) => await readable.pipeTo(stream.writable))
|
|
6
|
+
.catch(async (error) => await stream.writable.abort(error).catch(() => { }));
|
|
7
7
|
return stream.readable;
|
|
8
8
|
}
|
|
9
9
|
export function transformStreamFromPromise(promiseOrProvider) {
|