@tstdl/base 0.92.90 → 0.92.92

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.
@@ -4,64 +4,13 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
4
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
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
- var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
8
- if (value !== null && value !== void 0) {
9
- if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
10
- var dispose, inner;
11
- if (async) {
12
- if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
13
- dispose = value[Symbol.asyncDispose];
14
- }
15
- if (dispose === void 0) {
16
- if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
17
- dispose = value[Symbol.dispose];
18
- if (async) inner = dispose;
19
- }
20
- if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
21
- if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
22
- env.stack.push({ value: value, dispose: dispose, async: async });
23
- }
24
- else if (async) {
25
- env.stack.push({ async: true });
26
- }
27
- return value;
28
- };
29
- var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
30
- return function (env) {
31
- function fail(e) {
32
- env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
33
- env.hasError = true;
34
- }
35
- var r, s = 0;
36
- function next() {
37
- while (r = env.stack.pop()) {
38
- try {
39
- if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
40
- if (r.dispose) {
41
- var result = r.dispose.call(r.value);
42
- if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
43
- }
44
- else s |= 1;
45
- }
46
- catch (e) {
47
- fail(e);
48
- }
49
- }
50
- if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
51
- if (env.hasError) throw env.error;
52
- }
53
- return next();
54
- };
55
- })(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
56
- var e = new Error(message);
57
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
58
- });
59
7
  import '../polyfills.js';
8
+ import { readFile } from 'node:fs/promises';
60
9
  import { Storage } from '@google-cloud/storage';
61
10
  import { FileState, GoogleAIFileManager } from '@google/generative-ai/server';
62
11
  import { AsyncEnumerable } from '../enumerable/async-enumerable.js';
63
12
  import { DetailsError } from '../errors/details.error.js';
64
- import { TemporaryFile } from '../file/temporary-file.js';
13
+ import { NotImplementedError } from '../errors/not-implemented.error.js';
65
14
  import { Singleton } from '../injector/decorators.js';
66
15
  import { inject, injectArgument } from '../injector/inject.js';
67
16
  import { Logger } from '../logger/logger.js';
@@ -113,43 +62,33 @@ let AiFileService = class AiFileService {
113
62
  return files;
114
63
  }
115
64
  async uploadFile(fileInput, id) {
116
- const env_1 = { stack: [], error: void 0, hasError: false };
117
- try {
118
- const inputIsBlob = isBlob(fileInput);
119
- const tmpFile = __addDisposableResource(env_1, inputIsBlob
120
- ? await TemporaryFile.from(fileInput.stream())
121
- : undefined, true);
122
- const path = inputIsBlob ? tmpFile.path : fileInput.path;
123
- const mimeType = inputIsBlob ? fileInput.type : fileInput.mimeType;
124
- const fileSize = inputIsBlob ? fileInput.size : await tmpFile.size();
125
- this.#logger.verbose(`Uploading file "${id}" (${formatBytes(fileSize)})...`);
126
- if (isDefined(this.#storage)) {
127
- const bucket = await this.getBucket();
128
- const [file] = await bucket.upload(path, { destination: id, contentType: mimeType });
129
- return {
130
- id,
131
- name: id,
132
- uri: file.cloudStorageURI.toString(),
133
- mimeType
134
- };
135
- }
136
- const response = await this.#fileManager.uploadFile(path, { mimeType });
65
+ const inputIsBlob = isBlob(fileInput);
66
+ const buffer = inputIsBlob
67
+ ? await fileInput.bytes()
68
+ : await readFile(fileInput.path);
69
+ const mimeType = inputIsBlob ? fileInput.type : fileInput.mimeType;
70
+ this.#logger.verbose(`Uploading file "${id}" (${formatBytes(buffer.length)})...`);
71
+ if (isDefined(this.#storage)) {
72
+ throw new NotImplementedError();
73
+ /*
74
+ const bucket = await this.getBucket();
75
+ const [file] = await bucket.upload(path, { destination: id, contentType: mimeType });
76
+
137
77
  return {
138
- id,
139
- name: response.file.name,
140
- uri: response.file.uri,
141
- mimeType: response.file.mimeType
78
+ id,
79
+ name: id,
80
+ uri: file.cloudStorageURI.toString(),
81
+ mimeType
142
82
  };
83
+ */
143
84
  }
144
- catch (e_1) {
145
- env_1.error = e_1;
146
- env_1.hasError = true;
147
- }
148
- finally {
149
- const result_1 = __disposeResources(env_1);
150
- if (result_1)
151
- await result_1;
152
- }
85
+ const response = await this.#fileManager.uploadFile(buffer, { mimeType });
86
+ return {
87
+ id,
88
+ name: response.file.name,
89
+ uri: response.file.uri,
90
+ mimeType: response.file.mimeType
91
+ };
153
92
  }
154
93
  async getBucket() {
155
94
  if (isUndefined(this.#options.vertex)) {
package/orm/query.d.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  import type { SQLWrapper } from 'drizzle-orm';
2
2
  import type { Flatten, Record } from '../types.js';
3
3
  import type { Geometry } from '../types/geo-json.js';
4
- import type { Untagged } from '../types/tagged.js';
4
+ import type { UntaggedDeep } from '../types/tagged.js';
5
5
  export type LogicalQuery<T = any> = LogicalAndQuery<T> | LogicalOrQuery<T> | LogicalNorQuery<T>;
6
6
  export type LogicalQueryTypes = keyof (LogicalAndQuery & LogicalOrQuery & LogicalNorQuery);
7
7
  export declare const allLogicalQueryTypes: LogicalQueryTypes[];
8
8
  export type ComparisonQueryBody<T = any> = {
9
- [P in keyof T]?: ComparisonQueryOrValue<T[P]>;
9
+ [P in keyof T]?: T[P] extends Record ? ComparisonQueryBody<T[P]> : ComparisonQueryOrValue<T[P]>;
10
10
  } & Record<ComparisonQueryOrValue>;
11
11
  export type ComparisonQueryOrValue<T = any> = ComparisonQuery<T> | ComparisonValue<T>;
12
12
  export type ComparisonQuery<T = any> = Partial<ComparisonNotQuery<T> & ComparisonEqualsQuery<T> & ComparisonNotEqualsQuery<T> & ComparisonExistsQuery & ComparisonItemQuery<T> & ComparisonInQuery<T> & ComparisonNotInQuery<T> & ComparisonAllQuery<T> & ComparisonGreaterThanQuery<T> & ComparisonGreaterThanOrEqualsQuery<T> & ComparisonLessThanQuery<T> & ComparisonLessThanOrEqualsQuery<T> & ComparisonRegexQuery & ComparisonTextQuery & ComparisonGeoShapeQuery & ComparisonGeoDistanceQuery>;
@@ -15,7 +15,7 @@ export declare const allComparisonQueryTypes: ComparisonQueryTypes[];
15
15
  export type SpecialQuery<T = any> = Partial<TextSpanQuery<T>>;
16
16
  export type SpecialQueryTypes = keyof SpecialQuery;
17
17
  export declare const allSpecialQueryTypes: SpecialQueryTypes[];
18
- export type Query<T = any> = SQLWrapper | QueryObject<T>;
18
+ export type Query<T = any> = SQLWrapper | QueryObject<UntaggedDeep<T>>;
19
19
  export type QueryObject<T> = LogicalQuery<T> | (ComparisonQueryBody<T> & SpecialQuery<T>);
20
20
  export type QueryTypes = LogicalQueryTypes | ComparisonQueryTypes | SpecialQueryTypes;
21
21
  export declare const allQueryTypes: ("$and" | "$or" | "$nor" | "$not" | "$eq" | "$neq" | "$exists" | "$item" | "$in" | "$nin" | "$all" | "$gt" | "$gte" | "$lt" | "$lte" | "$regex" | "$text" | "$geoShape" | "$geoDistance" | "$textSpan")[];
@@ -30,7 +30,7 @@ export type LogicalOrQuery<T = any> = {
30
30
  export type LogicalNorQuery<T = any> = {
31
31
  $nor: readonly Query<T>[];
32
32
  };
33
- export type ComparisonValue<T> = Untagged<T | Flatten<T>> | SQLWrapper;
33
+ export type ComparisonValue<T> = T | Flatten<T> | SQLWrapper;
34
34
  export type ComparisonValueWithRegex<T> = T extends string ? ComparisonValue<T | RegExp> : T extends readonly string[] ? ComparisonValue<readonly (Flatten<T> | RegExp)[]> : (T | Flatten<T>);
35
35
  export type ComparisonNotQuery<T = any> = {
36
36
  $not: ComparisonQuery<T>;
@@ -75,8 +75,8 @@ export declare class EntityRepository<T extends Entity | EntityWithoutMetadata =
75
75
  tryHardDeleteByQuery(query: Query<T>): Promise<T | undefined>;
76
76
  hardDeleteMany(ids: string[]): Promise<T[]>;
77
77
  hardDeleteManyByQuery(query: Query<T>): Promise<T[]>;
78
- $getColumn(pathOrColumn: Paths<UntaggedDeep<T>> | ColumnDefinition): PgColumn;
79
- $convertOrderBy(orderBy: Order<T>): SQL<unknown>[];
78
+ getColumn(pathOrColumn: Paths<UntaggedDeep<T>> | ColumnDefinition): PgColumn;
79
+ convertOrderBy(orderBy: Order<T>): SQL<unknown>[];
80
80
  convertQuery(query: Query<T>): SQL;
81
81
  mapManyToEntity(columns: InferSelect[]): Promise<T[]>;
82
82
  mapToEntity(columns: InferSelect): Promise<T>;
@@ -125,7 +125,7 @@ let EntityRepository = class EntityRepository {
125
125
  .offset(options?.offset)
126
126
  .$dynamic();
127
127
  if (isDefined(options?.order)) {
128
- dbQuery = dbQuery.orderBy(...this.$convertOrderBy(options.order));
128
+ dbQuery = dbQuery.orderBy(...this.convertOrderBy(options.order));
129
129
  }
130
130
  const [row] = await dbQuery;
131
131
  if (isUndefined(row)) {
@@ -150,7 +150,7 @@ let EntityRepository = class EntityRepository {
150
150
  .limit(options?.limit)
151
151
  .$dynamic();
152
152
  if (isDefined(options?.order)) {
153
- dbQuery = dbQuery.orderBy(...this.$convertOrderBy(options.order));
153
+ dbQuery = dbQuery.orderBy(...this.convertOrderBy(options.order));
154
154
  }
155
155
  const rows = await dbQuery;
156
156
  return this.mapManyToEntity(rows);
@@ -230,7 +230,7 @@ let EntityRepository = class EntityRepository {
230
230
  return this.mapManyToEntity(rows);
231
231
  }
232
232
  async upsert(target, entity, update) {
233
- const targetColumns = toArray(target).map((path) => this.$getColumn(path));
233
+ const targetColumns = toArray(target).map((path) => this.getColumn(path));
234
234
  const columns = await this.mapToInsertColumns(entity);
235
235
  const mappedUpdate = await this.mapUpdate(update ?? entity);
236
236
  const [row] = await this.session
@@ -244,12 +244,12 @@ let EntityRepository = class EntityRepository {
244
244
  return this.mapToEntity(row);
245
245
  }
246
246
  async upsertMany(target, entities, update) {
247
- const targetColumns = toArray(target).map((path) => this.$getColumn(path));
247
+ const targetColumns = toArray(target).map((path) => this.getColumn(path));
248
248
  const columns = await this.mapManyToInsertColumns(entities);
249
249
  const mappedUpdate = isDefined(update)
250
250
  ? await this.mapUpdate(update)
251
251
  : {
252
- ...fromEntries(this.#columnDefinitions.map((column) => [column.name, sql `excluded.${sql.identifier(this.$getColumn(column).name)}`])),
252
+ ...fromEntries(this.#columnDefinitions.map((column) => [column.name, sql `excluded.${sql.identifier(this.getColumn(column).name)}`])),
253
253
  ...this._getMetadataUpdate(update)
254
254
  };
255
255
  const rows = await this.session
@@ -427,26 +427,26 @@ let EntityRepository = class EntityRepository {
427
427
  .returning();
428
428
  return this.mapManyToEntity(rows);
429
429
  }
430
- $getColumn(pathOrColumn) {
430
+ getColumn(pathOrColumn) {
431
431
  if (isString(pathOrColumn)) {
432
432
  const columnName = assertDefinedPass(this.#columnDefinitionsMap.get(pathOrColumn), `Could not map ${pathOrColumn} to column.`).name;
433
433
  return this.#table[columnName];
434
434
  }
435
435
  return this.#table[pathOrColumn.name];
436
436
  }
437
- $convertOrderBy(orderBy) {
437
+ convertOrderBy(orderBy) {
438
438
  if (isArray(orderBy)) {
439
439
  return orderBy.map((item) => {
440
440
  const itemIsArray = isArray(item);
441
441
  const target = itemIsArray ? item[0] : item;
442
- const column = isSQLWrapper(target) ? target : this.$getColumn(target);
442
+ const column = isSQLWrapper(target) ? target : this.getColumn(target);
443
443
  const direction = itemIsArray ? item[1] : 'asc';
444
444
  return direction == 'asc' ? asc(column) : desc(column);
445
445
  });
446
446
  }
447
447
  return objectEntries(orderBy)
448
448
  .map(([path, direction]) => {
449
- const column = this.$getColumn(path);
449
+ const column = this.getColumn(path);
450
450
  return direction == 'asc' ? asc(column) : desc(column);
451
451
  });
452
452
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.92.90",
3
+ "version": "0.92.92",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -93,6 +93,7 @@
93
93
  "./promise": "./promise/index.js",
94
94
  "./queue": "./queue/index.js",
95
95
  "./queue/mongo": "./queue/mongo/index.js",
96
+ "./queue/postgres": "./queue/postgres/index.js",
96
97
  "./random": "./random/index.js",
97
98
  "./reflection": "./reflection/index.js",
98
99
  "./rpc": "./rpc/index.js",
@@ -159,7 +160,7 @@
159
160
  },
160
161
  "peerDependencies": {
161
162
  "@elastic/elasticsearch": "^8.17",
162
- "@google/generative-ai": "^0.23",
163
+ "@google/generative-ai": "^0.24",
163
164
  "@tstdl/angular": "^0.92",
164
165
  "@zxcvbn-ts/core": "^3.0",
165
166
  "@zxcvbn-ts/language-common": "^3.0",
@@ -139,6 +139,7 @@ let PostgresQueue = class PostgresQueue extends Queue {
139
139
  };
140
140
  PostgresQueue = __decorate([
141
141
  Singleton({
142
+ argumentIdentityProvider: JSON.stringify,
142
143
  providers: [
143
144
  provide(EntityRepositoryConfig, { useValue: { schema: 'queue' } }),
144
145
  provide(DatabaseConfig, { useFactory: (_, context) => context.resolve(PostgresQueueModuleConfig).database ?? context.resolve(DatabaseConfig, undefined, { skipSelf: true }) })