@augment-vir/common 31.28.0 → 31.29.0
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/dist/augments/prisma/base-prisma-types.d.ts +15 -16
- package/dist/augments/prisma/prisma-basic-model.d.ts +5 -6
- package/dist/augments/prisma/prisma-full-model.d.ts +12 -36
- package/dist/augments/prisma/prisma-model-create.d.ts +7 -6
- package/dist/augments/prisma/prisma-model-name.d.ts +2 -2
- package/dist/augments/string/casing/capitalization.d.ts +1 -0
- package/dist/augments/string/casing/capitalization.js +2 -0
- package/dist/augments/string/casing/casing.d.ts +17 -1
- package/dist/augments/string/casing/casing.js +17 -0
- package/package.json +3 -3
|
@@ -1,20 +1,4 @@
|
|
|
1
1
|
import { type AnyFunction, type AnyObject } from '@augment-vir/core';
|
|
2
|
-
/**
|
|
3
|
-
* A base type for Prisma model payloads because Prisma doesn't give us one. This currently only
|
|
4
|
-
* includes the properties that are used within this package.
|
|
5
|
-
*
|
|
6
|
-
* Note: this omits the `composites` property because I don't have any examples of what those
|
|
7
|
-
* actually are.
|
|
8
|
-
*
|
|
9
|
-
* @category Prisma : Common
|
|
10
|
-
* @category Package : @augment-vir/common
|
|
11
|
-
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
12
|
-
*/
|
|
13
|
-
export type BasePrismaPayload = {
|
|
14
|
-
name: string;
|
|
15
|
-
objects: Record<string, BasePrismaPayload | BasePrismaPayload[] | null>;
|
|
16
|
-
scalars: AnyObject;
|
|
17
|
-
};
|
|
18
2
|
/**
|
|
19
3
|
* Base Prisma client type that all `PrismaClient` instances should be able to match, with enough
|
|
20
4
|
* data that it'll omit random accidental objects.
|
|
@@ -36,3 +20,18 @@ export type BasePrismaClient = {
|
|
|
36
20
|
} & {
|
|
37
21
|
[ModelName in string]: any;
|
|
38
22
|
};
|
|
23
|
+
/**
|
|
24
|
+
* Base Prisma.TypeMap type.
|
|
25
|
+
*
|
|
26
|
+
* @category Prisma : Common
|
|
27
|
+
* @category Package : @augment-vir/common
|
|
28
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
29
|
+
*/
|
|
30
|
+
export type BaseTypeMap = {
|
|
31
|
+
model: Record<string, {
|
|
32
|
+
payload: {
|
|
33
|
+
scalars: AnyObject;
|
|
34
|
+
objects: AnyObject;
|
|
35
|
+
};
|
|
36
|
+
}>;
|
|
37
|
+
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import { type PrismaModelName } from './prisma-model-name.js';
|
|
1
|
+
import { type BaseTypeMap } from './base-prisma-types.js';
|
|
3
2
|
/**
|
|
4
3
|
* A basic model entry with only its immediate properties.
|
|
5
4
|
*
|
|
@@ -16,7 +15,7 @@ import { type PrismaModelName } from './prisma-model-name.js';
|
|
|
16
15
|
*
|
|
17
16
|
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
18
17
|
*/
|
|
19
|
-
export type PrismaBasicModel<
|
|
18
|
+
export type PrismaBasicModel<TypeMap extends BaseTypeMap, Model extends keyof TypeMap['model']> = TypeMap['model'][Model]['payload']['scalars'];
|
|
20
19
|
/**
|
|
21
20
|
* Basic model entries for all models in the database.
|
|
22
21
|
*
|
|
@@ -24,6 +23,6 @@ export type PrismaBasicModel<PrismaClient extends BasePrismaClient, Model extend
|
|
|
24
23
|
* @category Package : @augment-vir/common
|
|
25
24
|
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
26
25
|
*/
|
|
27
|
-
export type PrismaAllBasicModels<
|
|
28
|
-
[ModelName in
|
|
29
|
-
}
|
|
26
|
+
export type PrismaAllBasicModels<TypeMap extends BaseTypeMap> = {
|
|
27
|
+
[ModelName in keyof TypeMap['model']]: PrismaBasicModel<TypeMap, ModelName>;
|
|
28
|
+
};
|
|
@@ -1,37 +1,13 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import { type
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
* import {type FullPrismaModel} from '@augment-vir/common';
|
|
13
|
-
*
|
|
14
|
-
* function doThing(fullModel: FullModel<Prisma.TypeMap, 'User'>) {}
|
|
15
|
-
* ```
|
|
16
|
-
*
|
|
17
|
-
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
18
|
-
*/
|
|
19
|
-
export type PrismaFullModel<PrismaClient extends BasePrismaClient, Model extends PrismaModelName<PrismaClient>> = ExpandPrismaTypeMapPayload<PrismaClient[Model][symbol]['types']['payload']>;
|
|
20
|
-
/**
|
|
21
|
-
* Expand a Prisma payload into its scalars and recursive relations.
|
|
22
|
-
*
|
|
23
|
-
* @category Prisma : Common : Util
|
|
24
|
-
* @category Package : @augment-vir/common
|
|
25
|
-
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
26
|
-
*/
|
|
27
|
-
export type ExpandPrismaTypeMapPayload<Payload extends BasePrismaPayload> = Payload['scalars'] & {
|
|
28
|
-
[Key in keyof Payload['objects']]: ExpandPotentialArrayPrismaTypeMapPayload<NonNullable<Payload['objects'][Key]>> | (null extends Payload['objects'][Key] ? null : never);
|
|
1
|
+
import { type BaseTypeMap } from './base-prisma-types.js';
|
|
2
|
+
import { type PrismaBasicModel } from './prisma-basic-model.js';
|
|
3
|
+
export type PrismaFullModel<TypeMap extends BaseTypeMap, Model extends keyof TypeMap['model']> = PrismaBasicModel<TypeMap, Model> & ExpandObjects<TypeMap['model'][Model]['payload']['objects']>;
|
|
4
|
+
type ExpandObjects<Objects> = {
|
|
5
|
+
[K in keyof Objects]: Objects[K] extends (infer U)[] ? U extends {
|
|
6
|
+
scalars: any;
|
|
7
|
+
objects: any;
|
|
8
|
+
} ? Array<U['scalars'] & ExpandObjects<U['objects']>> : Objects[K] : Objects[K] extends {
|
|
9
|
+
scalars: any;
|
|
10
|
+
objects: any;
|
|
11
|
+
} ? Objects[K]['scalars'] & ExpandObjects<Objects[K]['objects']> : Objects[K];
|
|
29
12
|
};
|
|
30
|
-
|
|
31
|
-
* Expand a payload that might be inside of an array, keeping it inside of an array if it is.
|
|
32
|
-
*
|
|
33
|
-
* @category Prisma : Common : Util
|
|
34
|
-
* @category Package : @augment-vir/common
|
|
35
|
-
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
36
|
-
*/
|
|
37
|
-
export type ExpandPotentialArrayPrismaTypeMapPayload<PayloadWrapper extends BasePrismaPayload | BasePrismaPayload[]> = PayloadWrapper extends (infer ActualPayload extends BasePrismaPayload)[] ? ExpandPrismaTypeMapPayload<ActualPayload>[] : PayloadWrapper extends BasePrismaPayload ? ExpandPrismaTypeMapPayload<PayloadWrapper> : never;
|
|
13
|
+
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type FirstLetterLowercase } from '@augment-vir/core';
|
|
2
|
+
import { type BasePrismaClient, type BaseTypeMap } from './base-prisma-types.js';
|
|
2
3
|
import { type PrismaModelName } from './prisma-model-name.js';
|
|
3
4
|
/**
|
|
4
5
|
* Use this to define mock entries that _shouldn't_ be saved to the database so that we can easily
|
|
@@ -74,7 +75,7 @@ export declare const prismaModelCreateOmitId: unique symbol;
|
|
|
74
75
|
*
|
|
75
76
|
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
76
77
|
*/
|
|
77
|
-
export type PrismaModelCreate<PrismaClient extends BasePrismaClient, Model extends PrismaModelName<
|
|
78
|
+
export type PrismaModelCreate<PrismaClient extends BasePrismaClient, TypeMap extends BaseTypeMap, Model extends PrismaModelName<TypeMap>> = NonNullable<Parameters<PrismaClient[FirstLetterLowercase<Model>]['create']>[0]> extends {
|
|
78
79
|
data?: infer Data;
|
|
79
80
|
} ? NonNullable<Data> & Partial<{
|
|
80
81
|
[prismaModelCreateExclude]: true;
|
|
@@ -108,8 +109,8 @@ export type PrismaModelCreate<PrismaClient extends BasePrismaClient, Model exten
|
|
|
108
109
|
*
|
|
109
110
|
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
110
111
|
*/
|
|
111
|
-
export type PrismaKeyedModelCreate<PrismaClient extends BasePrismaClient, Model extends PrismaModelName<
|
|
112
|
-
[EntryName in string]: PrismaModelCreate<PrismaClient, Model>;
|
|
112
|
+
export type PrismaKeyedModelCreate<PrismaClient extends BasePrismaClient, TypeMap extends BaseTypeMap, Model extends PrismaModelName<TypeMap>> = {
|
|
113
|
+
[EntryName in string]: PrismaModelCreate<PrismaClient, TypeMap, Model>;
|
|
113
114
|
};
|
|
114
115
|
/**
|
|
115
116
|
* Model create data stored by model name in either array or keyed form. Used in
|
|
@@ -154,6 +155,6 @@ export type PrismaKeyedModelCreate<PrismaClient extends BasePrismaClient, Model
|
|
|
154
155
|
*
|
|
155
156
|
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
156
157
|
*/
|
|
157
|
-
export type PrismaAllModelsCreate<PrismaClient extends BasePrismaClient> = Readonly<Partial<{
|
|
158
|
-
[Model in PrismaModelName<
|
|
158
|
+
export type PrismaAllModelsCreate<PrismaClient extends BasePrismaClient, TypeMap extends BaseTypeMap> = Readonly<Partial<{
|
|
159
|
+
[Model in PrismaModelName<TypeMap>]: Readonly<PrismaKeyedModelCreate<PrismaClient, TypeMap, Model>> | ReadonlyArray<Readonly<PrismaModelCreate<PrismaClient, TypeMap, Model>>>;
|
|
159
160
|
}>>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type BaseTypeMap } from './base-prisma-types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Extracts all model names from a generated `PrismaClient`.
|
|
4
4
|
*
|
|
@@ -15,4 +15,4 @@ import { type BasePrismaClient } from './base-prisma-types.js';
|
|
|
15
15
|
*
|
|
16
16
|
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
17
17
|
*/
|
|
18
|
-
export type PrismaModelName<
|
|
18
|
+
export type PrismaModelName<TypeMap extends BaseTypeMap> = Extract<keyof TypeMap['model'], string>;
|
|
@@ -10,6 +10,7 @@ export declare function maybeCapitalize(input: string, casingOptions: Pick<Casin
|
|
|
10
10
|
/**
|
|
11
11
|
* Capitalize the first letter of the input.
|
|
12
12
|
*
|
|
13
|
+
* @deprecated Prefer `setFirstLetterCasing`.
|
|
13
14
|
* @category String
|
|
14
15
|
* @category Package : @augment-vir/common
|
|
15
16
|
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
@@ -6,11 +6,13 @@
|
|
|
6
6
|
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
7
7
|
*/
|
|
8
8
|
export function maybeCapitalize(input, casingOptions) {
|
|
9
|
+
// eslint-disable-next-line sonarjs/deprecation, @typescript-eslint/no-deprecated
|
|
9
10
|
return casingOptions.capitalizeFirstLetter ? capitalizeFirstLetter(input) : input;
|
|
10
11
|
}
|
|
11
12
|
/**
|
|
12
13
|
* Capitalize the first letter of the input.
|
|
13
14
|
*
|
|
15
|
+
* @deprecated Prefer `setFirstLetterCasing`.
|
|
14
16
|
* @category String
|
|
15
17
|
* @category Package : @augment-vir/common
|
|
16
18
|
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type PartialWithUndefined } from '@augment-vir/core';
|
|
1
|
+
import { type FirstLetterLowercase, type FirstLetterUppercase, type PartialWithUndefined } from '@augment-vir/core';
|
|
2
2
|
/**
|
|
3
3
|
* Options for casing functions in `@augment-vir/common`.
|
|
4
4
|
*
|
|
@@ -33,6 +33,22 @@ export declare enum StringCase {
|
|
|
33
33
|
Upper = "upper",
|
|
34
34
|
Lower = "lower"
|
|
35
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* Convert the first letter of a string to either lower or uppercase.
|
|
38
|
+
*
|
|
39
|
+
* @category String
|
|
40
|
+
* @category Package : @augment-vir/common
|
|
41
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
42
|
+
*/
|
|
43
|
+
export type FirstLetterCase<SpecificCase extends StringCase, Value extends string> = SpecificCase extends StringCase.Lower ? FirstLetterLowercase<Value> : FirstLetterUppercase<Value>;
|
|
44
|
+
/**
|
|
45
|
+
* Set the first letter of the input to uppercase or lowercase.
|
|
46
|
+
*
|
|
47
|
+
* @category String
|
|
48
|
+
* @category Package : @augment-vir/common
|
|
49
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
50
|
+
*/
|
|
51
|
+
export declare function setFirstLetterCasing<const SpecificCase extends StringCase, const Value extends string>(input: Value, stringCase: SpecificCase): FirstLetterCase<SpecificCase, Value>;
|
|
36
52
|
/**
|
|
37
53
|
* Indicates whether the given string has different lower and upper case variants. (Some strings
|
|
38
54
|
* don't, such as all numbers or `'√'`.)
|
|
@@ -20,6 +20,23 @@ export var StringCase;
|
|
|
20
20
|
StringCase["Upper"] = "upper";
|
|
21
21
|
StringCase["Lower"] = "lower";
|
|
22
22
|
})(StringCase || (StringCase = {}));
|
|
23
|
+
/**
|
|
24
|
+
* Set the first letter of the input to uppercase or lowercase.
|
|
25
|
+
*
|
|
26
|
+
* @category String
|
|
27
|
+
* @category Package : @augment-vir/common
|
|
28
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
29
|
+
*/
|
|
30
|
+
export function setFirstLetterCasing(input, stringCase) {
|
|
31
|
+
if (!input.length) {
|
|
32
|
+
return '';
|
|
33
|
+
}
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
35
|
+
const firstLetter = input[0];
|
|
36
|
+
return ((stringCase === StringCase.Upper
|
|
37
|
+
? firstLetter.toUpperCase()
|
|
38
|
+
: firstLetter.toLowerCase()) + input.slice(1));
|
|
39
|
+
}
|
|
23
40
|
/**
|
|
24
41
|
* Indicates whether the given string has different lower and upper case variants. (Some strings
|
|
25
42
|
* don't, such as all numbers or `'√'`.)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@augment-vir/common",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.29.0",
|
|
4
4
|
"description": "A collection of augments, helpers types, functions, and classes for any JavaScript environment.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"augment",
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"test:web": "virmator --no-deps test web"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@augment-vir/assert": "^31.
|
|
44
|
-
"@augment-vir/core": "^31.
|
|
43
|
+
"@augment-vir/assert": "^31.29.0",
|
|
44
|
+
"@augment-vir/core": "^31.29.0",
|
|
45
45
|
"@date-vir/duration": "^7.3.2",
|
|
46
46
|
"ansi-styles": "^6.2.1",
|
|
47
47
|
"deepcopy-esm": "^2.1.1",
|