@aneuhold/core-ts-db-lib 3.0.3 → 4.0.1

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.
Files changed (116) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/lib/browser.d.ts +25 -20
  3. package/lib/browser.d.ts.map +1 -1
  4. package/lib/browser.js +15 -15
  5. package/lib/browser.js.map +1 -1
  6. package/lib/browser.ts +97 -39
  7. package/lib/documents/BaseDocument.d.ts +22 -9
  8. package/lib/documents/BaseDocument.d.ts.map +1 -1
  9. package/lib/documents/BaseDocument.js +16 -7
  10. package/lib/documents/BaseDocument.js.map +1 -1
  11. package/lib/documents/BaseDocument.ts +27 -7
  12. package/lib/documents/common/ApiKey.d.ts +8 -25
  13. package/lib/documents/common/ApiKey.d.ts.map +1 -1
  14. package/lib/documents/common/ApiKey.js +7 -36
  15. package/lib/documents/common/ApiKey.js.map +1 -1
  16. package/lib/documents/common/ApiKey.ts +11 -41
  17. package/lib/documents/common/User.d.ts +25 -31
  18. package/lib/documents/common/User.d.ts.map +1 -1
  19. package/lib/documents/common/User.js +22 -39
  20. package/lib/documents/common/User.js.map +1 -1
  21. package/lib/documents/common/User.ts +29 -53
  22. package/lib/documents/dashboard/NonogramKatanaItem.d.ts +18 -27
  23. package/lib/documents/dashboard/NonogramKatanaItem.d.ts.map +1 -1
  24. package/lib/documents/dashboard/NonogramKatanaItem.js +17 -31
  25. package/lib/documents/dashboard/NonogramKatanaItem.js.map +1 -1
  26. package/lib/documents/dashboard/NonogramKatanaItem.ts +21 -45
  27. package/lib/documents/dashboard/NonogramKatanaUpgrade.d.ts +16 -41
  28. package/lib/documents/dashboard/NonogramKatanaUpgrade.d.ts.map +1 -1
  29. package/lib/documents/dashboard/NonogramKatanaUpgrade.js +16 -43
  30. package/lib/documents/dashboard/NonogramKatanaUpgrade.js.map +1 -1
  31. package/lib/documents/dashboard/NonogramKatanaUpgrade.ts +20 -55
  32. package/lib/documents/dashboard/Task.d.ts +73 -97
  33. package/lib/documents/dashboard/Task.d.ts.map +1 -1
  34. package/lib/documents/dashboard/Task.js +38 -80
  35. package/lib/documents/dashboard/Task.js.map +1 -1
  36. package/lib/documents/dashboard/Task.ts +71 -111
  37. package/lib/documents/dashboard/UserConfig.d.ts +49 -69
  38. package/lib/documents/dashboard/UserConfig.d.ts.map +1 -1
  39. package/lib/documents/dashboard/UserConfig.js +31 -51
  40. package/lib/documents/dashboard/UserConfig.js.map +1 -1
  41. package/lib/documents/dashboard/UserConfig.ts +41 -87
  42. package/lib/embedded-types/dashboard/nonogramKatanaItem/ItemName.d.ts +5 -0
  43. package/lib/embedded-types/dashboard/nonogramKatanaItem/ItemName.d.ts.map +1 -1
  44. package/lib/embedded-types/dashboard/nonogramKatanaItem/ItemName.js +5 -0
  45. package/lib/embedded-types/dashboard/nonogramKatanaItem/ItemName.js.map +1 -1
  46. package/lib/embedded-types/dashboard/nonogramKatanaItem/ItemName.ts +7 -0
  47. package/lib/embedded-types/dashboard/nonogramKatanaUpgrade/UpgradeName.d.ts +5 -0
  48. package/lib/embedded-types/dashboard/nonogramKatanaUpgrade/UpgradeName.d.ts.map +1 -1
  49. package/lib/embedded-types/dashboard/nonogramKatanaUpgrade/UpgradeName.js +5 -0
  50. package/lib/embedded-types/dashboard/nonogramKatanaUpgrade/UpgradeName.js.map +1 -1
  51. package/lib/embedded-types/dashboard/nonogramKatanaUpgrade/UpgradeName.ts +7 -0
  52. package/lib/embedded-types/dashboard/task/FilterSettings.d.ts +69 -41
  53. package/lib/embedded-types/dashboard/task/FilterSettings.d.ts.map +1 -1
  54. package/lib/embedded-types/dashboard/task/FilterSettings.js +29 -36
  55. package/lib/embedded-types/dashboard/task/FilterSettings.js.map +1 -1
  56. package/lib/embedded-types/dashboard/task/FilterSettings.ts +51 -74
  57. package/lib/embedded-types/dashboard/task/RecurrenceInfo.d.ts +74 -52
  58. package/lib/embedded-types/dashboard/task/RecurrenceInfo.d.ts.map +1 -1
  59. package/lib/embedded-types/dashboard/task/RecurrenceInfo.js +66 -28
  60. package/lib/embedded-types/dashboard/task/RecurrenceInfo.js.map +1 -1
  61. package/lib/embedded-types/dashboard/task/RecurrenceInfo.ts +83 -77
  62. package/lib/embedded-types/dashboard/task/SortSettings.d.ts +61 -42
  63. package/lib/embedded-types/dashboard/task/SortSettings.d.ts.map +1 -1
  64. package/lib/embedded-types/dashboard/task/SortSettings.js +34 -31
  65. package/lib/embedded-types/dashboard/task/SortSettings.js.map +1 -1
  66. package/lib/embedded-types/dashboard/task/SortSettings.ts +66 -61
  67. package/lib/embedded-types/dashboard/userConfig/Tags.d.ts +18 -11
  68. package/lib/embedded-types/dashboard/userConfig/Tags.d.ts.map +1 -1
  69. package/lib/embedded-types/dashboard/userConfig/Tags.js +15 -1
  70. package/lib/embedded-types/dashboard/userConfig/Tags.js.map +1 -1
  71. package/lib/embedded-types/dashboard/userConfig/Tags.ts +21 -9
  72. package/lib/schemas/required-refs/RequiredUserId.d.ts +9 -5
  73. package/lib/schemas/required-refs/RequiredUserId.d.ts.map +1 -1
  74. package/lib/schemas/required-refs/RequiredUserId.js +9 -4
  75. package/lib/schemas/required-refs/RequiredUserId.js.map +1 -1
  76. package/lib/schemas/required-refs/RequiredUserId.ts +13 -4
  77. package/lib/services/DocumentService.d.ts +1 -1
  78. package/lib/services/DocumentService.d.ts.map +1 -1
  79. package/lib/services/DocumentService.js +0 -1
  80. package/lib/services/DocumentService.js.map +1 -1
  81. package/lib/services/DocumentService.ts +1 -1
  82. package/lib/services/dashboard/Task/TaskRecurrenceService.d.ts +4 -4
  83. package/lib/services/dashboard/Task/TaskRecurrenceService.d.ts.map +1 -1
  84. package/lib/services/dashboard/Task/TaskRecurrenceService.js +3 -4
  85. package/lib/services/dashboard/Task/TaskRecurrenceService.js.map +1 -1
  86. package/lib/services/dashboard/Task/TaskRecurrenceService.ts +8 -5
  87. package/lib/services/dashboard/Task/TaskService.d.ts +1 -2
  88. package/lib/services/dashboard/Task/TaskService.d.ts.map +1 -1
  89. package/lib/services/dashboard/Task/TaskService.js +0 -1
  90. package/lib/services/dashboard/Task/TaskService.js.map +1 -1
  91. package/lib/services/dashboard/Task/TaskService.ts +1 -2
  92. package/lib/services/dashboard/Task/TaskSortService.d.ts.map +1 -1
  93. package/lib/services/dashboard/Task/TaskSortService.js +0 -1
  94. package/lib/services/dashboard/Task/TaskSortService.js.map +1 -1
  95. package/lib/services/dashboard/Task/TaskSortService.ts +1 -2
  96. package/package.json +9 -9
  97. package/lib/documents/BaseDocumentWithType.d.ts +0 -8
  98. package/lib/documents/BaseDocumentWithType.d.ts.map +0 -1
  99. package/lib/documents/BaseDocumentWithType.js +0 -7
  100. package/lib/documents/BaseDocumentWithType.js.map +0 -1
  101. package/lib/documents/BaseDocumentWithType.ts +0 -8
  102. package/lib/schemas/type-guards/commonTypeGuards.d.ts +0 -36
  103. package/lib/schemas/type-guards/commonTypeGuards.d.ts.map +0 -1
  104. package/lib/schemas/type-guards/commonTypeGuards.js +0 -46
  105. package/lib/schemas/type-guards/commonTypeGuards.js.map +0 -1
  106. package/lib/schemas/type-guards/commonTypeGuards.ts +0 -49
  107. package/lib/schemas/validators/DocumentValidator.d.ts +0 -9
  108. package/lib/schemas/validators/DocumentValidator.d.ts.map +0 -1
  109. package/lib/schemas/validators/DocumentValidator.js +0 -2
  110. package/lib/schemas/validators/DocumentValidator.js.map +0 -1
  111. package/lib/schemas/validators/DocumentValidator.ts +0 -9
  112. package/lib/schemas/validators/ValidateUtil.d.ts +0 -122
  113. package/lib/schemas/validators/ValidateUtil.d.ts.map +0 -1
  114. package/lib/schemas/validators/ValidateUtil.js +0 -216
  115. package/lib/schemas/validators/ValidateUtil.js.map +0 -1
  116. package/lib/schemas/validators/ValidateUtil.ts +0 -240
@@ -1,49 +1,19 @@
1
- import type { UUID } from 'crypto';
2
- import crypto from 'crypto';
3
- import RequiredUserId from '../../schemas/required-refs/RequiredUserId.js';
4
- import type { DocumentValidator } from '../../schemas/validators/DocumentValidator.js';
5
- import Validate from '../../schemas/validators/ValidateUtil.js';
6
- import DocumentService from '../../services/DocumentService.js';
7
- import BaseDocument from '../BaseDocument.js';
1
+ import { randomUUID } from 'crypto';
2
+ import { z } from 'zod';
3
+ import { RequiredUserIdSchema } from '../../schemas/required-refs/RequiredUserId.js';
8
4
 
9
5
  /**
10
- * Validates the provided {@link ApiKey} instance.
11
- *
12
- * @param apiKey - The {@link ApiKey} instance to validate.
13
- * @returns An object containing the updated document and any validation errors.
6
+ * The schema for {@link ApiKey} documents.
14
7
  */
15
- export const validateApiKey: DocumentValidator<ApiKey> = (apiKey: ApiKey) => {
16
- const errors: string[] = [];
17
- const exampleApiKey = new ApiKey(DocumentService.generateID());
18
- const validate = new Validate(apiKey, errors);
19
-
20
- validate.string('key', exampleApiKey.key);
21
-
22
- return { updatedDoc: apiKey, errors };
23
- };
8
+ export const ApiKeySchema = RequiredUserIdSchema.extend({
9
+ /**
10
+ * The API key for the user. This is indexed in the DB.
11
+ */
12
+ key: z.uuid().default(() => randomUUID())
13
+ });
24
14
 
25
15
  /**
26
16
  * A document containing an API key for a particular user. This is stored
27
17
  * separately from the {@link User} document to enhance security a bit.
28
18
  */
29
- export default class ApiKey extends BaseDocument implements RequiredUserId {
30
- /**
31
- * The API key for the user. This is indexed in the DB.
32
- */
33
- key: UUID = crypto.randomUUID();
34
-
35
- /**
36
- * The user ID that this key is for. This field is indexed in the database.
37
- */
38
- userId: UUID;
39
-
40
- /**
41
- * Constructs a new {@link ApiKey} for the provided user.
42
- *
43
- * @param userId - The ID of the user.
44
- */
45
- constructor(userId: UUID) {
46
- super();
47
- this.userId = userId;
48
- }
49
- }
19
+ export type ApiKey = z.infer<typeof ApiKeySchema>;
@@ -1,41 +1,35 @@
1
- import type { UUID } from 'crypto';
2
- import type { DocumentValidator } from '../../schemas/validators/DocumentValidator.js';
3
- import BaseDocument from '../BaseDocument.js';
1
+ import { z } from 'zod';
4
2
  /**
5
- * A User CTO which can be used to reference a User with only the necessary
6
- * information.
3
+ * The schema for {@link UserCTO} documents. This also acts a base for the {@link UserSchema}.
7
4
  */
8
- export type UserCTO = {
9
- _id: UUID;
10
- userName: string;
11
- };
5
+ export declare const UserCTOSchema: z.ZodObject<{
6
+ _id: z.ZodPipe<z.ZodDefault<z.ZodUUID>, z.ZodTransform<`${string}-${string}-${string}-${string}-${string}`, string>>;
7
+ userName: z.ZodString;
8
+ }, z.core.$strip>;
12
9
  /**
13
- * Validates a User document.
14
- *
15
- * @param user - The user document to validate.
16
- * @returns An object containing the updated user document and an array of error messages, if any.
10
+ * The schema for {@link User} documents.
17
11
  */
18
- export declare const validateUser: DocumentValidator<User>;
12
+ export declare const UserSchema: z.ZodObject<{
13
+ _id: z.ZodPipe<z.ZodDefault<z.ZodUUID>, z.ZodTransform<`${string}-${string}-${string}-${string}-${string}`, string>>;
14
+ userName: z.ZodString;
15
+ email: z.ZodOptional<z.ZodNullable<z.ZodEmail>>;
16
+ auth: z.ZodDefault<z.ZodObject<{
17
+ password: z.ZodOptional<z.ZodNullable<z.ZodString>>;
18
+ googleId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
19
+ }, z.core.$strip>>;
20
+ projectAccess: z.ZodDefault<z.ZodObject<{
21
+ dashboard: z.ZodDefault<z.ZodBoolean>;
22
+ }, z.core.$strip>>;
23
+ }, z.core.$strip>;
19
24
  /**
20
25
  * A standard user of all personal projects. This should be linked to from
21
26
  * other documents that need to reference a user, instead of cluttering the
22
27
  * key user information.
23
28
  */
24
- export default class User extends BaseDocument {
25
- userName: string;
26
- email?: string;
27
- auth: {
28
- password?: string;
29
- googleId?: string;
30
- };
31
- projectAccess: {
32
- dashboard: boolean;
33
- };
34
- /**
35
- * Constructs a new {@link User} with default values.
36
- *
37
- * @param userName - The username of the user.
38
- */
39
- constructor(userName: string);
40
- }
29
+ export type User = z.infer<typeof UserSchema>;
30
+ /**
31
+ * A User CTO which can be used to reference a User with only the necessary
32
+ * information.
33
+ */
34
+ export type UserCTO = z.infer<typeof UserCTOSchema>;
41
35
  //# sourceMappingURL=User.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"User.d.ts","sourceRoot":"","sources":["../../../src/documents/common/User.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+CAA+C,CAAC;AAEvF,OAAO,YAAY,MAAM,oBAAoB,CAAC;AAE9C;;;GAGG;AACH,MAAM,MAAM,OAAO,GAAG;IACpB,GAAG,EAAE,IAAI,CAAC;IACV,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,YAAY,EAAE,iBAAiB,CAAC,IAAI,CAehD,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,IAAK,SAAQ,YAAY;IAC5C,QAAQ,EAAE,MAAM,CAAC;IAEjB,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,IAAI,EAAE;QACJ,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,CAAM;IAEP,aAAa;;MAEX;IAEF;;;;OAIG;gBACS,QAAQ,EAAE,MAAM;CAI7B"}
1
+ {"version":3,"file":"User.d.ts","sourceRoot":"","sources":["../../../src/documents/common/User.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB;;GAEG;AACH,eAAO,MAAM,aAAa;;;iBAExB,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,UAAU;;;;;;;;;;;iBAerB,CAAC;AAEH;;;;GAIG;AACH,MAAM,MAAM,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,UAAU,CAAC,CAAC;AAE9C;;;GAGG;AACH,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC"}
@@ -1,45 +1,28 @@
1
- import Validate from '../../schemas/validators/ValidateUtil.js';
2
- import BaseDocument from '../BaseDocument.js';
1
+ import { z } from 'zod';
2
+ import { BaseDocumentSchema } from '../BaseDocument.js';
3
3
  /**
4
- * Validates a User document.
5
- *
6
- * @param user - The user document to validate.
7
- * @returns An object containing the updated user document and an array of error messages, if any.
4
+ * The schema for {@link UserCTO} documents. This also acts a base for the {@link UserSchema}.
8
5
  */
9
- export const validateUser = (user) => {
10
- const errors = [];
11
- const validate = new Validate(user, errors);
12
- const exampleUser = new User('example');
13
- validate.string('userName', 'UsernameUnknown');
14
- validate.optionalString('password');
15
- validate.optionalString('email');
16
- validate.object('auth', exampleUser.auth);
17
- validate.optionalString('auth.password');
18
- validate.optionalString('auth.googleId');
19
- validate.object('projectAccess', exampleUser.projectAccess);
20
- validate.boolean('projectAccess.dashboard', exampleUser.projectAccess.dashboard);
21
- return { updatedDoc: user, errors };
22
- };
6
+ export const UserCTOSchema = BaseDocumentSchema.extend({
7
+ userName: z.string()
8
+ });
23
9
  /**
24
- * A standard user of all personal projects. This should be linked to from
25
- * other documents that need to reference a user, instead of cluttering the
26
- * key user information.
10
+ * The schema for {@link User} documents.
27
11
  */
28
- export default class User extends BaseDocument {
29
- userName;
30
- email;
31
- auth = {};
32
- projectAccess = {
12
+ export const UserSchema = UserCTOSchema.extend({
13
+ email: z.email().nullish(),
14
+ auth: z
15
+ .object({
16
+ password: z.string().nullish(),
17
+ googleId: z.string().nullish()
18
+ })
19
+ .default({}),
20
+ projectAccess: z
21
+ .object({
22
+ dashboard: z.boolean().default(true)
23
+ })
24
+ .default({
33
25
  dashboard: true
34
- };
35
- /**
36
- * Constructs a new {@link User} with default values.
37
- *
38
- * @param userName - The username of the user.
39
- */
40
- constructor(userName) {
41
- super();
42
- this.userName = userName;
43
- }
44
- }
26
+ })
27
+ });
45
28
  //# sourceMappingURL=User.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"User.js","sourceRoot":"","sources":["../../../src/documents/common/User.ts"],"names":[],"mappings":"AAEA,OAAO,QAAQ,MAAM,0CAA0C,CAAC;AAChE,OAAO,YAAY,MAAM,oBAAoB,CAAC;AAW9C;;;;;GAKG;AACH,MAAM,CAAC,MAAM,YAAY,GAA4B,CAAC,IAAI,EAAE,EAAE;IAC5D,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,MAAM,QAAQ,GAAG,IAAI,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAC5C,MAAM,WAAW,GAAG,IAAI,IAAI,CAAC,SAAS,CAAC,CAAC;IAExC,QAAQ,CAAC,MAAM,CAAC,UAAU,EAAE,iBAAiB,CAAC,CAAC;IAC/C,QAAQ,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;IACpC,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;IACjC,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC;IAC1C,QAAQ,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC;IACzC,QAAQ,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC;IACzC,QAAQ,CAAC,MAAM,CAAC,eAAe,EAAE,WAAW,CAAC,aAAa,CAAC,CAAC;IAC5D,QAAQ,CAAC,OAAO,CAAC,yBAAyB,EAAE,WAAW,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;IAEjF,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;AACtC,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,IAAK,SAAQ,YAAY;IAC5C,QAAQ,CAAS;IAEjB,KAAK,CAAU;IAEf,IAAI,GAGA,EAAE,CAAC;IAEP,aAAa,GAAG;QACd,SAAS,EAAE,IAAI;KAChB,CAAC;IAEF;;;;OAIG;IACH,YAAY,QAAgB;QAC1B,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;CACF"}
1
+ {"version":3,"file":"User.js","sourceRoot":"","sources":["../../../src/documents/common/User.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAExD;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,kBAAkB,CAAC,MAAM,CAAC;IACrD,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;CACrB,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC;IAC7C,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,OAAO,EAAE;IAC1B,IAAI,EAAE,CAAC;SACJ,MAAM,CAAC;QACN,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE;QAC9B,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE;KAC/B,CAAC;SACD,OAAO,CAAC,EAAE,CAAC;IACd,aAAa,EAAE,CAAC;SACb,MAAM,CAAC;QACN,SAAS,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC;KACrC,CAAC;SACD,OAAO,CAAC;QACP,SAAS,EAAE,IAAI;KAChB,CAAC;CACL,CAAC,CAAC"}
@@ -1,66 +1,42 @@
1
- import type { UUID } from 'crypto';
2
- import type { DocumentValidator } from '../../schemas/validators/DocumentValidator.js';
3
- import Validate from '../../schemas/validators/ValidateUtil.js';
4
- import BaseDocument from '../BaseDocument.js';
1
+ import { z } from 'zod';
2
+ import { BaseDocumentSchema } from '../BaseDocument.js';
5
3
 
6
4
  /**
7
- * A User CTO which can be used to reference a User with only the necessary
8
- * information.
5
+ * The schema for {@link UserCTO} documents. This also acts a base for the {@link UserSchema}.
9
6
  */
10
- export type UserCTO = {
11
- _id: UUID;
12
- userName: string;
13
- };
7
+ export const UserCTOSchema = BaseDocumentSchema.extend({
8
+ userName: z.string()
9
+ });
14
10
 
15
11
  /**
16
- * Validates a User document.
17
- *
18
- * @param user - The user document to validate.
19
- * @returns An object containing the updated user document and an array of error messages, if any.
12
+ * The schema for {@link User} documents.
20
13
  */
21
- export const validateUser: DocumentValidator<User> = (user) => {
22
- const errors: string[] = [];
23
- const validate = new Validate(user, errors);
24
- const exampleUser = new User('example');
25
-
26
- validate.string('userName', 'UsernameUnknown');
27
- validate.optionalString('password');
28
- validate.optionalString('email');
29
- validate.object('auth', exampleUser.auth);
30
- validate.optionalString('auth.password');
31
- validate.optionalString('auth.googleId');
32
- validate.object('projectAccess', exampleUser.projectAccess);
33
- validate.boolean('projectAccess.dashboard', exampleUser.projectAccess.dashboard);
34
-
35
- return { updatedDoc: user, errors };
36
- };
14
+ export const UserSchema = UserCTOSchema.extend({
15
+ email: z.email().nullish(),
16
+ auth: z
17
+ .object({
18
+ password: z.string().nullish(),
19
+ googleId: z.string().nullish()
20
+ })
21
+ .default({}),
22
+ projectAccess: z
23
+ .object({
24
+ dashboard: z.boolean().default(true)
25
+ })
26
+ .default({
27
+ dashboard: true
28
+ })
29
+ });
37
30
 
38
31
  /**
39
32
  * A standard user of all personal projects. This should be linked to from
40
33
  * other documents that need to reference a user, instead of cluttering the
41
34
  * key user information.
42
35
  */
43
- export default class User extends BaseDocument {
44
- userName: string;
45
-
46
- email?: string;
47
-
48
- auth: {
49
- password?: string;
50
- googleId?: string;
51
- } = {};
36
+ export type User = z.infer<typeof UserSchema>;
52
37
 
53
- projectAccess = {
54
- dashboard: true
55
- };
56
-
57
- /**
58
- * Constructs a new {@link User} with default values.
59
- *
60
- * @param userName - The username of the user.
61
- */
62
- constructor(userName: string) {
63
- super();
64
- this.userName = userName;
65
- }
66
- }
38
+ /**
39
+ * A User CTO which can be used to reference a User with only the necessary
40
+ * information.
41
+ */
42
+ export type UserCTO = z.infer<typeof UserCTOSchema>;
@@ -1,34 +1,25 @@
1
- import type { UUID } from 'crypto';
1
+ import { z } from 'zod';
2
2
  import NonogramKatanaItemName from '../../embedded-types/dashboard/nonogramKatanaItem/ItemName.js';
3
- import RequiredUserId from '../../schemas/required-refs/RequiredUserId.js';
4
- import type { DocumentValidator } from '../../schemas/validators/DocumentValidator.js';
5
- import BaseDocumentWithType from '../BaseDocumentWithType.js';
6
3
  /**
7
- * Validates a {@link NonogramKatanaItem}.
8
- *
9
- * @param item - The {@link NonogramKatanaItem} to validate.
10
- * @returns An object containing the updated document and any validation errors.
4
+ * The docType value for NonogramKatanaItem documents.
11
5
  */
12
- export declare const validateNonogramKatanaItem: DocumentValidator<NonogramKatanaItem>;
6
+ export declare const NonogramKatanaItem_docType = "nonogramKatanaItem";
7
+ /**
8
+ * The schema for {@link NonogramKatanaItem} documents.
9
+ */
10
+ export declare const NonogramKatanaItemSchema: z.ZodObject<{
11
+ docType: z.ZodDefault<z.ZodLiteral<"nonogramKatanaItem">>;
12
+ itemName: z.ZodEnum<typeof NonogramKatanaItemName>;
13
+ currentAmount: z.ZodDefault<z.ZodInt>;
14
+ storageCap: z.ZodOptional<z.ZodNullable<z.ZodInt>>;
15
+ minDesired: z.ZodOptional<z.ZodNullable<z.ZodInt>>;
16
+ maxDesired: z.ZodOptional<z.ZodNullable<z.ZodInt>>;
17
+ priority: z.ZodDefault<z.ZodInt>;
18
+ _id: z.ZodPipe<z.ZodDefault<z.ZodUUID>, z.ZodTransform<`${string}-${string}-${string}-${string}-${string}`, string>>;
19
+ userId: z.ZodPipe<z.ZodUUID, z.ZodTransform<`${string}-${string}-${string}-${string}-${string}`, string>>;
20
+ }, z.core.$strip>;
13
21
  /**
14
22
  * An item in the Nonogram Katana game.
15
23
  */
16
- export default class NonogramKatanaItem extends BaseDocumentWithType implements RequiredUserId {
17
- static docType: string;
18
- docType: string;
19
- /**
20
- * The owner of this Nonogram Katana item.
21
- */
22
- userId: UUID;
23
- itemName: NonogramKatanaItemName;
24
- currentAmount: number;
25
- storageCap?: number;
26
- minDesired?: number;
27
- maxDesired?: number;
28
- /**
29
- * Priority, where the higher the number, the higher up the list it is.
30
- */
31
- priority: number;
32
- constructor(ownerId: UUID, itemName: NonogramKatanaItemName);
33
- }
24
+ export type NonogramKatanaItem = z.infer<typeof NonogramKatanaItemSchema>;
34
25
  //# sourceMappingURL=NonogramKatanaItem.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"NonogramKatanaItem.d.ts","sourceRoot":"","sources":["../../../src/documents/dashboard/NonogramKatanaItem.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,sBAAsB,MAAM,+DAA+D,CAAC;AACnG,OAAO,cAAc,MAAM,+CAA+C,CAAC;AAC3E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+CAA+C,CAAC;AACvF,OAAO,oBAAoB,MAAM,4BAA4B,CAAC;AAE9D;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,EAAE,iBAAiB,CAAC,kBAAkB,CAQ5E,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,kBAAmB,SAAQ,oBAAqB,YAAW,cAAc;IAC5F,MAAM,CAAC,OAAO,SAAwB;IAEtC,OAAO,SAA8B;IAErC;;OAEG;IACH,MAAM,EAAE,IAAI,CAAC;IAEb,QAAQ,EAAE,sBAAsB,CAAC;IAEjC,aAAa,EAAE,MAAM,CAAK;IAE1B,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAK;gBAET,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,sBAAsB;CAK5D"}
1
+ {"version":3,"file":"NonogramKatanaItem.d.ts","sourceRoot":"","sources":["../../../src/documents/dashboard/NonogramKatanaItem.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,sBAAsB,MAAM,+DAA+D,CAAC;AAInG;;GAEG;AACH,eAAO,MAAM,0BAA0B,uBAAuB,CAAC;AAE/D;;GAEG;AACH,eAAO,MAAM,wBAAwB;;;;;;;;;;iBAanC,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC"}
@@ -1,40 +1,26 @@
1
+ import { z } from 'zod';
1
2
  import NonogramKatanaItemName from '../../embedded-types/dashboard/nonogramKatanaItem/ItemName.js';
2
- import RequiredUserId from '../../schemas/required-refs/RequiredUserId.js';
3
- import BaseDocumentWithType from '../BaseDocumentWithType.js';
3
+ import { RequiredUserIdSchema } from '../../schemas/required-refs/RequiredUserId.js';
4
+ import { BaseDocumentWithTypeSchema } from '../BaseDocument.js';
4
5
  /**
5
- * Validates a {@link NonogramKatanaItem}.
6
- *
7
- * @param item - The {@link NonogramKatanaItem} to validate.
8
- * @returns An object containing the updated document and any validation errors.
6
+ * The docType value for NonogramKatanaItem documents.
9
7
  */
10
- export const validateNonogramKatanaItem = (item) => {
11
- const errors = [];
12
- // No validation at the moment.
13
- return { updatedDoc: item, errors };
14
- };
8
+ export const NonogramKatanaItem_docType = 'nonogramKatanaItem';
15
9
  /**
16
- * An item in the Nonogram Katana game.
10
+ * The schema for {@link NonogramKatanaItem} documents.
17
11
  */
18
- export default class NonogramKatanaItem extends BaseDocumentWithType {
19
- static docType = 'nonogramKatanaItem';
20
- docType = NonogramKatanaItem.docType;
21
- /**
22
- * The owner of this Nonogram Katana item.
23
- */
24
- userId;
25
- itemName;
26
- currentAmount = 0;
27
- storageCap;
28
- minDesired;
29
- maxDesired;
12
+ export const NonogramKatanaItemSchema = z.object({
13
+ ...BaseDocumentWithTypeSchema.shape,
14
+ ...RequiredUserIdSchema.shape,
15
+ docType: z.literal(NonogramKatanaItem_docType).default(NonogramKatanaItem_docType),
16
+ itemName: z.enum(NonogramKatanaItemName),
17
+ currentAmount: z.int().default(0),
18
+ storageCap: z.int().nullish(),
19
+ minDesired: z.int().nullish(),
20
+ maxDesired: z.int().nullish(),
30
21
  /**
31
22
  * Priority, where the higher the number, the higher up the list it is.
32
23
  */
33
- priority = 0;
34
- constructor(ownerId, itemName) {
35
- super();
36
- this.userId = ownerId;
37
- this.itemName = itemName;
38
- }
39
- }
24
+ priority: z.int().default(0)
25
+ });
40
26
  //# sourceMappingURL=NonogramKatanaItem.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"NonogramKatanaItem.js","sourceRoot":"","sources":["../../../src/documents/dashboard/NonogramKatanaItem.ts"],"names":[],"mappings":"AACA,OAAO,sBAAsB,MAAM,+DAA+D,CAAC;AACnG,OAAO,cAAc,MAAM,+CAA+C,CAAC;AAE3E,OAAO,oBAAoB,MAAM,4BAA4B,CAAC;AAE9D;;;;;GAKG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAA0C,CAC/E,IAAwB,EACxB,EAAE;IACF,MAAM,MAAM,GAAa,EAAE,CAAC;IAE5B,+BAA+B;IAE/B,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;AACtC,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,kBAAmB,SAAQ,oBAAoB;IAClE,MAAM,CAAC,OAAO,GAAG,oBAAoB,CAAC;IAEtC,OAAO,GAAG,kBAAkB,CAAC,OAAO,CAAC;IAErC;;OAEG;IACH,MAAM,CAAO;IAEb,QAAQ,CAAyB;IAEjC,aAAa,GAAW,CAAC,CAAC;IAE1B,UAAU,CAAU;IAEpB,UAAU,CAAU;IAEpB,UAAU,CAAU;IAEpB;;OAEG;IACH,QAAQ,GAAW,CAAC,CAAC;IAErB,YAAY,OAAa,EAAE,QAAgC;QACzD,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC;QACtB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC"}
1
+ {"version":3,"file":"NonogramKatanaItem.js","sourceRoot":"","sources":["../../../src/documents/dashboard/NonogramKatanaItem.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,sBAAsB,MAAM,+DAA+D,CAAC;AACnG,OAAO,EAAE,oBAAoB,EAAE,MAAM,+CAA+C,CAAC;AACrF,OAAO,EAAE,0BAA0B,EAAE,MAAM,oBAAoB,CAAC;AAEhE;;GAEG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,oBAAoB,CAAC;AAE/D;;GAEG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/C,GAAG,0BAA0B,CAAC,KAAK;IACnC,GAAG,oBAAoB,CAAC,KAAK;IAC7B,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,0BAA0B,CAAC,CAAC,OAAO,CAAC,0BAA0B,CAAC;IAClF,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,sBAAsB,CAAC;IACxC,aAAa,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IACjC,UAAU,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE;IAC7B,UAAU,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE;IAC7B,UAAU,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE;IAC7B;;OAEG;IACH,QAAQ,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;CAC7B,CAAC,CAAC"}
@@ -1,56 +1,32 @@
1
- import type { UUID } from 'crypto';
1
+ import { z } from 'zod';
2
2
  import NonogramKatanaItemName from '../../embedded-types/dashboard/nonogramKatanaItem/ItemName.js';
3
- import RequiredUserId from '../../schemas/required-refs/RequiredUserId.js';
4
- import type { DocumentValidator } from '../../schemas/validators/DocumentValidator.js';
5
- import BaseDocumentWithType from '../BaseDocumentWithType.js';
3
+ import { RequiredUserIdSchema } from '../../schemas/required-refs/RequiredUserId.js';
4
+ import { BaseDocumentWithTypeSchema } from '../BaseDocument.js';
6
5
 
7
6
  /**
8
- * Validates a {@link NonogramKatanaItem}.
9
- *
10
- * @param item - The {@link NonogramKatanaItem} to validate.
11
- * @returns An object containing the updated document and any validation errors.
7
+ * The docType value for NonogramKatanaItem documents.
12
8
  */
13
- export const validateNonogramKatanaItem: DocumentValidator<NonogramKatanaItem> = (
14
- item: NonogramKatanaItem
15
- ) => {
16
- const errors: string[] = [];
17
-
18
- // No validation at the moment.
19
-
20
- return { updatedDoc: item, errors };
21
- };
9
+ export const NonogramKatanaItem_docType = 'nonogramKatanaItem';
22
10
 
23
11
  /**
24
- * An item in the Nonogram Katana game.
12
+ * The schema for {@link NonogramKatanaItem} documents.
25
13
  */
26
- export default class NonogramKatanaItem extends BaseDocumentWithType implements RequiredUserId {
27
- static docType = 'nonogramKatanaItem';
28
-
29
- docType = NonogramKatanaItem.docType;
30
-
31
- /**
32
- * The owner of this Nonogram Katana item.
33
- */
34
- userId: UUID;
35
-
36
- itemName: NonogramKatanaItemName;
37
-
38
- currentAmount: number = 0;
39
-
40
- storageCap?: number;
41
-
42
- minDesired?: number;
43
-
44
- maxDesired?: number;
45
-
14
+ export const NonogramKatanaItemSchema = z.object({
15
+ ...BaseDocumentWithTypeSchema.shape,
16
+ ...RequiredUserIdSchema.shape,
17
+ docType: z.literal(NonogramKatanaItem_docType).default(NonogramKatanaItem_docType),
18
+ itemName: z.enum(NonogramKatanaItemName),
19
+ currentAmount: z.int().default(0),
20
+ storageCap: z.int().nullish(),
21
+ minDesired: z.int().nullish(),
22
+ maxDesired: z.int().nullish(),
46
23
  /**
47
24
  * Priority, where the higher the number, the higher up the list it is.
48
25
  */
49
- priority: number = 0;
26
+ priority: z.int().default(0)
27
+ });
50
28
 
51
- constructor(ownerId: UUID, itemName: NonogramKatanaItemName) {
52
- super();
53
- this.userId = ownerId;
54
- this.itemName = itemName;
55
- }
56
- }
29
+ /**
30
+ * An item in the Nonogram Katana game.
31
+ */
32
+ export type NonogramKatanaItem = z.infer<typeof NonogramKatanaItemSchema>;
@@ -1,48 +1,23 @@
1
- import type { UUID } from 'crypto';
2
- import NonogramKatanaItemName from '../../embedded-types/dashboard/nonogramKatanaItem/ItemName.js';
1
+ import { z } from 'zod';
3
2
  import NonogramKatanaUpgradeName from '../../embedded-types/dashboard/nonogramKatanaUpgrade/UpgradeName.js';
4
- import RequiredUserId from '../../schemas/required-refs/RequiredUserId.js';
5
- import type { DocumentValidator } from '../../schemas/validators/DocumentValidator.js';
6
- import BaseDocumentWithType from '../BaseDocumentWithType.js';
7
3
  /**
8
- * Validates a {@link NonogramKatanaUpgrade} document.
9
- *
10
- * @param upgrade The {@link NonogramKatanaUpgrade} document to validate.
11
- * @returns An object containing the updated document and any validation errors.
4
+ * The docType value for NonogramKatanaUpgrade documents.
12
5
  */
13
- export declare const validateNonogramKatanaUpgrade: DocumentValidator<NonogramKatanaUpgrade>;
6
+ export declare const NonogramKatanaUpgrade_docType = "nonogramKatanaUpgrade";
7
+ /**
8
+ * The schema for {@link NonogramKatanaUpgrade} documents.
9
+ */
10
+ export declare const NonogramKatanaUpgradeSchema: z.ZodObject<{
11
+ docType: z.ZodDefault<z.ZodLiteral<"nonogramKatanaUpgrade">>;
12
+ upgradeName: z.ZodEnum<typeof NonogramKatanaUpgradeName>;
13
+ completed: z.ZodDefault<z.ZodBoolean>;
14
+ currentItemAmounts: z.ZodDefault<z.ZodRecord<z.ZodEnum<typeof import("../../embedded-types/dashboard/nonogramKatanaItem/ItemName.js").default> & z.core.$partial, z.ZodOptional<z.ZodNullable<z.ZodInt>>>>;
15
+ priority: z.ZodDefault<z.ZodInt>;
16
+ _id: z.ZodPipe<z.ZodDefault<z.ZodUUID>, z.ZodTransform<`${string}-${string}-${string}-${string}-${string}`, string>>;
17
+ userId: z.ZodPipe<z.ZodUUID, z.ZodTransform<`${string}-${string}-${string}-${string}-${string}`, string>>;
18
+ }, z.core.$strip>;
14
19
  /**
15
20
  * Represents an upgrade for a Nonogram Katana.
16
- *
17
- * @example
18
- * ```typescript
19
- * const upgrade = new NonogramKatanaUpgrade(ownerId, upgradeName);
20
- * upgrade.completed = true;
21
- * upgrade.priority = 5;
22
- * ```
23
21
  */
24
- export default class NonogramKatanaUpgrade extends BaseDocumentWithType implements RequiredUserId {
25
- static docType: string;
26
- docType: string;
27
- /**
28
- * The owner of this Nonogram Katana upgrade.
29
- */
30
- userId: UUID;
31
- upgradeName: NonogramKatanaUpgradeName;
32
- completed: boolean;
33
- currentItemAmounts: {
34
- [key in NonogramKatanaItemName]?: number;
35
- };
36
- /**
37
- * Priority, where the higher the number, the higher up the list it is.
38
- */
39
- priority: number;
40
- /**
41
- * Creates an instance of NonogramKatanaUpgrade.
42
- *
43
- * @param ownerId - The ID of the owner of this upgrade.
44
- * @param upgradeName - The name of the upgrade.
45
- */
46
- constructor(ownerId: UUID, upgradeName: NonogramKatanaUpgradeName);
47
- }
22
+ export type NonogramKatanaUpgrade = z.infer<typeof NonogramKatanaUpgradeSchema>;
48
23
  //# sourceMappingURL=NonogramKatanaUpgrade.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"NonogramKatanaUpgrade.d.ts","sourceRoot":"","sources":["../../../src/documents/dashboard/NonogramKatanaUpgrade.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,sBAAsB,MAAM,+DAA+D,CAAC;AACnG,OAAO,yBAAyB,MAAM,qEAAqE,CAAC;AAC5G,OAAO,cAAc,MAAM,+CAA+C,CAAC;AAC3E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+CAA+C,CAAC;AACvF,OAAO,oBAAoB,MAAM,4BAA4B,CAAC;AAE9D;;;;;GAKG;AACH,eAAO,MAAM,6BAA6B,EAAE,iBAAiB,CAAC,qBAAqB,CAQlF,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,CAAC,OAAO,OAAO,qBAAsB,SAAQ,oBAAqB,YAAW,cAAc;IAC/F,MAAM,CAAC,OAAO,SAA2B;IAEzC,OAAO,SAAiC;IAExC;;OAEG;IACH,MAAM,EAAE,IAAI,CAAC;IAEb,WAAW,EAAE,yBAAyB,CAAC;IAEvC,SAAS,EAAE,OAAO,CAAS;IAE3B,kBAAkB,EAAE;SAAG,GAAG,IAAI,sBAAsB,CAAC,CAAC,EAAE,MAAM;KAAE,CAAM;IAEtE;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAK;IAErB;;;;;OAKG;gBACS,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,yBAAyB;CAKlE"}
1
+ {"version":3,"file":"NonogramKatanaUpgrade.d.ts","sourceRoot":"","sources":["../../../src/documents/dashboard/NonogramKatanaUpgrade.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,yBAAyB,MAAM,qEAAqE,CAAC;AAI5G;;GAEG;AACH,eAAO,MAAM,6BAA6B,0BAA0B,CAAC;AAErE;;GAEG;AACH,eAAO,MAAM,2BAA2B;;;;;;;;iBAWtC,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,CAAC"}