@appweaver/data 0.0.0-stage → 2.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.
- package/LICENSE +21 -0
- package/README.md +61 -2
- package/config.d.ts +6 -0
- package/config.js +22 -0
- package/database/create-client.d.ts +11 -0
- package/database/create-client.js +145 -0
- package/database/database-config.d.ts +14 -0
- package/database/database-config.js +40 -0
- package/database/database-error.d.ts +49 -0
- package/database/database-error.js +216 -0
- package/database/index.d.ts +3 -0
- package/database/index.js +19 -0
- package/database/prisma-database.d.ts +33 -0
- package/database/prisma-database.js +178 -0
- package/database/run-transaction.d.ts +21 -0
- package/database/run-transaction.js +15 -0
- package/export/export-config.d.ts +7 -0
- package/export/export-config.js +17 -0
- package/export/export-service.d.ts +22 -0
- package/export/export-service.js +188 -0
- package/export/index.d.ts +1 -0
- package/export/index.js +17 -0
- package/factory/create-model.d.ts +11 -0
- package/factory/create-model.js +479 -0
- package/factory/create-policy.d.ts +12 -0
- package/factory/create-policy.js +20 -0
- package/factory/create-service.d.ts +14 -0
- package/factory/create-service.js +116 -0
- package/index.d.ts +22 -0
- package/index.js +38 -0
- package/internal.d.ts +2 -0
- package/internal.js +6 -0
- package/module.d.ts +3 -0
- package/module.js +81 -0
- package/package.json +67 -3
- package/prisma/client/browser.d.ts +39 -0
- package/prisma/client/browser.js +56 -0
- package/prisma/client/client.d.ts +58 -0
- package/prisma/client/client.js +70 -0
- package/prisma/client/commonInputTypes.d.ts +345 -0
- package/prisma/client/commonInputTypes.js +11 -0
- package/prisma/client/enums.d.ts +1 -0
- package/prisma/client/enums.js +11 -0
- package/prisma/client/internal/class.d.ts +198 -0
- package/prisma/client/internal/class.js +85 -0
- package/prisma/client/internal/prismaNamespace.d.ts +1125 -0
- package/prisma/client/internal/prismaNamespace.js +204 -0
- package/prisma/client/internal/prismaNamespaceBrowser.d.ts +137 -0
- package/prisma/client/internal/prismaNamespaceBrowser.js +175 -0
- package/prisma/client/models/ApiKey.d.ts +1167 -0
- package/prisma/client/models/ApiKey.js +2 -0
- package/prisma/client/models/ConnectedAccount.d.ts +1094 -0
- package/prisma/client/models/ConnectedAccount.js +2 -0
- package/prisma/client/models/File.d.ts +1291 -0
- package/prisma/client/models/File.js +2 -0
- package/prisma/client/models/OneTimeToken.d.ts +1055 -0
- package/prisma/client/models/OneTimeToken.js +2 -0
- package/prisma/client/models/Permission.d.ts +1209 -0
- package/prisma/client/models/Permission.js +2 -0
- package/prisma/client/models/Role.d.ts +1209 -0
- package/prisma/client/models/Role.js +2 -0
- package/prisma/client/models/Seeder.d.ts +1023 -0
- package/prisma/client/models/Seeder.js +2 -0
- package/prisma/client/models.d.ts +8 -0
- package/prisma/client/models.js +2 -0
- package/resource/load-data-resources.d.ts +13 -0
- package/resource/load-data-resources.js +37 -0
- package/resource/model-schema.d.ts +34 -0
- package/resource/model-schema.js +54 -0
- package/resource/resource-config.d.ts +16 -0
- package/resource/resource-config.js +62 -0
- package/resource/resource-loader.d.ts +25 -0
- package/resource/resource-loader.js +138 -0
- package/resource/resource-service.d.ts +462 -0
- package/resource/resource-service.js +1042 -0
- package/resource/schemas/index.d.ts +3 -0
- package/resource/schemas/index.js +19 -0
- package/resource/schemas/resource-aggregate-schema.d.ts +53 -0
- package/resource/schemas/resource-aggregate-schema.js +130 -0
- package/resource/schemas/resource-filter-schema.d.ts +39 -0
- package/resource/schemas/resource-filter-schema.js +153 -0
- package/resource/schemas/resource-sort-schema.d.ts +38 -0
- package/resource/schemas/resource-sort-schema.js +113 -0
- package/resource/utils/aggregate-util.d.ts +113 -0
- package/resource/utils/aggregate-util.js +322 -0
- package/resource/utils/cursor-util.d.ts +60 -0
- package/resource/utils/cursor-util.js +116 -0
- package/resource/utils/date-util.d.ts +22 -0
- package/resource/utils/date-util.js +112 -0
- package/resource/utils/delete-util.d.ts +131 -0
- package/resource/utils/delete-util.js +385 -0
- package/resource/utils/filter-util.d.ts +24 -0
- package/resource/utils/filter-util.js +289 -0
- package/resource/utils/prune-util.d.ts +11 -0
- package/resource/utils/prune-util.js +56 -0
- package/resource/utils/relation-util.d.ts +75 -0
- package/resource/utils/relation-util.js +400 -0
- package/resource/utils/sort-util.d.ts +31 -0
- package/resource/utils/sort-util.js +235 -0
- package/resource/utils/text-search-util.d.ts +14 -0
- package/resource/utils/text-search-util.js +39 -0
- package/resources.d.ts +10 -0
- package/resources.js +26 -0
- package/security/auth-config.d.ts +23 -0
- package/security/auth-config.js +43 -0
- package/security/create-auth-resources.d.ts +28 -0
- package/security/create-auth-resources.js +163 -0
- package/security/helper.d.ts +109 -0
- package/security/helper.js +298 -0
- package/security/resources/api-key/model.d.ts +2 -0
- package/security/resources/api-key/model.js +67 -0
- package/security/resources/api-key/policy.d.ts +2 -0
- package/security/resources/api-key/policy.js +27 -0
- package/security/resources/api-key/service.d.ts +3 -0
- package/security/resources/api-key/service.js +34 -0
- package/security/resources/connected-account/model.d.ts +2 -0
- package/security/resources/connected-account/model.js +57 -0
- package/security/resources/connected-account/service.d.ts +2 -0
- package/security/resources/connected-account/service.js +7 -0
- package/security/resources/one-time-token/model.d.ts +2 -0
- package/security/resources/one-time-token/model.js +36 -0
- package/security/resources/permission/model.d.ts +2 -0
- package/security/resources/permission/model.js +16 -0
- package/security/resources/role/model.d.ts +2 -0
- package/security/resources/role/model.js +22 -0
- package/security/store/database-security-store.d.ts +5 -0
- package/security/store/database-security-store.js +54 -0
- package/seeder/create-seeder.d.ts +29 -0
- package/seeder/create-seeder.js +28 -0
- package/seeder/index.d.ts +2 -0
- package/seeder/index.js +18 -0
- package/seeder/resources/seeder/model.d.ts +2 -0
- package/seeder/resources/seeder/model.js +38 -0
- package/seeder/seeder.d.ts +29 -0
- package/seeder/seeder.js +197 -0
- package/storage/file-service.d.ts +133 -0
- package/storage/file-service.js +586 -0
- package/storage/image-config.d.ts +3 -0
- package/storage/image-config.js +11 -0
- package/storage/resources/file/model.d.ts +2 -0
- package/storage/resources/file/model.js +80 -0
- package/types/auth.d.ts +23 -0
- package/types/auth.js +2 -0
- package/types/generated.d.ts +366 -0
- package/types/generated.js +3 -0
- package/types/storage.d.ts +35 -0
- package/types/storage.js +2 -0
- package/utils/export-util.d.ts +8 -0
- package/utils/export-util.js +26 -0
- package/utils/file-util.d.ts +106 -0
- package/utils/file-util.js +254 -0
- package/utils/model-util.d.ts +36 -0
- package/utils/model-util.js +154 -0
- package/utils/policy-util.d.ts +18 -0
- package/utils/policy-util.js +28 -0
- package/utils/virtual-util.d.ts +11 -0
- package/utils/virtual-util.js +53 -0
package/types/auth.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { AuthSource, AuthUser } from '@appweaver/common';
|
|
2
|
+
import { FileBuffer } from './storage';
|
|
3
|
+
export type AvatarFile = FileBuffer & {
|
|
4
|
+
size: number;
|
|
5
|
+
};
|
|
6
|
+
export type UserInfo = {
|
|
7
|
+
id: string;
|
|
8
|
+
email: string;
|
|
9
|
+
firstName: string;
|
|
10
|
+
lastName: string;
|
|
11
|
+
avatarUrl?: string;
|
|
12
|
+
avatarFile?: AvatarFile;
|
|
13
|
+
};
|
|
14
|
+
export type UserAdditionalData = {
|
|
15
|
+
firstName: string;
|
|
16
|
+
lastName: string;
|
|
17
|
+
avatarUrl?: string;
|
|
18
|
+
avatarFile?: AvatarFile;
|
|
19
|
+
};
|
|
20
|
+
export type RegistrationDataFn<T = any> = (source: AuthSource, email: string, password?: string, additionalData?: Partial<UserAdditionalData>) => T | Promise<T>;
|
|
21
|
+
export type RegistrationFilesFn = (source: AuthSource, additionalData?: Partial<UserAdditionalData>) => RegistrationFiles | Promise<RegistrationFiles>;
|
|
22
|
+
export type RegistrationFiles = Record<string, FileBuffer | null | undefined>;
|
|
23
|
+
export type CheckOAuth2UserFn = (source: AuthSource, userInfo: UserInfo, authUser: AuthUser | null) => void | string | Error | Promise<void | string | Error>;
|
package/types/auth.js
ADDED
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
import { AggregateSelect, IResourceService, QueryFilter, QuerySort } from '@appweaver/common';
|
|
2
|
+
export type ApiKey = {
|
|
3
|
+
id: number;
|
|
4
|
+
key: string;
|
|
5
|
+
keyHash: string;
|
|
6
|
+
name?: string | null;
|
|
7
|
+
description?: string | null;
|
|
8
|
+
enabled: boolean;
|
|
9
|
+
expiresAt?: Date | null;
|
|
10
|
+
updatedAt: Date;
|
|
11
|
+
createdAt: Date;
|
|
12
|
+
createdById?: number | null;
|
|
13
|
+
};
|
|
14
|
+
export type ApiKeySingle = {
|
|
15
|
+
id: number;
|
|
16
|
+
key: string;
|
|
17
|
+
name?: string | null;
|
|
18
|
+
description?: string | null;
|
|
19
|
+
enabled: boolean;
|
|
20
|
+
expiresAt?: Date | null;
|
|
21
|
+
updatedAt: Date;
|
|
22
|
+
createdAt: Date;
|
|
23
|
+
createdById?: number | null;
|
|
24
|
+
};
|
|
25
|
+
export type ApiKeyMultiple = {
|
|
26
|
+
id: number;
|
|
27
|
+
key: string;
|
|
28
|
+
name?: string | null;
|
|
29
|
+
description?: string | null;
|
|
30
|
+
enabled: boolean;
|
|
31
|
+
expiresAt?: Date | null;
|
|
32
|
+
updatedAt: Date;
|
|
33
|
+
createdAt: Date;
|
|
34
|
+
createdById?: number | null;
|
|
35
|
+
};
|
|
36
|
+
export type ApiKeyCreate = {
|
|
37
|
+
name?: string | null;
|
|
38
|
+
description?: string | null;
|
|
39
|
+
enabled?: boolean;
|
|
40
|
+
expiresAt?: Date | null;
|
|
41
|
+
};
|
|
42
|
+
export type ApiKeyUpdate = {
|
|
43
|
+
name?: string | null;
|
|
44
|
+
description?: string | null;
|
|
45
|
+
enabled?: boolean;
|
|
46
|
+
};
|
|
47
|
+
export type ApiKeyReplace = {
|
|
48
|
+
name?: string | null;
|
|
49
|
+
description?: string | null;
|
|
50
|
+
enabled?: boolean;
|
|
51
|
+
};
|
|
52
|
+
export type ApiKeyRelationCreate = {
|
|
53
|
+
name?: string | null;
|
|
54
|
+
description?: string | null;
|
|
55
|
+
enabled?: boolean;
|
|
56
|
+
expiresAt?: Date | null;
|
|
57
|
+
};
|
|
58
|
+
export type ApiKeyRelationUpdate = {
|
|
59
|
+
id: number;
|
|
60
|
+
name?: string | null;
|
|
61
|
+
description?: string | null;
|
|
62
|
+
enabled?: boolean;
|
|
63
|
+
};
|
|
64
|
+
export type ApiKeyQuery = QueryFilter<ApiKey>;
|
|
65
|
+
export type ApiKeySort = QuerySort<ApiKeyMultiple>;
|
|
66
|
+
export type ApiKeyAggregate = AggregateSelect<ApiKey>;
|
|
67
|
+
export type ApiKeyResourceService = IResourceService<ApiKey, ApiKeyMultiple, ApiKeyCreate, ApiKeyUpdate, ApiKeyQuery, ApiKeyReplace>;
|
|
68
|
+
export type ConnectedAccount = {
|
|
69
|
+
id: number;
|
|
70
|
+
provider: string;
|
|
71
|
+
providerAccountId: string;
|
|
72
|
+
scope?: string | null;
|
|
73
|
+
lastLoginAt: Date;
|
|
74
|
+
updatedAt: Date;
|
|
75
|
+
createdAt: Date;
|
|
76
|
+
};
|
|
77
|
+
export type ConnectedAccountSingle = {
|
|
78
|
+
id: number;
|
|
79
|
+
provider: string;
|
|
80
|
+
providerAccountId: string;
|
|
81
|
+
scope?: string | null;
|
|
82
|
+
lastLoginAt: Date;
|
|
83
|
+
updatedAt: Date;
|
|
84
|
+
createdAt: Date;
|
|
85
|
+
};
|
|
86
|
+
export type ConnectedAccountMultiple = {
|
|
87
|
+
id: number;
|
|
88
|
+
provider: string;
|
|
89
|
+
providerAccountId: string;
|
|
90
|
+
scope?: string | null;
|
|
91
|
+
lastLoginAt: Date;
|
|
92
|
+
updatedAt: Date;
|
|
93
|
+
createdAt: Date;
|
|
94
|
+
};
|
|
95
|
+
export type ConnectedAccountCreate = {
|
|
96
|
+
provider: string;
|
|
97
|
+
providerAccountId: string;
|
|
98
|
+
scope?: string | null;
|
|
99
|
+
lastLoginAt: Date;
|
|
100
|
+
};
|
|
101
|
+
export type ConnectedAccountUpdate = {
|
|
102
|
+
provider?: string;
|
|
103
|
+
providerAccountId?: string;
|
|
104
|
+
scope?: string | null;
|
|
105
|
+
lastLoginAt?: Date;
|
|
106
|
+
};
|
|
107
|
+
export type ConnectedAccountReplace = {
|
|
108
|
+
provider: string;
|
|
109
|
+
providerAccountId: string;
|
|
110
|
+
scope?: string | null;
|
|
111
|
+
lastLoginAt: Date;
|
|
112
|
+
};
|
|
113
|
+
export type ConnectedAccountRelationCreate = {
|
|
114
|
+
provider: string;
|
|
115
|
+
providerAccountId: string;
|
|
116
|
+
scope?: string | null;
|
|
117
|
+
lastLoginAt: Date;
|
|
118
|
+
};
|
|
119
|
+
export type ConnectedAccountRelationUpdate = {
|
|
120
|
+
id: number;
|
|
121
|
+
provider?: string;
|
|
122
|
+
providerAccountId?: string;
|
|
123
|
+
scope?: string | null;
|
|
124
|
+
lastLoginAt?: Date;
|
|
125
|
+
};
|
|
126
|
+
export type ConnectedAccountQuery = QueryFilter<ConnectedAccount>;
|
|
127
|
+
export type ConnectedAccountSort = QuerySort<ConnectedAccountMultiple>;
|
|
128
|
+
export type ConnectedAccountAggregate = AggregateSelect<ConnectedAccount>;
|
|
129
|
+
export type ConnectedAccountResourceService = IResourceService<ConnectedAccount, ConnectedAccountMultiple, ConnectedAccountCreate, ConnectedAccountUpdate, ConnectedAccountQuery, ConnectedAccountReplace>;
|
|
130
|
+
export type OneTimeToken = {
|
|
131
|
+
id: number;
|
|
132
|
+
tokenHash: string;
|
|
133
|
+
purpose: string;
|
|
134
|
+
data: any;
|
|
135
|
+
expiresAt: Date;
|
|
136
|
+
createdAt: Date;
|
|
137
|
+
};
|
|
138
|
+
export type OneTimeTokenSingle = {
|
|
139
|
+
id: number;
|
|
140
|
+
tokenHash: string;
|
|
141
|
+
purpose: string;
|
|
142
|
+
data: any;
|
|
143
|
+
expiresAt: Date;
|
|
144
|
+
createdAt: Date;
|
|
145
|
+
};
|
|
146
|
+
export type OneTimeTokenMultiple = {
|
|
147
|
+
id: number;
|
|
148
|
+
tokenHash: string;
|
|
149
|
+
purpose: string;
|
|
150
|
+
data: any;
|
|
151
|
+
expiresAt: Date;
|
|
152
|
+
createdAt: Date;
|
|
153
|
+
};
|
|
154
|
+
export type OneTimeTokenCreate = {
|
|
155
|
+
tokenHash: string;
|
|
156
|
+
purpose: string;
|
|
157
|
+
data: any;
|
|
158
|
+
expiresAt: Date;
|
|
159
|
+
};
|
|
160
|
+
export type OneTimeTokenUpdate = {
|
|
161
|
+
tokenHash?: string;
|
|
162
|
+
purpose?: string;
|
|
163
|
+
data?: any;
|
|
164
|
+
expiresAt?: Date;
|
|
165
|
+
};
|
|
166
|
+
export type OneTimeTokenReplace = {
|
|
167
|
+
tokenHash: string;
|
|
168
|
+
purpose: string;
|
|
169
|
+
data: any;
|
|
170
|
+
expiresAt: Date;
|
|
171
|
+
};
|
|
172
|
+
export type OneTimeTokenRelationCreate = {
|
|
173
|
+
tokenHash: string;
|
|
174
|
+
purpose: string;
|
|
175
|
+
data: any;
|
|
176
|
+
expiresAt: Date;
|
|
177
|
+
};
|
|
178
|
+
export type OneTimeTokenRelationUpdate = {
|
|
179
|
+
id: number;
|
|
180
|
+
tokenHash?: string;
|
|
181
|
+
purpose?: string;
|
|
182
|
+
data?: any;
|
|
183
|
+
expiresAt?: Date;
|
|
184
|
+
};
|
|
185
|
+
export type OneTimeTokenQuery = QueryFilter<OneTimeToken>;
|
|
186
|
+
export type OneTimeTokenSort = QuerySort<OneTimeTokenMultiple>;
|
|
187
|
+
export type OneTimeTokenAggregate = AggregateSelect<OneTimeToken>;
|
|
188
|
+
export type OneTimeTokenResourceService = IResourceService<OneTimeToken, OneTimeTokenMultiple, OneTimeTokenCreate, OneTimeTokenUpdate, OneTimeTokenQuery, OneTimeTokenReplace>;
|
|
189
|
+
export type Permission = {
|
|
190
|
+
id: number;
|
|
191
|
+
name: string;
|
|
192
|
+
updatedAt: Date;
|
|
193
|
+
createdAt: Date;
|
|
194
|
+
createdById?: number | null;
|
|
195
|
+
};
|
|
196
|
+
export type PermissionSingle = {
|
|
197
|
+
id: number;
|
|
198
|
+
name: string;
|
|
199
|
+
};
|
|
200
|
+
export type PermissionMultiple = {
|
|
201
|
+
id: number;
|
|
202
|
+
name: string;
|
|
203
|
+
};
|
|
204
|
+
export type PermissionCreate = {
|
|
205
|
+
name: string;
|
|
206
|
+
};
|
|
207
|
+
export type PermissionUpdate = {
|
|
208
|
+
name?: string;
|
|
209
|
+
};
|
|
210
|
+
export type PermissionReplace = {
|
|
211
|
+
name: string;
|
|
212
|
+
};
|
|
213
|
+
export type PermissionRelationCreate = {
|
|
214
|
+
name: string;
|
|
215
|
+
};
|
|
216
|
+
export type PermissionRelationUpdate = {
|
|
217
|
+
id: number;
|
|
218
|
+
name?: string;
|
|
219
|
+
};
|
|
220
|
+
export type PermissionQuery = QueryFilter<Permission>;
|
|
221
|
+
export type PermissionSort = QuerySort<PermissionMultiple>;
|
|
222
|
+
export type PermissionAggregate = AggregateSelect<Permission>;
|
|
223
|
+
export type PermissionResourceService = IResourceService<Permission, PermissionMultiple, PermissionCreate, PermissionUpdate, PermissionQuery, PermissionReplace>;
|
|
224
|
+
export type Role = {
|
|
225
|
+
id: number;
|
|
226
|
+
name: string;
|
|
227
|
+
permissions: Array<PermissionSingle>;
|
|
228
|
+
updatedAt: Date;
|
|
229
|
+
createdAt: Date;
|
|
230
|
+
createdById?: number | null;
|
|
231
|
+
};
|
|
232
|
+
export type RoleSingle = {
|
|
233
|
+
id: number;
|
|
234
|
+
name: string;
|
|
235
|
+
permissions?: Array<PermissionSingle>;
|
|
236
|
+
};
|
|
237
|
+
export type RoleMultiple = {
|
|
238
|
+
id: number;
|
|
239
|
+
name: string;
|
|
240
|
+
permissions?: Array<PermissionSingle>;
|
|
241
|
+
};
|
|
242
|
+
export type RoleCreate = {
|
|
243
|
+
name: string;
|
|
244
|
+
permissions: Array<{
|
|
245
|
+
id: number;
|
|
246
|
+
} | number>;
|
|
247
|
+
};
|
|
248
|
+
export type RoleUpdate = {
|
|
249
|
+
name?: string;
|
|
250
|
+
permissions?: Array<{
|
|
251
|
+
id: number;
|
|
252
|
+
} | number>;
|
|
253
|
+
};
|
|
254
|
+
export type RoleReplace = {
|
|
255
|
+
name: string;
|
|
256
|
+
permissions: Array<{
|
|
257
|
+
id: number;
|
|
258
|
+
} | number>;
|
|
259
|
+
};
|
|
260
|
+
export type RoleRelationCreate = {
|
|
261
|
+
name: string;
|
|
262
|
+
};
|
|
263
|
+
export type RoleRelationUpdate = {
|
|
264
|
+
id: number;
|
|
265
|
+
name?: string;
|
|
266
|
+
};
|
|
267
|
+
export type RoleQuery = QueryFilter<Role>;
|
|
268
|
+
export type RoleSort = QuerySort<RoleMultiple>;
|
|
269
|
+
export type RoleAggregate = AggregateSelect<Role>;
|
|
270
|
+
export type RoleResourceService = IResourceService<Role, RoleMultiple, RoleCreate, RoleUpdate, RoleQuery, RoleReplace>;
|
|
271
|
+
export type File = {
|
|
272
|
+
id: number;
|
|
273
|
+
name: string;
|
|
274
|
+
originalName: string;
|
|
275
|
+
mimeType: string;
|
|
276
|
+
sizeBytes: number;
|
|
277
|
+
checksum: string;
|
|
278
|
+
title?: string | null;
|
|
279
|
+
description?: string | null;
|
|
280
|
+
resourceField?: string | null;
|
|
281
|
+
resourceName?: string | null;
|
|
282
|
+
resourceId?: string | null;
|
|
283
|
+
url: string;
|
|
284
|
+
updatedAt: Date;
|
|
285
|
+
createdAt: Date;
|
|
286
|
+
createdById?: number | null;
|
|
287
|
+
deletedAt?: Date | null;
|
|
288
|
+
};
|
|
289
|
+
export type FileSingle = {
|
|
290
|
+
id: number;
|
|
291
|
+
name: string;
|
|
292
|
+
originalName: string;
|
|
293
|
+
mimeType: string;
|
|
294
|
+
sizeBytes: number;
|
|
295
|
+
checksum: string;
|
|
296
|
+
title?: string | null;
|
|
297
|
+
description?: string | null;
|
|
298
|
+
url: string;
|
|
299
|
+
updatedAt: Date;
|
|
300
|
+
createdAt: Date;
|
|
301
|
+
createdById?: number | null;
|
|
302
|
+
};
|
|
303
|
+
export type FileMultiple = {
|
|
304
|
+
id: number;
|
|
305
|
+
name: string;
|
|
306
|
+
originalName: string;
|
|
307
|
+
mimeType: string;
|
|
308
|
+
sizeBytes: number;
|
|
309
|
+
checksum: string;
|
|
310
|
+
title?: string | null;
|
|
311
|
+
description?: string | null;
|
|
312
|
+
url: string;
|
|
313
|
+
updatedAt: Date;
|
|
314
|
+
createdAt: Date;
|
|
315
|
+
createdById?: number | null;
|
|
316
|
+
};
|
|
317
|
+
export type FileCreate = {
|
|
318
|
+
name: string;
|
|
319
|
+
originalName: string;
|
|
320
|
+
mimeType: string;
|
|
321
|
+
sizeBytes: number;
|
|
322
|
+
checksum: string;
|
|
323
|
+
title?: string | null;
|
|
324
|
+
description?: string | null;
|
|
325
|
+
};
|
|
326
|
+
export type FileUpdate = {
|
|
327
|
+
name?: string;
|
|
328
|
+
originalName?: string;
|
|
329
|
+
mimeType?: string;
|
|
330
|
+
sizeBytes?: number;
|
|
331
|
+
checksum?: string;
|
|
332
|
+
title?: string | null;
|
|
333
|
+
description?: string | null;
|
|
334
|
+
};
|
|
335
|
+
export type FileReplace = {
|
|
336
|
+
name: string;
|
|
337
|
+
originalName: string;
|
|
338
|
+
mimeType: string;
|
|
339
|
+
sizeBytes: number;
|
|
340
|
+
checksum: string;
|
|
341
|
+
title?: string | null;
|
|
342
|
+
description?: string | null;
|
|
343
|
+
};
|
|
344
|
+
export type FileRelationCreate = {
|
|
345
|
+
name: string;
|
|
346
|
+
originalName: string;
|
|
347
|
+
mimeType: string;
|
|
348
|
+
sizeBytes: number;
|
|
349
|
+
checksum: string;
|
|
350
|
+
title?: string | null;
|
|
351
|
+
description?: string | null;
|
|
352
|
+
};
|
|
353
|
+
export type FileRelationUpdate = {
|
|
354
|
+
id: number;
|
|
355
|
+
name?: string;
|
|
356
|
+
originalName?: string;
|
|
357
|
+
mimeType?: string;
|
|
358
|
+
sizeBytes?: number;
|
|
359
|
+
checksum?: string;
|
|
360
|
+
title?: string | null;
|
|
361
|
+
description?: string | null;
|
|
362
|
+
};
|
|
363
|
+
export type FileQuery = QueryFilter<File>;
|
|
364
|
+
export type FileSort = QuerySort<FileMultiple>;
|
|
365
|
+
export type FileAggregate = AggregateSelect<File>;
|
|
366
|
+
export type FileResourceService = IResourceService<File, FileMultiple, FileCreate, FileUpdate, FileQuery, FileReplace>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Readable } from 'node:stream';
|
|
2
|
+
/**
|
|
3
|
+
* An in-memory file, used to store a file that was not received as a multipart upload, such as an avatar downloaded
|
|
4
|
+
* from an OAuth2 provider or an image generated by the application itself.
|
|
5
|
+
*/
|
|
6
|
+
export type FileBuffer = {
|
|
7
|
+
/** The original file name, used to derive the stored name and its extension. */
|
|
8
|
+
name: string;
|
|
9
|
+
/** The media type of the content, checked against the `mimeType` of the file field. */
|
|
10
|
+
mimeType: string;
|
|
11
|
+
/** The file content. */
|
|
12
|
+
data: Buffer;
|
|
13
|
+
/** The content size in bytes checked against the size limit of the file field, defaults to the data buffer length. */
|
|
14
|
+
size?: number;
|
|
15
|
+
/** The content encoding, defaults to `7bit`. */
|
|
16
|
+
encoding?: string;
|
|
17
|
+
};
|
|
18
|
+
/** A file part of a multipart upload, the shape of the files of `@fastify/multipart`. */
|
|
19
|
+
export type UploadedFile = {
|
|
20
|
+
type: 'file';
|
|
21
|
+
fieldname: string;
|
|
22
|
+
filename: string;
|
|
23
|
+
encoding: string;
|
|
24
|
+
mimetype: string;
|
|
25
|
+
/** The content, with the bytes read so far and whether the size limit truncated it. */
|
|
26
|
+
file: Readable & {
|
|
27
|
+
bytesRead: number;
|
|
28
|
+
truncated: boolean;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
/** A part of a multipart upload: a file, or a field the file services skip. */
|
|
32
|
+
export type UploadPart = UploadedFile | {
|
|
33
|
+
type: 'field';
|
|
34
|
+
fieldname: string;
|
|
35
|
+
};
|
package/types/storage.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts an array of data into a CSV-formatted string.
|
|
3
|
+
*
|
|
4
|
+
* @param {Object[]} data - The array of data to be converted into CSV format.
|
|
5
|
+
* @param {boolean} [header=false] - Whether to include a header row in the generated CSV.
|
|
6
|
+
* @return {string} The CSV-formatted string representation of the input data.
|
|
7
|
+
*/
|
|
8
|
+
export declare function toCsv(data: any[], header?: boolean): string;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toCsv = toCsv;
|
|
4
|
+
const sync_1 = require("csv-stringify/sync");
|
|
5
|
+
const common_1 = require("@appweaver/common");
|
|
6
|
+
const export_config_1 = require("../export/export-config");
|
|
7
|
+
/**
|
|
8
|
+
* Converts an array of data into a CSV-formatted string.
|
|
9
|
+
*
|
|
10
|
+
* @param {Object[]} data - The array of data to be converted into CSV format.
|
|
11
|
+
* @param {boolean} [header=false] - Whether to include a header row in the generated CSV.
|
|
12
|
+
* @return {string} The CSV-formatted string representation of the input data.
|
|
13
|
+
*/
|
|
14
|
+
function toCsv(data, header = false) {
|
|
15
|
+
return (0, sync_1.stringify)(Object.values(data), {
|
|
16
|
+
delimiter: export_config_1.exportConfig.CSV_DELIMITER,
|
|
17
|
+
cast: {
|
|
18
|
+
date: (value) => value.toISOString(),
|
|
19
|
+
object: (value) => (0, common_1.isArray)(value) &&
|
|
20
|
+
((0, common_1.isString)(value) || (0, common_1.isNumber)(value) || (0, common_1.isBoolean)(value))
|
|
21
|
+
? value.join(export_config_1.exportConfig.CSV_JOIN_DELIMITER)
|
|
22
|
+
: JSON.stringify(value)
|
|
23
|
+
},
|
|
24
|
+
header
|
|
25
|
+
});
|
|
26
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { FilesConfig, ResourceModel } from '@appweaver/common';
|
|
2
|
+
import { File } from '../types/generated';
|
|
3
|
+
/**
|
|
4
|
+
* Builds the access URL for a stored file. The `public` or `protected` path prefix is resolved from the access type
|
|
5
|
+
* configured in the file policy of the resource owning the file, and the route prefix is taken from the
|
|
6
|
+
* `STORAGE_FILES_ROUTE_PREFIX` configuration.
|
|
7
|
+
*
|
|
8
|
+
* @param {File} file - The file object containing the name and owning resource information.
|
|
9
|
+
* @return {string} The absolute URL for accessing the file.
|
|
10
|
+
*/
|
|
11
|
+
export declare function buildFileUrl(file: File): string;
|
|
12
|
+
/**
|
|
13
|
+
* Splits the file fields of a deleted resource by what happens to their files. On a delete removing the resource from
|
|
14
|
+
* the database each field follows its `onResourceDeleted` option, which defaults to `'delete'`, while on a soft delete
|
|
15
|
+
* it follows its `onResourceSoftDeleted` option, which defaults to `'keep'`.
|
|
16
|
+
*
|
|
17
|
+
* @param {FilesConfig} [files] - The file fields of the deleted resource's model.
|
|
18
|
+
* @param {boolean} softDeleted - Whether the resource was soft deleted.
|
|
19
|
+
* @return {{deleted: string[], kept: string[]}} The fields whose files are removed from storage, and the fields whose
|
|
20
|
+
* files are retained, but no longer served.
|
|
21
|
+
*/
|
|
22
|
+
export declare function deletedResourceFileFields(files: FilesConfig | undefined, softDeleted: boolean): {
|
|
23
|
+
deleted: string[];
|
|
24
|
+
kept: string[];
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Parses a range string and converts it into an object with start and end values.
|
|
28
|
+
*
|
|
29
|
+
* @param {string} [range] - The range string to parse, typically in the format "bytes=start-end".
|
|
30
|
+
* @return {{start: number, end?: number}} An object containing the start value and an optional end value.
|
|
31
|
+
*/
|
|
32
|
+
export declare function parseRange(range?: string): {
|
|
33
|
+
start: number;
|
|
34
|
+
end?: number;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Calculates the maximum file size allowed based on the provided file configuration.
|
|
38
|
+
*
|
|
39
|
+
* @param {FilesConfig} fileConfig - An object containing file configuration data, including maximum size for each file
|
|
40
|
+
* type.
|
|
41
|
+
* @return {number} The maximum size in bytes allowed for any file based on the given configuration.
|
|
42
|
+
*/
|
|
43
|
+
export declare function maxFileSize(fileConfig: FilesConfig): number;
|
|
44
|
+
/**
|
|
45
|
+
* Converts a given size represented as a string or number into its equivalent size in bytes.
|
|
46
|
+
*
|
|
47
|
+
* @param {string | number} [size] - The size to be converted, either as a string or a number.
|
|
48
|
+
* @return {number} The size in bytes. Returns 0 if the input is invalid or not provided.
|
|
49
|
+
*/
|
|
50
|
+
export declare function sizeInBytes(size?: string | number): number;
|
|
51
|
+
/**
|
|
52
|
+
* Validates if the provided MIME type matches a given pattern or regular expression.
|
|
53
|
+
*
|
|
54
|
+
* @param {string} mimeType - The MIME type to validate.
|
|
55
|
+
* @param {string|RegExp} [mimeTypeExp] - An optional pattern or regular expression to match the MIME type against.
|
|
56
|
+
* If not provided, the method will always return true.
|
|
57
|
+
* @return {boolean} True if the MIME type matches the specified pattern or regular expression, false otherwise.
|
|
58
|
+
*/
|
|
59
|
+
export declare function isValidMimeType(mimeType: string, mimeTypeExp?: string | RegExp): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Generates a file name based on a given name, an optional pattern, and a set of variables.
|
|
62
|
+
*
|
|
63
|
+
* @param {string} name The original file name including its extension.
|
|
64
|
+
* @param {string} [pattern] An optional pattern to customize the generated file name. If not provided, a default
|
|
65
|
+
* pattern will be used.
|
|
66
|
+
* @param {Record<string, any>} [variables={}] Additional variables to replace in the pattern. These can include custom
|
|
67
|
+
* placeholders to dynamically generate the file name.
|
|
68
|
+
* @return {string} The generated, sanitized file name based on the provided or default pattern.
|
|
69
|
+
*/
|
|
70
|
+
export declare function generateFileName(name: string, pattern?: string, variables?: Record<string, any>): string;
|
|
71
|
+
/**
|
|
72
|
+
* Validates that no configured file name pattern writes into a path reserved by `STORAGE_RESERVED_PATHS`. Both the
|
|
73
|
+
* global `STORAGE_NAME_PATTERN` and the `namePattern` of every file field of the provided models are checked. Patterns
|
|
74
|
+
* defined as a factory function cannot be resolved before an upload, so they are validated at runtime instead.
|
|
75
|
+
*
|
|
76
|
+
* @param {Record<string, ResourceModel>} models - The loaded resource models, keyed by model name.
|
|
77
|
+
* @throws {Error} Throws an error naming the model, the field, and the reserved path when a pattern is reserved.
|
|
78
|
+
*/
|
|
79
|
+
export declare function validateFileNamePatterns(models: Record<string, ResourceModel>): void;
|
|
80
|
+
/**
|
|
81
|
+
* Sanitizes a given filename by removing invalid characters that are not allowed in file systems. Path separators are
|
|
82
|
+
* preserved, since a file name may be a path relative to the storage root.
|
|
83
|
+
*
|
|
84
|
+
* @param fileName The original filename to sanitize.
|
|
85
|
+
* @return A sanitized filename with invalid characters removed.
|
|
86
|
+
*/
|
|
87
|
+
export declare function sanitizeFilename(fileName: string): string;
|
|
88
|
+
/**
|
|
89
|
+
* Sanitizes an untrusted value into a single file path segment. In addition to the characters removed by
|
|
90
|
+
* {@link sanitizeFilename}, all path separators are stripped and leading dots are removed, so that the value can never
|
|
91
|
+
* introduce a subdirectory, a `..` traversal or a hidden file.
|
|
92
|
+
*
|
|
93
|
+
* @param value The untrusted value to sanitize.
|
|
94
|
+
* @return A sanitized single path segment, or an empty string when nothing usable remains.
|
|
95
|
+
*/
|
|
96
|
+
export declare function sanitizeFileSegment(value?: string | null): string;
|
|
97
|
+
/**
|
|
98
|
+
* Aggregates the provided files into a structured object based on the given configuration.
|
|
99
|
+
*
|
|
100
|
+
* @param {File[]} files - An array of file objects to be processed and aggregated.
|
|
101
|
+
* @param {FilesConfig} filesConfig - An object that defines the configuration for each file field, including whether
|
|
102
|
+
* the field supports multiple files.
|
|
103
|
+
* @return {Record<string, File | File[] | null>} A record where keys correspond to the configured fields, and values
|
|
104
|
+
* are either a single file, an array of files, or null if no files match the field.
|
|
105
|
+
*/
|
|
106
|
+
export declare function aggregateFiles(files: File[], filesConfig: FilesConfig): Record<string, File | File[] | null>;
|