@api-client/core 0.18.38 → 0.18.39

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 (54) hide show
  1. package/build/src/browser.d.ts +1 -1
  2. package/build/src/browser.d.ts.map +1 -1
  3. package/build/src/browser.js.map +1 -1
  4. package/build/src/mocking/ModelingMock.d.ts +19 -0
  5. package/build/src/mocking/ModelingMock.d.ts.map +1 -0
  6. package/build/src/mocking/ModelingMock.js +19 -0
  7. package/build/src/mocking/ModelingMock.js.map +1 -0
  8. package/build/src/mocking/ProjectMock.js +1 -1
  9. package/build/src/mocking/ProjectMock.js.map +1 -1
  10. package/build/src/mocking/lib/File.d.ts +34 -0
  11. package/build/src/mocking/lib/File.d.ts.map +1 -0
  12. package/build/src/mocking/lib/File.js +64 -0
  13. package/build/src/mocking/lib/File.js.map +1 -0
  14. package/build/src/mocking/lib/Group.d.ts +16 -0
  15. package/build/src/mocking/lib/Group.d.ts.map +1 -0
  16. package/build/src/mocking/lib/Group.js +39 -0
  17. package/build/src/mocking/lib/Group.js.map +1 -0
  18. package/build/src/mocking/lib/Invitation.d.ts +16 -0
  19. package/build/src/mocking/lib/Invitation.d.ts.map +1 -0
  20. package/build/src/mocking/lib/Invitation.js +42 -0
  21. package/build/src/mocking/lib/Invitation.js.map +1 -0
  22. package/build/src/mocking/lib/Organization.d.ts +16 -0
  23. package/build/src/mocking/lib/Organization.d.ts.map +1 -0
  24. package/build/src/mocking/lib/Organization.js +34 -0
  25. package/build/src/mocking/lib/Organization.js.map +1 -0
  26. package/build/src/mocking/lib/Patch.d.ts +29 -0
  27. package/build/src/mocking/lib/Patch.d.ts.map +1 -0
  28. package/build/src/mocking/lib/Patch.js +102 -0
  29. package/build/src/mocking/lib/Patch.js.map +1 -0
  30. package/build/src/mocking/lib/Trash.d.ts +16 -0
  31. package/build/src/mocking/lib/Trash.d.ts.map +1 -0
  32. package/build/src/mocking/lib/Trash.js +39 -0
  33. package/build/src/mocking/lib/Trash.js.map +1 -0
  34. package/build/src/mocking/lib/User.d.ts +12 -12
  35. package/build/src/mocking/lib/User.d.ts.map +1 -1
  36. package/build/src/mocking/lib/User.js +29 -26
  37. package/build/src/mocking/lib/User.js.map +1 -1
  38. package/build/src/sdk/SdkMock.d.ts +125 -156
  39. package/build/src/sdk/SdkMock.d.ts.map +1 -1
  40. package/build/src/sdk/SdkMock.js +774 -596
  41. package/build/src/sdk/SdkMock.js.map +1 -1
  42. package/build/tsconfig.tsbuildinfo +1 -1
  43. package/data/models/example-generator-api.json +9 -9
  44. package/package.json +5 -3
  45. package/src/mocking/ModelingMock.ts +19 -0
  46. package/src/mocking/ProjectMock.ts +1 -1
  47. package/src/mocking/lib/File.ts +72 -0
  48. package/src/mocking/lib/Group.ts +52 -0
  49. package/src/mocking/lib/Invitation.ts +58 -0
  50. package/src/mocking/lib/Organization.ts +42 -0
  51. package/src/mocking/lib/Patch.ts +128 -0
  52. package/src/mocking/lib/Trash.ts +47 -0
  53. package/src/mocking/lib/User.ts +30 -29
  54. package/src/sdk/SdkMock.ts +966 -650
@@ -42813,13 +42813,13 @@
42813
42813
  "@id": "#210"
42814
42814
  },
42815
42815
  {
42816
- "@id": "#213"
42816
+ "@id": "#219"
42817
42817
  },
42818
42818
  {
42819
- "@id": "#216"
42819
+ "@id": "#213"
42820
42820
  },
42821
42821
  {
42822
- "@id": "#219"
42822
+ "@id": "#216"
42823
42823
  }
42824
42824
  ],
42825
42825
  "doc:root": false,
@@ -44253,7 +44253,7 @@
44253
44253
  "doc:ExternalDomainElement",
44254
44254
  "doc:DomainElement"
44255
44255
  ],
44256
- "doc:raw": "type: 'GENERAL'\ncountryDialCode : '+32'\nareaCode : '21'\nsubscriberNumber: '12.87.00'\nformatted: '+32-(0)21 302099'\n",
44256
+ "doc:raw": "-\n type: 'GENERAL'\n value: 'info@company.be'\n-\n type: 'IT_DEPT'\n value: 'it-service@company.be'\n",
44257
44257
  "core:mediaType": "application/yaml",
44258
44258
  "sourcemaps:sources": [
44259
44259
  {
@@ -44274,7 +44274,7 @@
44274
44274
  "doc:ExternalDomainElement",
44275
44275
  "doc:DomainElement"
44276
44276
  ],
44277
- "doc:raw": "-\n type: 'GENERAL'\n value: 'info@company.be'\n-\n type: 'IT_DEPT'\n value: 'it-service@company.be'\n",
44277
+ "doc:raw": "type: \"GENERAL\"\nvalue: \"www.company.be\"\n",
44278
44278
  "core:mediaType": "application/yaml",
44279
44279
  "sourcemaps:sources": [
44280
44280
  {
@@ -44295,7 +44295,7 @@
44295
44295
  "doc:ExternalDomainElement",
44296
44296
  "doc:DomainElement"
44297
44297
  ],
44298
- "doc:raw": "type: \"GENERAL\"\nvalue: \"www.company.be\"\n",
44298
+ "doc:raw": "type: 'GENERAL'\ncountryDialCode : '+32'\nareaCode : '21'\nsubscriberNumber: '12.87.00'\nformatted: '+32-(0)21 302099'\n",
44299
44299
  "core:mediaType": "application/yaml",
44300
44300
  "sourcemaps:sources": [
44301
44301
  {
@@ -45121,17 +45121,17 @@
45121
45121
  {
45122
45122
  "@id": "#215/source-map/lexical/element_0",
45123
45123
  "sourcemaps:element": "amf://id#215",
45124
- "sourcemaps:value": "[(1,0)-(6,0)]"
45124
+ "sourcemaps:value": "[(1,0)-(7,0)]"
45125
45125
  },
45126
45126
  {
45127
45127
  "@id": "#218/source-map/lexical/element_0",
45128
45128
  "sourcemaps:element": "amf://id#218",
45129
- "sourcemaps:value": "[(1,0)-(7,0)]"
45129
+ "sourcemaps:value": "[(1,0)-(3,0)]"
45130
45130
  },
45131
45131
  {
45132
45132
  "@id": "#221/source-map/lexical/element_0",
45133
45133
  "sourcemaps:element": "amf://id#221",
45134
- "sourcemaps:value": "[(1,0)-(3,0)]"
45134
+ "sourcemaps:value": "[(1,0)-(6,0)]"
45135
45135
  },
45136
45136
  {
45137
45137
  "@id": "#338/source-map/synthesized-field/element_1",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@api-client/core",
3
3
  "description": "The API Client's core client library. Works in NodeJS and in a ES enabled browser.",
4
- "version": "0.18.38",
4
+ "version": "0.18.39",
5
5
  "license": "Apache-2.0",
6
6
  "exports": {
7
7
  "./browser.js": {
@@ -87,12 +87,13 @@
87
87
  "@api-client/graph": "^0.3.5",
88
88
  "@api-client/json": "^0.2.0",
89
89
  "@esm-bundle/chai": "^4.3.4-fix.0",
90
+ "@faker-js/faker": "^10.1.0",
91
+ "@jarrodek/amw": "^0.1.1",
90
92
  "@jarrodek/pluralize": "^1.0.2",
91
93
  "@metrichor/jmespath": "^0.3.1",
92
94
  "@pawel-up/csv": "^0.2.0",
93
95
  "@pawel-up/data-mock": "^0.4.0",
94
96
  "@pawel-up/jexl": "^4.0.1",
95
- "@types/sinon": "^21.0.0",
96
97
  "@xmldom/xmldom": "^0.8.11",
97
98
  "amf-json-ld-lib": "^0.0.15",
98
99
  "chalk": "^5.4.1",
@@ -100,7 +101,6 @@
100
101
  "dompurify": "^3.2.6",
101
102
  "jsdom": "^27.0.0",
102
103
  "nanoid": "^5.1.5",
103
- "sinon": "^21.0.0",
104
104
  "tslog": "^4.9.3",
105
105
  "ws": "^8.12.0",
106
106
  "xpath": "^0.0.34"
@@ -123,6 +123,7 @@
123
123
  "@types/json-schema": "^7.0.15",
124
124
  "@types/mocha": "^10.0.10",
125
125
  "@types/node": "^24.0.1",
126
+ "@types/sinon": "^21.0.0",
126
127
  "@web/dev-server": "^0.4.6",
127
128
  "@web/dev-server-rollup": "^0.6.4",
128
129
  "@web/test-runner": "^0.20.0",
@@ -145,6 +146,7 @@
145
146
  "oauth2-mock-server": "^8.0.0",
146
147
  "prettier": "^3.5.1",
147
148
  "schema-org-json-schemas": "^2.1.4",
149
+ "sinon": "^21.0.0",
148
150
  "ts-lit-plugin": "^2.0.2",
149
151
  "ts-node-maintained": "^10.9.5",
150
152
  "typescript": "^5.5.2",
@@ -0,0 +1,19 @@
1
+ import { faker, type Faker } from '@faker-js/faker'
2
+ import { Organization } from './lib/Organization.js'
3
+ import { Group } from './lib/Group.js'
4
+ import { User } from './lib/User.js'
5
+ import { File } from './lib/File.js'
6
+ import { Invitation } from './lib/Invitation.js'
7
+ import { Trash } from './lib/Trash.js'
8
+ import { Patch } from './lib/Patch.js'
9
+
10
+ export class ModelingMock {
11
+ faker: Faker = faker
12
+ organization = new Organization()
13
+ group = new Group()
14
+ user = new User()
15
+ file = new File()
16
+ invitation = new Invitation()
17
+ trash = new Trash()
18
+ patch = new Patch()
19
+ }
@@ -29,7 +29,7 @@ export class ProjectMock extends DataMock {
29
29
  super(init)
30
30
  this.projectRequest = new Request(init)
31
31
  this.response = new Response(init)
32
- this.user = new User(init)
32
+ this.user = new User()
33
33
  this.history = new History(init)
34
34
  this.url = new Url(init)
35
35
  this.certificates = new Certificates(init)
@@ -0,0 +1,72 @@
1
+ import { faker } from '@faker-js/faker'
2
+ import { ProjectKind, DomainFileKind, CertificateFileKind, FolderKind, ApiFileKind } from '../../models/kinds.js'
3
+ import { File as CoreFile, type IFile, type FileBreadcrumb } from '../../models/store/File.js'
4
+ import { nanoid } from '../../nanoid.js'
5
+
6
+ export class File {
7
+ /**
8
+ * Generates a random file object.
9
+ * @param init Optional values to be present in the object.
10
+ * @returns Random file
11
+ */
12
+ file(init: Partial<IFile> = {}): IFile {
13
+ const {
14
+ kind = faker.helpers.arrayElement([ProjectKind, DomainFileKind, CertificateFileKind, ApiFileKind] as const),
15
+ info = { name: faker.system.fileName() },
16
+ } = init
17
+ return CoreFile.createSchema({ kind, info })
18
+ }
19
+
20
+ /**
21
+ * Generates a list of random file objects.
22
+ * @param size Number of files to generate. Default is 25.
23
+ * @returns List of random files
24
+ */
25
+ files(size = 25): IFile[] {
26
+ const result = []
27
+ for (let i = 0; i < size; i++) {
28
+ result.push(this.file())
29
+ }
30
+ return result
31
+ }
32
+
33
+ /**
34
+ * Generates a random folder object.
35
+ * @param init Optional values to be present in the object.
36
+ * @returns Random folder
37
+ */
38
+ folder(init: Partial<IFile> = {}): IFile {
39
+ return this.file({ kind: FolderKind, ...init })
40
+ }
41
+
42
+ /**
43
+ * Generates a list of random folder objects.
44
+ * @param size Number of folders to generate. Default is 25.
45
+ * @returns List of random folders
46
+ */
47
+ folders(size = 25): IFile[] {
48
+ const result = []
49
+ for (let i = 0; i < size; i++) {
50
+ result.push(this.folder())
51
+ }
52
+ return result
53
+ }
54
+
55
+ /**
56
+ * Generates a random file breadcrumb object.
57
+ * @param size Optional depth of the breadcrumb. Default is random between 2-3.
58
+ * @returns Random file breadcrumb
59
+ */
60
+ fileBreadcrumbs(size?: number): FileBreadcrumb[] {
61
+ const depth = size ?? 2 + Math.floor(Math.random() * 2) // 2-3
62
+ const items: FileBreadcrumb[] = []
63
+ for (let i = 0; i < depth; i += 1) {
64
+ const kind =
65
+ i === depth - 1
66
+ ? faker.helpers.arrayElement([ProjectKind, DomainFileKind, CertificateFileKind, ApiFileKind] as const)
67
+ : FolderKind
68
+ items.push({ key: nanoid(), kind, name: faker.system.fileName() })
69
+ }
70
+ return items
71
+ }
72
+ }
@@ -0,0 +1,52 @@
1
+ import { faker } from '@faker-js/faker'
2
+ import { GroupKind } from '../../models/kinds.js'
3
+ import { nanoid } from '../../nanoid.js'
4
+ import type { GroupSchema } from '../../models/store/Group.js'
5
+
6
+ export class Group {
7
+ /**
8
+ * Generates a random organization object.
9
+ * @param init Optional values to be present in the object.
10
+ * @returns Random organization
11
+ */
12
+ group(init: Partial<GroupSchema> = {}): GroupSchema {
13
+ const {
14
+ key = nanoid(),
15
+ name = faker.lorem.word(),
16
+ color = faker.color.rgb(),
17
+ oid = nanoid(),
18
+ owner = nanoid(),
19
+ createdAt = faker.date.past().getTime(),
20
+ updatedAt = faker.date.recent().getTime(),
21
+ description = faker.lorem.sentence(),
22
+ users = [],
23
+ icon = faker.image.avatar(),
24
+ } = init
25
+ return {
26
+ kind: GroupKind,
27
+ key,
28
+ name,
29
+ color,
30
+ oid,
31
+ owner,
32
+ createdAt,
33
+ updatedAt,
34
+ description,
35
+ users,
36
+ icon,
37
+ }
38
+ }
39
+
40
+ /**
41
+ * Generates a list of random organization objects.
42
+ * @param size Number of organizations to generate. Default is 25.
43
+ * @returns List of random organizations
44
+ */
45
+ groups(size = 25): GroupSchema[] {
46
+ const result = []
47
+ for (let i = 0; i < size; i++) {
48
+ result.push(this.group())
49
+ }
50
+ return result
51
+ }
52
+ }
@@ -0,0 +1,58 @@
1
+ import { faker } from '@faker-js/faker'
2
+ import { InvitationKind } from '../../models/kinds.js'
3
+ import type { InvitationSchema } from '../../models/store/Invitation.js'
4
+ import { nanoid } from '../../nanoid.js'
5
+
6
+ export class Invitation {
7
+ /**
8
+ * Generates a random invitation object.
9
+ * @param init Optional values to be present in the object.
10
+ * @returns Random invitation
11
+ */
12
+ invitation(init: Partial<InvitationSchema> = {}): InvitationSchema {
13
+ const {
14
+ key = nanoid(),
15
+ uid = nanoid(),
16
+ oid = nanoid(),
17
+ name = faker.person.fullName(),
18
+ email = faker.internet.email(),
19
+ createdAt = faker.date.past().getTime(),
20
+ updatedAt = faker.date.recent().getTime(),
21
+ token = nanoid(32),
22
+ expiresAt = faker.date.future().getTime(),
23
+ status = 'pending',
24
+ grantType = faker.helpers.arrayElement(['owner', 'manager', 'editor', 'viewer'] as const),
25
+ resent = 0,
26
+ lastSentAt = createdAt,
27
+ } = init
28
+ return {
29
+ kind: InvitationKind,
30
+ key,
31
+ uid,
32
+ oid,
33
+ name,
34
+ email,
35
+ createdAt,
36
+ updatedAt,
37
+ token,
38
+ expiresAt,
39
+ status,
40
+ grantType,
41
+ resent,
42
+ lastSentAt,
43
+ } as InvitationSchema
44
+ }
45
+
46
+ /**
47
+ * Generates a list of random invitation objects.
48
+ * @param size Number of invitations to generate. Default is 25.
49
+ * @returns List of random invitations
50
+ */
51
+ invitations(size = 25): InvitationSchema[] {
52
+ const result = []
53
+ for (let i = 0; i < size; i++) {
54
+ result.push(this.invitation())
55
+ }
56
+ return result
57
+ }
58
+ }
@@ -0,0 +1,42 @@
1
+ import { faker } from '@faker-js/faker'
2
+ import { OrganizationKind } from '../../models/kinds.js'
3
+ import { nanoid } from '../../nanoid.js'
4
+ import type { IOrganization } from '../../models/store/Organization.js'
5
+
6
+ export class Organization {
7
+ /**
8
+ * Generates a random organization object.
9
+ * @param init Optional values to be present in the object.
10
+ * @returns Random organization
11
+ */
12
+ organization(init: Partial<IOrganization> = {}): IOrganization {
13
+ const {
14
+ key = nanoid(),
15
+ name = faker.company.name(),
16
+ createdBy = nanoid(),
17
+ createdDate = faker.date.past().getTime(),
18
+ grantType = faker.helpers.arrayElement(['owner', 'manager', 'editor', 'viewer'] as const),
19
+ } = init
20
+ return {
21
+ kind: OrganizationKind,
22
+ key,
23
+ name,
24
+ createdBy,
25
+ createdDate,
26
+ grantType,
27
+ }
28
+ }
29
+
30
+ /**
31
+ * Generates a list of random organization objects.
32
+ * @param size Number of organizations to generate. Default is 25.
33
+ * @returns List of random organizations
34
+ */
35
+ organizations(size = 25): IOrganization[] {
36
+ const result = []
37
+ for (let i = 0; i < size; i++) {
38
+ result.push(this.organization())
39
+ }
40
+ return result
41
+ }
42
+ }
@@ -0,0 +1,128 @@
1
+ import { faker } from '@faker-js/faker'
2
+ import type { MediaPatchRevision } from '../../patch/types.js'
3
+ import { nanoid } from '../../nanoid.js'
4
+ import type {
5
+ AddOperation,
6
+ CopyOperation,
7
+ MoveOperation,
8
+ Operation,
9
+ RemoveOperation,
10
+ ReplaceOperation,
11
+ TestOperation,
12
+ } from '@api-client/json/patch/types.js'
13
+
14
+ export class Patch {
15
+ /**
16
+ * Generates a random invitation object.
17
+ * @param init Optional values to be present in the object.
18
+ * @returns Random invitation
19
+ */
20
+ mediaPatchRevision(init: Partial<MediaPatchRevision> = {}): MediaPatchRevision {
21
+ const {
22
+ id = nanoid(),
23
+ timestamp = faker.date.recent().getTime(),
24
+ patch = this.patches(faker.number.int({ min: 1, max: 5 })),
25
+ version = faker.number.int({ min: 1, max: 1000 }),
26
+ revert = [],
27
+ newVersion = version + 1,
28
+ } = init
29
+ return {
30
+ id,
31
+ timestamp,
32
+ patch,
33
+ version,
34
+ revert,
35
+ newVersion,
36
+ } as MediaPatchRevision
37
+ }
38
+
39
+ /**
40
+ * Generates a list of random invitation objects.
41
+ * @param size Number of invitations to generate. Default is 25.
42
+ * @returns List of random invitations
43
+ */
44
+ mediaPatchRevisions(size = 25): MediaPatchRevision[] {
45
+ const result = []
46
+ for (let i = 0; i < size; i++) {
47
+ result.push(this.mediaPatchRevision())
48
+ }
49
+ return result
50
+ }
51
+
52
+ /**
53
+ * Generates a random JSON patch operation.
54
+ * @returns A random patch information.
55
+ */
56
+ patch(): Operation {
57
+ const type = faker.helpers.arrayElement(['add', 'remove', 'replace', 'move', 'copy', 'test'] as const)
58
+ switch (type) {
59
+ case 'add':
60
+ return this.addPatch()
61
+ case 'remove':
62
+ return this.removePatch()
63
+ case 'replace':
64
+ return this.replacePatch()
65
+ case 'move':
66
+ return this.movePatch()
67
+ case 'copy':
68
+ return this.copyPatch()
69
+ case 'test':
70
+ return this.testPatch()
71
+ }
72
+ }
73
+
74
+ patches(size = 25): Operation[] {
75
+ const result = []
76
+ for (let i = 0; i < size; i++) {
77
+ result.push(this.patch())
78
+ }
79
+ return result
80
+ }
81
+
82
+ addPatch(): AddOperation {
83
+ return {
84
+ op: 'add',
85
+ path: `/${nanoid()}`,
86
+ value: faker.lorem.word(),
87
+ }
88
+ }
89
+
90
+ removePatch(): RemoveOperation {
91
+ return {
92
+ op: 'remove',
93
+ path: `/${nanoid()}`,
94
+ } as RemoveOperation
95
+ }
96
+
97
+ replacePatch(): ReplaceOperation {
98
+ return {
99
+ op: 'replace',
100
+ path: `/${nanoid()}`,
101
+ value: faker.lorem.word(),
102
+ } as ReplaceOperation
103
+ }
104
+
105
+ movePatch(): MoveOperation {
106
+ return {
107
+ op: 'move',
108
+ from: `/${nanoid()}`,
109
+ path: `/${nanoid()}`,
110
+ } as MoveOperation
111
+ }
112
+
113
+ copyPatch(): CopyOperation {
114
+ return {
115
+ op: 'copy',
116
+ from: `/${nanoid()}`,
117
+ path: `/${nanoid()}`,
118
+ } as CopyOperation
119
+ }
120
+
121
+ testPatch(): TestOperation {
122
+ return {
123
+ op: 'test',
124
+ path: `/${nanoid()}`,
125
+ value: faker.lorem.word(),
126
+ } as TestOperation
127
+ }
128
+ }
@@ -0,0 +1,47 @@
1
+ import { faker } from '@faker-js/faker'
2
+ import { ProjectKind, DomainFileKind, CertificateFileKind, FolderKind, ApiFileKind } from '../../models/kinds.js'
3
+ import type { TrashEntry as CoreTrashEntry } from '../../models/TrashEntry.js'
4
+ import { nanoid } from '../../nanoid.js'
5
+
6
+ export class Trash {
7
+ /**
8
+ * Generates a random invitation object.
9
+ * @param init Optional values to be present in the object.
10
+ * @returns Random invitation
11
+ */
12
+ trashEntry(init: Partial<CoreTrashEntry> = {}): CoreTrashEntry {
13
+ const {
14
+ key = nanoid(),
15
+ refKey = nanoid(),
16
+ kind = faker.helpers.arrayElement([
17
+ ProjectKind,
18
+ DomainFileKind,
19
+ CertificateFileKind,
20
+ FolderKind,
21
+ ApiFileKind,
22
+ ] as const),
23
+ info = { byMe: false, time: faker.date.recent().getTime(), user: nanoid(), name: faker.system.fileName() },
24
+ capabilities = { canDelete: true, canRestore: true },
25
+ } = init
26
+ return {
27
+ key,
28
+ refKey,
29
+ kind,
30
+ info,
31
+ capabilities,
32
+ } as CoreTrashEntry
33
+ }
34
+
35
+ /**
36
+ * Generates a list of random invitation objects.
37
+ * @param size Number of invitations to generate. Default is 25.
38
+ * @returns List of random invitations
39
+ */
40
+ trashEntries(size = 25): CoreTrashEntry[] {
41
+ const result = []
42
+ for (let i = 0; i < size; i++) {
43
+ result.push(this.trashEntry())
44
+ }
45
+ return result
46
+ }
47
+ }
@@ -1,10 +1,6 @@
1
- import type { IDataMockInit } from '@pawel-up/data-mock/types.js'
2
- import { Types } from '@pawel-up/data-mock/Types.js'
3
- import { Person } from '@pawel-up/data-mock/Person.js'
4
- import { Internet } from '@pawel-up/data-mock/Internet.js'
5
- import { Random } from '@pawel-up/data-mock/Random.js'
1
+ import { faker } from '@faker-js/faker'
2
+ import { nanoid } from '../../nanoid.js'
6
3
  import { IUser, Kind as UserKind } from '../../models/store/User.js'
7
- import { Time } from '@pawel-up/data-mock/Time.js'
8
4
 
9
5
  export interface IUserInit {
10
6
  noEmail?: boolean
@@ -13,48 +9,53 @@ export interface IUserInit {
13
9
  }
14
10
 
15
11
  export class User {
16
- person: Person
17
- types: Types
18
- internet: Internet
19
- random: Random
20
- time: Time
21
-
22
- constructor(init: IDataMockInit = {}) {
23
- this.person = new Person(init)
24
- this.types = new Types(init.seed)
25
- this.internet = new Internet(init)
26
- this.random = new Random(init.seed)
27
- this.time = new Time(init)
28
- }
29
-
12
+ /**
13
+ * Generates a random user object.
14
+ * @param init Configuration options for the user object.
15
+ * @returns Random user
16
+ */
30
17
  user(init: IUserInit = {}): IUser {
31
18
  const result: IUser = {
32
19
  kind: UserKind,
33
- key: this.types.string(21),
34
- name: this.person.name(),
35
- status: this.random.pickOne(['active', 'deleted', 'suspended', 'pending']),
20
+ key: nanoid(),
21
+ name: faker.person.fullName(),
22
+ status: faker.helpers.arrayElement(['active', 'deleted', 'suspended', 'pending']),
36
23
  email: [],
37
- created: this.time.timestamp(),
38
- updated: this.time.timestamp(),
24
+ created: faker.date.past().getTime(),
25
+ updated: faker.date.recent().getTime(),
39
26
  }
40
27
  if (!init.noEmail) {
41
28
  result.email = [
42
29
  {
43
- email: this.internet.email(),
44
- verified: this.types.boolean(),
30
+ email: faker.internet.email(),
31
+ verified: faker.datatype.boolean(),
45
32
  },
46
33
  ]
47
34
  }
48
35
  if (!init.noPicture) {
49
36
  result.picture = {
50
- url: this.internet.avatar(),
37
+ url: faker.image.avatar(),
51
38
  }
52
39
  }
53
40
  if (!init.noProvider) {
54
41
  result.provider = {
55
- refreshToken: this.types.string(21),
42
+ refreshToken: faker.string.alphanumeric(21),
56
43
  }
57
44
  }
58
45
  return result
59
46
  }
47
+
48
+ /**
49
+ * Generates a list of random user objects.
50
+ * @param size The size of the returning array
51
+ * @param init Configuration options for the user object.
52
+ * @returns List of random users
53
+ */
54
+ users(size = 25, init: IUserInit = {}): IUser[] {
55
+ const result: IUser[] = []
56
+ for (let i = 0; i < size; i++) {
57
+ result.push(this.user(init))
58
+ }
59
+ return result
60
+ }
60
61
  }