@api-client/core 0.20.8 → 0.20.10

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.
@@ -0,0 +1,270 @@
1
+ import { DataDomain } from '../../../../src/modeling/DataDomain.js'
2
+ import type { DomainEntity } from '../../../../src/modeling/DomainEntity.js'
3
+ import type { DomainModel } from '../../../../src/modeling/DomainModel.js'
4
+ import { SemanticType } from '../../../../src/modeling/Semantics.js'
5
+
6
+ /**
7
+ * Creates the simplest data domain with a single entity user.
8
+ */
9
+ export function userOnlyDomain(): { domain: DataDomain; model: DomainModel; user: DomainEntity } {
10
+ const domain = new DataDomain({ info: { name: 'Testing Domain', version: '1.0.0' } })
11
+ const model = domain.addModel({ info: { name: 'Container model' } })
12
+ const user = model.addEntity({ info: { name: 'user' } })
13
+ user.addProperty({ info: { name: 'id' }, primary: true })
14
+ user.addProperty({ info: { name: 'username' }, semantics: [{ id: SemanticType.Username }] })
15
+ user.addProperty({ info: { name: 'password' }, semantics: [{ id: SemanticType.Password }] })
16
+ user.addProperty({ info: { name: 'email' }, semantics: [{ id: SemanticType.Email }] })
17
+ user.addProperty({
18
+ info: { name: 'role' },
19
+ semantics: [{ id: SemanticType.UserRole }],
20
+ schema: {
21
+ enum: ['admin', 'member', 'guest'],
22
+ },
23
+ })
24
+ return { domain, model, user }
25
+ }
26
+
27
+ /**
28
+ * Returns a domain that has 1:1 association between user and config.
29
+ */
30
+ export function singletonDomain(): {
31
+ domain: DataDomain
32
+ model: DomainModel
33
+ user: DomainEntity
34
+ config: DomainEntity
35
+ } {
36
+ const { domain, model, user } = userOnlyDomain()
37
+ const config = model.addEntity({ info: { name: 'config' } })
38
+ config.addProperty({ info: { name: 'id' }, primary: true })
39
+ // user has 1 config
40
+ user.addAssociation({
41
+ info: { name: 'config' },
42
+ targets: [{ key: config.key }],
43
+ multiple: false,
44
+ required: false,
45
+ })
46
+ config.addAssociation({
47
+ info: { name: 'owner' },
48
+ targets: [{ key: user.key }],
49
+ multiple: false,
50
+ required: true,
51
+ semantics: [{ id: SemanticType.ResourceOwnerIdentifier }],
52
+ })
53
+ return { domain, model, user, config }
54
+ }
55
+
56
+ /**
57
+ * Returns a blog domain with four entities: user, blog, post, comment.
58
+ */
59
+ export function blogDomain(): {
60
+ domain: DataDomain
61
+ user: DomainEntity
62
+ blog: DomainEntity
63
+ post: DomainEntity
64
+ comment: DomainEntity
65
+ } {
66
+ const domain = new DataDomain({ info: { version: '1.0.0' } })
67
+ const model = domain.addModel({ info: { name: 'Container Model' } })
68
+
69
+ const user = model.addEntity({ info: { name: 'user' }, semantics: [{ id: SemanticType.User }] })
70
+ user.addProperty({
71
+ info: { name: 'id' },
72
+ type: 'string',
73
+ primary: true,
74
+ required: true,
75
+ schema: { defaultValue: { type: 'function', value: 'random' } },
76
+ })
77
+ user.addProperty({
78
+ info: { name: 'name' },
79
+ type: 'string',
80
+ required: true,
81
+ semantics: [{ id: SemanticType.Username }],
82
+ })
83
+ user.addProperty({
84
+ info: { name: 'password' },
85
+ type: 'string',
86
+ required: true,
87
+ semantics: [{ id: SemanticType.Password }],
88
+ })
89
+ user.addProperty({
90
+ info: { name: 'role' },
91
+ type: 'string',
92
+ required: true,
93
+ semantics: [{ id: SemanticType.UserRole }],
94
+ schema: {
95
+ defaultValue: { type: 'literal', value: 'user' },
96
+ enum: ['user', 'admin', 'moderator'],
97
+ },
98
+ })
99
+
100
+ const blog = model.addEntity({ info: { name: 'blog' } })
101
+ blog.addProperty({
102
+ info: { name: 'id' },
103
+ type: 'string',
104
+ primary: true,
105
+ required: true,
106
+ schema: { defaultValue: { type: 'function', value: 'random' } },
107
+ })
108
+ blog.addProperty({
109
+ info: { name: 'title' },
110
+ type: 'string',
111
+ required: true,
112
+ semantics: [{ id: SemanticType.Title }],
113
+ })
114
+ blog.addProperty({
115
+ info: { name: 'content' },
116
+ type: 'string',
117
+ required: true,
118
+ semantics: [{ id: SemanticType.Description }, { id: SemanticType.Markdown }],
119
+ })
120
+ blog.addProperty({
121
+ info: { name: 'status' },
122
+ type: 'string',
123
+ required: true,
124
+ semantics: [{ id: SemanticType.Status }],
125
+ schema: {
126
+ defaultValue: { type: 'literal', value: 'draft' },
127
+ enum: ['draft', 'published'],
128
+ },
129
+ })
130
+ blog.addProperty({
131
+ info: { name: 'created_at' },
132
+ type: 'datetime',
133
+ readOnly: true,
134
+ schema: { defaultValue: { type: 'function', value: 'now' } },
135
+ })
136
+ blog.addProperty({
137
+ info: { name: 'updated_at' },
138
+ type: 'datetime',
139
+ readOnly: true,
140
+ schema: { defaultValue: { type: 'function', value: 'now' } },
141
+ })
142
+ blog.addAssociation({
143
+ info: { name: 'author' },
144
+ targets: [{ key: user.key }],
145
+ multiple: false,
146
+ required: true,
147
+ semantics: [{ id: SemanticType.ResourceOwnerIdentifier }],
148
+ })
149
+ user.addAssociation({
150
+ info: { name: 'blogs' },
151
+ targets: [{ key: blog.key }],
152
+ multiple: true,
153
+ required: false,
154
+ onDelete: 'cascade',
155
+ })
156
+
157
+ const post = model.addEntity({ info: { name: 'posts' } })
158
+ post.addProperty({
159
+ info: { name: 'id' },
160
+ type: 'string',
161
+ primary: true,
162
+ required: true,
163
+ schema: { defaultValue: { type: 'function', value: 'random' } },
164
+ })
165
+ post.addProperty({
166
+ info: { name: 'title' },
167
+ type: 'string',
168
+ required: true,
169
+ semantics: [{ id: SemanticType.Title }],
170
+ })
171
+ post.addProperty({
172
+ info: { name: 'content' },
173
+ type: 'string',
174
+ required: true,
175
+ semantics: [{ id: SemanticType.Description }, { id: SemanticType.Markdown }],
176
+ })
177
+ post.addProperty({
178
+ info: { name: 'status' },
179
+ type: 'string',
180
+ required: true,
181
+ semantics: [{ id: SemanticType.Status }],
182
+ schema: {
183
+ defaultValue: { type: 'literal', value: 'draft' },
184
+ enum: ['draft', 'published'],
185
+ },
186
+ })
187
+ post.addProperty({
188
+ info: { name: 'created_at' },
189
+ type: 'datetime',
190
+ readOnly: true,
191
+ schema: { defaultValue: { type: 'function', value: 'now' } },
192
+ })
193
+ post.addProperty({
194
+ info: { name: 'updated_at' },
195
+ type: 'datetime',
196
+ readOnly: true,
197
+ schema: { defaultValue: { type: 'function', value: 'now' } },
198
+ })
199
+ post.addAssociation({
200
+ info: { name: 'author' },
201
+ targets: [{ key: user.key }],
202
+ multiple: false,
203
+ required: true,
204
+ semantics: [{ id: SemanticType.ResourceOwnerIdentifier }],
205
+ })
206
+ post.addAssociation({
207
+ info: { name: 'blog' },
208
+ targets: [{ key: blog.key }],
209
+ multiple: false,
210
+ required: true,
211
+ })
212
+ user.addAssociation({
213
+ info: { name: 'posts' },
214
+ targets: [{ key: post.key }],
215
+ multiple: true,
216
+ required: false,
217
+ onDelete: 'cascade',
218
+ })
219
+ blog.addAssociation({
220
+ info: { name: 'posts' },
221
+ targets: [{ key: post.key }],
222
+ multiple: true,
223
+ required: false,
224
+ onDelete: 'cascade',
225
+ })
226
+
227
+ const comment = model.addEntity({ info: { name: 'comment' } })
228
+ comment.addProperty({
229
+ info: { name: 'id' },
230
+ type: 'string',
231
+ primary: true,
232
+ required: true,
233
+ schema: { defaultValue: { type: 'function', value: 'random' } },
234
+ })
235
+ comment.addProperty({
236
+ info: { name: 'content' },
237
+ type: 'string',
238
+ required: true,
239
+ semantics: [{ id: SemanticType.Markdown }],
240
+ })
241
+ comment.addAssociation({
242
+ info: { name: 'author' },
243
+ targets: [{ key: user.key }],
244
+ multiple: false,
245
+ required: true,
246
+ semantics: [{ id: SemanticType.ResourceOwnerIdentifier }],
247
+ })
248
+ comment.addAssociation({
249
+ info: { name: 'post' },
250
+ targets: [{ key: post.key }],
251
+ multiple: false,
252
+ required: true,
253
+ })
254
+ user.addAssociation({
255
+ info: { name: 'comments' },
256
+ targets: [{ key: comment.key }],
257
+ multiple: true,
258
+ required: false,
259
+ onDelete: 'cascade',
260
+ })
261
+ post.addAssociation({
262
+ info: { name: 'comments' },
263
+ targets: [{ key: comment.key }],
264
+ multiple: true,
265
+ required: false,
266
+ onDelete: 'cascade',
267
+ })
268
+
269
+ return { domain, user, blog, post, comment }
270
+ }