@tstdl/base 0.90.88 → 0.90.90

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.
@@ -77,7 +77,7 @@ export declare const authenticationApiDefinition: {
77
77
  method: "POST";
78
78
  parameters: ObjectSchema<{
79
79
  subject: string;
80
- data: {};
80
+ data: import("../types.js").ObjectLiteral;
81
81
  }>;
82
82
  result: import("../schema/types/types.js").ValueSchema<"ok">;
83
83
  };
@@ -4,7 +4,7 @@ import type { ObjectSchemaOrType } from '../../schema/types/types.js';
4
4
  import type { Record } from '../../types.js';
5
5
  import type { AuthenticationApiDefinition } from '../authentication.api.js';
6
6
  export declare function getAuthenticationApiClient<AdditionalTokenPayload extends Record, AuthenticationData, AdditionalInitSecretResetData extends Record>(additionalTokenPayloadSchema: ObjectSchemaOrType<AdditionalTokenPayload>, authenticationDataSchema: SchemaTestable<AuthenticationData>, additionalInitSecretResetData: ObjectSchemaOrType<AdditionalInitSecretResetData>): ApiClient<AuthenticationApiDefinition<AdditionalTokenPayload, AuthenticationData, AdditionalInitSecretResetData>>;
7
- declare const defaultAuthenticationApiClient: ApiClient<AuthenticationApiDefinition<{}, unknown, {}>>;
7
+ declare const defaultAuthenticationApiClient: ApiClient<AuthenticationApiDefinition<import("../../types.js").ObjectLiteral, unknown, import("../../types.js").ObjectLiteral>>;
8
8
  export declare class AuthenticationApiClient extends defaultAuthenticationApiClient {
9
9
  }
10
10
  export {};
@@ -1,7 +1,7 @@
1
1
  import { EntityRepository } from '../../database/index.js';
2
2
  import { afterResolve } from '../../injector/index.js';
3
3
  import { equals } from '../../utils/equals.js';
4
- import { filterUndefinedFromRecord, objectEntries, objectKeys } from '../../utils/object/object.js';
4
+ import { filterUndefinedObjectProperties, objectEntries, objectKeys } from '../../utils/object/object.js';
5
5
  import { _throw } from '../../utils/throw.js';
6
6
  import { isDefined, isUndefined } from '../../utils/type-guards.js';
7
7
  import { MongoBaseRepository } from './mongo-base.repository.js';
@@ -263,7 +263,7 @@ export class MongoEntityRepository extends EntityRepository {
263
263
  function normalizeIndex(index) {
264
264
  const { name: providedName, unique, v, background, ns, ...indexRest } = index; // eslint-disable-line @typescript-eslint/no-unused-vars
265
265
  const name = providedName ?? objectKeys(index.key).join('_');
266
- return filterUndefinedFromRecord({ name, unique: (unique == true) ? true : undefined, ...indexRest });
266
+ return filterUndefinedObjectProperties({ name, unique: (unique == true) ? true : undefined, ...indexRest });
267
267
  }
268
268
  function convertOptions(options, mappingMap) {
269
269
  if (options == undefined) {
@@ -1,5 +1,6 @@
1
1
  import { type CancellationSignal } from '../../cancellation/index.js';
2
2
  import { dispose, type Disposable } from '../../disposable/index.js';
3
+ import type { OneOrMany } from '../../schema/index.js';
3
4
  import type { Record, TypedOmit, UndefinableJson, UndefinableJsonObject } from '../../types.js';
4
5
  import { HttpForm, type HttpFormObject } from '../http-form.js';
5
6
  import { HttpHeaders, type HttpHeadersObject } from '../http-headers.js';
@@ -22,14 +23,17 @@ export type HttpRequestAuthorization = {
22
23
  bearer?: string;
23
24
  token?: string;
24
25
  };
26
+ export type HttpFormDataObjectValue = string | number | boolean | Uint8Array | Blob;
27
+ export type HttpFormDataObject = Record<string, OneOrMany<HttpFormDataObjectValue>>;
25
28
  export type HttpClientRequestOptions = Partial<TypedOmit<HttpClientRequest, 'url' | 'method' | 'abortSignal' | 'abort' | 'headers' | 'query' | 'body'>> & {
26
29
  urlParameter?: HttpUrlParametersObject | HttpUrlParameters;
27
30
  headers?: HttpHeadersObject | HttpHeaders;
28
31
  query?: HttpQueryObject | HttpQuery;
29
32
  credentials?: HttpRequestCredentials;
30
33
  authorization?: HttpRequestAuthorization;
31
- body?: TypedOmit<HttpRequestBody, 'form'> & {
34
+ body?: TypedOmit<HttpRequestBody, 'form' | 'formData'> & {
32
35
  form?: HttpFormObject | HttpForm;
36
+ formData?: HttpFormDataObject | FormData;
33
37
  };
34
38
  abortSignal?: CancellationSignal;
35
39
  };
@@ -1,7 +1,8 @@
1
1
  import { CancellationToken } from '../../cancellation/index.js';
2
2
  import { dispose } from '../../disposable/index.js';
3
3
  import { clone } from '../../utils/clone.js';
4
- import { isDefined, isString, isUndefined } from '../../utils/type-guards.js';
4
+ import { objectEntries } from '../../utils/object/object.js';
5
+ import { isArray, isBlob, isDefined, isString, isUint8Array, isUndefined } from '../../utils/type-guards.js';
5
6
  import { HttpForm } from '../http-form.js';
6
7
  import { HttpHeaders } from '../http-headers.js';
7
8
  import { HttpQuery } from '../http-query.js';
@@ -149,5 +150,28 @@ function normalizeBody(body) {
149
150
  if (isDefined(normalizedBody.form)) {
150
151
  normalizedBody.form = new HttpForm(normalizedBody.form);
151
152
  }
153
+ if (isDefined(normalizedBody.formData) && !(normalizedBody.formData instanceof FormData)) {
154
+ const formData = new FormData();
155
+ for (const [key, value] of objectEntries(normalizedBody.formData)) {
156
+ if (isArray(value)) {
157
+ for (const item of value) {
158
+ formData.append(key, convertFormDataObjectValue(item));
159
+ }
160
+ }
161
+ else {
162
+ formData.set(key, convertFormDataObjectValue(value));
163
+ }
164
+ }
165
+ normalizedBody.formData = formData;
166
+ }
152
167
  return normalizedBody;
153
168
  }
169
+ function convertFormDataObjectValue(value) {
170
+ if (isString(value) || isBlob(value)) {
171
+ return value;
172
+ }
173
+ if (isUint8Array(value)) {
174
+ return new Blob([value]);
175
+ }
176
+ return String(value);
177
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.90.88",
3
+ "version": "0.90.90",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -1,7 +1,7 @@
1
- import type { Record, SimplifiedOptionalize, SimplifyObject, TypedOmit } from '../../types.js';
1
+ import type { ObjectLiteral, Optionalize, Record, SimplifyObject, TypedOmit } from '../../types.js';
2
2
  import type { IfNever } from 'type-fest';
3
- import type { ObjectSchema, ObjectSchemaProperties, TypedObjectSchemaUnknownProperties } from '../types/index.js';
3
+ import { type ObjectSchema, type ObjectSchemaProperties, type TypedObjectSchemaUnknownProperties } from '../types/index.js';
4
4
  export type ObjectOptions<T extends Record = Record> = TypedOmit<ObjectSchema<T>, 'properties' | 'unknownProperties' | 'unknownPropertiesKey'>;
5
5
  export declare function explicitObject<T extends Record>(properties: ObjectSchemaProperties<T>, options?: ObjectOptions<T>): ObjectSchema<T>;
6
- export declare function object<T extends Record = Record<never>, K extends PropertyKey = any, V = never>(properties: ObjectSchemaProperties<T>, options?: ObjectOptions<T> & TypedObjectSchemaUnknownProperties<K, V>): ObjectSchema<SimplifyObject<SimplifiedOptionalize<T> & IfNever<V, {}, Record<K, V>>>>;
7
- export declare const emptyObjectSchema: ObjectSchema<{}>;
6
+ export declare function object<T extends Record = Record<never>, K extends PropertyKey = any, V = never>(properties: ObjectSchemaProperties<T>, options?: ObjectOptions<T> & TypedObjectSchemaUnknownProperties<K, V>): ObjectSchema<SimplifyObject<Optionalize<T> & IfNever<V, ObjectLiteral, Record<K, V>>>>;
7
+ export declare const emptyObjectSchema: ObjectSchema<ObjectLiteral>;
package/types.d.ts CHANGED
@@ -103,6 +103,7 @@ export type ReplaceIfUnknown<T, U> = IfUnknown<T, U, T>;
103
103
  export type OmitNever<T extends Record> = {
104
104
  [K in keyof T as T[K] extends never ? never : K]: T[K];
105
105
  };
106
+ export type BaseType<T extends Exclude<Primitive, null | undefined>> = T extends string ? string : never | T extends number ? number : never | T extends boolean ? boolean : never | T extends bigint ? bigint : never | T extends symbol ? symbol : never;
106
107
  export type SharedProperties<A, B, C = unknown, D = unknown, E = unknown, F = unknown, G = unknown, H = unknown, I = unknown, J = unknown> = OmitNever<Pick<A & B & C & D & E & F & G & H & I & J, keyof A & keyof B & keyof ReplaceIfUnknown<C, never> & keyof ReplaceIfUnknown<D, never> & keyof ReplaceIfUnknown<E, never> & keyof ReplaceIfUnknown<F, never> & keyof ReplaceIfUnknown<G, never> & keyof ReplaceIfUnknown<H, never> & keyof ReplaceIfUnknown<I, never> & keyof ReplaceIfUnknown<J, never>>>;
107
108
  /**
108
109
  * Omit properties from a type that extend from a specific type.
@@ -114,7 +115,6 @@ export type OmitBy<T, V> = Omit<T, {
114
115
  * Normalize properties of a type that allow `undefined` to make them optional.
115
116
  */
116
117
  export type Optionalize<T extends object> = OmitBy<T, undefined> & Partial<PickBy<T, undefined>>;
117
- export type SimplifiedOptionalize<T extends object> = SimplifyObject<Optionalize<T>>;
118
118
  export type Unoptionalize<T extends object> = SimplifyObject<OmitBy<T, undefined> & {
119
119
  [P in PropertiesOfType<T, undefined>]: T[P] | undefined;
120
120
  }>;
@@ -1,5 +1,4 @@
1
- import type { FromEntries, ObjectLiteral, PickBy, Record, SimplifyObject } from '../../types.js';
2
- import type { IsEqual } from 'type-fest';
1
+ import type { BaseType, FromEntries, ObjectLiteral, Optionalize, PickBy, Record, SimplifyObject } from '../../types.js';
3
2
  export declare function hasOwnProperty<T extends Record>(obj: T, key: keyof T): boolean;
4
3
  /**
5
4
  * Returns object entries including those with symbols keys (which Object.entries does not)
@@ -19,10 +18,8 @@ export declare function mapObjectValuesAsync<T extends ObjectLiteral, V>(object:
19
18
  export declare function filterObject<T extends ObjectLiteral, U extends T[keyof T]>(object: T, predicate: (value: T[keyof T], key: keyof T) => value is U): PickBy<T, U>;
20
19
  export declare function filterObject<T extends ObjectLiteral>(object: T, predicate: (value: T[keyof T], key: keyof T) => boolean): Partial<T>;
21
20
  export declare function filterObjectAsync<T extends ObjectLiteral>(object: T, predicate: (value: T[keyof T], key: keyof T) => Promise<boolean>): Promise<Partial<T>>;
22
- export declare function filterUndefinedFromRecord<T extends Record>(record: T): T extends Record<infer K, infer V> ? Record<K, Exclude<V, undefined>> : never;
23
- export declare function filterUndefinedObjectProperties<T extends ObjectLiteral>(object: T): {
24
- [P in keyof T]?: IsEqual<T[P], undefined> extends true ? never : Exclude<T[P], undefined>;
25
- };
21
+ export declare function filterUndefinedFromRecord<K extends PropertyKey, V>(record: Record<K, V>): Record<BaseType<K>, Exclude<V, undefined>>;
22
+ export declare function filterUndefinedObjectProperties<T extends ObjectLiteral>(object: T): SimplifyObject<Optionalize<T>>;
26
23
  export declare function copyObjectProperties<T extends ObjectLiteral, U extends T>(source: T, target: U): void;
27
24
  export declare function getGetter<T extends ObjectLiteral, U extends keyof T>(obj: T, property: keyof T, bind: boolean): () => T[U];
28
25
  export declare function deepObjectEntries(object: ObjectLiteral, keepInnerObjects?: boolean, prefix?: string): [string, any][];