Skip to content

Commit b2b306d

Browse files
Merge pull request #130 from brandongregoryscott/feature/default-values-factory
Immutable record default values utilities
2 parents b67e7e7 + 979581e commit b2b306d

17 files changed

Lines changed: 399 additions & 150 deletions

package-lock.json

Lines changed: 16 additions & 66 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@
1212
},
1313
"description": "Common patterns, functions, etc... used when building react applications",
1414
"devDependencies": {
15-
"@types/faker": "4.1.12",
15+
"@types/faker": "5.5.6",
1616
"@types/humanize-plus": "1.8.0",
1717
"@types/jest": "25.1.5",
1818
"@types/lodash": "4.14.108",
1919
"@types/node": "13.11.0",
20-
"@types/rosie": "0.0.37",
21-
"andculturecode-javascript-testing": "0.0.1",
20+
"@types/rosie": "0.0.39",
21+
"andculturecode-javascript-testing": "0.2.1",
2222
"axios": "0.21.1",
2323
"cross-env": "6.0.3",
2424
"cypress": "3.8.3",
25-
"faker": "4.1.0",
25+
"faker": "5.5.3",
2626
"humanize-plus": "1.8.2",
2727
"i18next": "19.4.5",
2828
"i18next-browser-languagedetector": "6.0.1",
@@ -32,7 +32,7 @@
3232
"lodash": "4.17.21",
3333
"prettier": "1.19.1",
3434
"rimraf": "2.6.2",
35-
"rosie": "2.0.1",
35+
"rosie": "2.1.0",
3636
"ts-jest": "25.5.1",
3737
"ts-loader": "8.0.4",
3838
"tslint": "6.1.2",
@@ -72,7 +72,7 @@
7272
"url": "git+https://github.com/AndcultureCode/AndcultureCode.JavaScript.Core.git"
7373
},
7474
"scripts": {
75-
"build": "tsc --pretty && webpack && npm run validate-peer-dependencies",
75+
"build": "tsc --pretty --project tsconfig.dist.json && webpack && npm run validate-peer-dependencies",
7676
"clean": "rimraf dist && rimraf coverage",
7777
"configure:git": "echo Ensuring git hooksPath is set to .githooks directory && git config core.hooksPath .githooks && chmod +x .githooks/*",
7878
"coverage": "jest ./src --coverage",
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { Auditable } from "../interfaces/auditable";
2+
3+
// -----------------------------------------------------------------------------------------
4+
// #region Constants
5+
// -----------------------------------------------------------------------------------------
6+
7+
const AuditableDefaultValues: Auditable = {
8+
createdById: undefined,
9+
createdOn: undefined,
10+
deletedById: undefined,
11+
deletedOn: undefined,
12+
id: undefined,
13+
updatedById: undefined,
14+
updatedOn: undefined,
15+
};
16+
17+
// #endregion Constants
18+
19+
// -----------------------------------------------------------------------------------------
20+
// #region Exports
21+
// -----------------------------------------------------------------------------------------
22+
23+
export { AuditableDefaultValues };
24+
25+
// #endregion Exports

src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// #region Constants
33
// -----------------------------------------------------------------------------------------
44

5+
export { AuditableDefaultValues } from "./constants/auditable-default-values";
56
export { EmailConstants } from "./constants/email-constants";
67
export { Rfc4646LanguageCodes } from "./constants/rfc4646-language-codes";
78
export { VideoResolutions } from "./constants/video-resolutions";
@@ -63,7 +64,10 @@ export { CancellablePromise } from "./types/cancellable-promise";
6364
export { CatchResultHandler } from "./types/catch-result-handler";
6465
export { Constructor } from "./types/constructor";
6566
export { FinallyHandler } from "./types/finally-handler";
67+
export { OmitKeys } from "./types/omit-keys";
6668
export { SyncWorkload } from "./types/sync-workload";
69+
export { RequiredOr } from "./types/required-or";
70+
export { RequiredOrUndefined } from "./types/required-or-undefined";
6771
export { TimerFunctionReturn } from "./types/timer-function-return";
6872

6973
// #endregion Types

src/tests/factories/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
export { AxiosResponseFactory } from "andculturecode-javascript-testing";
1+
export {
2+
AxiosResponseFactory,
3+
StubResourceRecordFactory,
4+
} from "andculturecode-javascript-testing";
25
export * from "./result-error-record-factory";
36
export * from "./result-record-factory";
4-
export * from "./stub-resource-record-factory";

src/tests/factories/stub-resource-record-factory.ts

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/tests/stubs/stub-resource-record.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
// -----------------------------------------------------------------------------------------
2-
// #region Interfaces
2+
// #region Types
33
// -----------------------------------------------------------------------------------------
44

5-
interface StubResource {
6-
id: number;
7-
name?: string;
8-
}
5+
/**
6+
* Omit all keys from `TSource` that intersect with `TExclusion`
7+
*/
8+
type OmitKeys<TSource, TExclusion> = Omit<TSource, keyof TExclusion>;
99

10-
// #endregion Interfaces
10+
// #endregion Types
1111

1212
// -----------------------------------------------------------------------------------------
13-
// #region Export
13+
// #region Exports
1414
// -----------------------------------------------------------------------------------------
1515

16-
export { StubResource };
16+
export { OmitKeys };
1717

18-
// #endregion Export
18+
// #endregion Exports

src/types/required-or-undefined.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { RequiredOr } from "./required-or";
2+
3+
// -----------------------------------------------------------------------------------------
4+
// #region Types
5+
// -----------------------------------------------------------------------------------------
6+
7+
/**
8+
* Mark all properties of `T` as required or explicitly set as undefined
9+
*/
10+
type RequiredOrUndefined<T> = RequiredOr<T, undefined>;
11+
12+
// #endregion Types
13+
14+
// -----------------------------------------------------------------------------------------
15+
// #region Exports
16+
// -----------------------------------------------------------------------------------------
17+
18+
export { RequiredOrUndefined };
19+
20+
// #endregion Exports

src/types/required-or.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// -----------------------------------------------------------------------------------------
2+
// #region Types
3+
// -----------------------------------------------------------------------------------------
4+
5+
/**
6+
* Mark all properties of `T` as required from the original type _or_ another type
7+
*/
8+
type RequiredOr<T, TOrType> = {
9+
[Property in keyof Required<T>]: T[Property] | TOrType;
10+
};
11+
12+
// #endregion Types
13+
14+
// -----------------------------------------------------------------------------------------
15+
// #region Exports
16+
// -----------------------------------------------------------------------------------------
17+
18+
export { RequiredOr };
19+
20+
// #endregion Exports

0 commit comments

Comments
 (0)