@appweaver/core 1.0.25 → 1.1.0
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/package.json +1 -1
- package/prisma/client/internal/class.js +4 -4
- package/prisma/client/internal/prismaNamespace.d.ts +1 -0
- package/prisma/client/internal/prismaNamespace.js +1 -0
- package/prisma/client/internal/prismaNamespaceBrowser.d.ts +1 -0
- package/prisma/client/internal/prismaNamespaceBrowser.js +1 -0
- package/prisma/client/models/File.d.ts +29 -1
- package/resource/resource-service.d.ts +0 -1
- package/resource/resource-service.js +2 -39
- package/security/auth-service.d.ts +16 -1
- package/security/auth-service.js +28 -0
- package/security/create-auth-resources.d.ts +2 -1
- package/security/oauth2/create-oauth2-plugin.d.ts +2 -7
- package/security/oauth2/create-oauth2-plugin.js +45 -1
- package/security/oauth2/oauth2-custom.d.ts +1 -0
- package/security/oauth2/oauth2-custom.js +2 -1
- package/security/oauth2/oauth2-facebook.js +3 -2
- package/security/oauth2/oauth2-google.js +2 -1
- package/seeder/seeder.d.ts +1 -1
- package/seeder/seeder.js +5 -5
- package/server/index.d.ts +1 -0
- package/server/index.js +1 -0
- package/server/register-route.js +13 -0
- package/server/virtual-projection.d.ts +26 -0
- package/server/virtual-projection.js +231 -0
- package/storage/file-service.js +21 -7
- package/storage/resources/file/model.js +7 -8
- package/types/auth.d.ts +17 -1
- package/types/generated.d.ts +5 -0
- package/utils/file-util.d.ts +9 -0
- package/utils/file-util.js +16 -0
- package/utils/index.d.ts +1 -0
- package/utils/index.js +1 -0
- package/utils/virtual-util.d.ts +11 -0
- package/utils/virtual-util.js +53 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.projectVirtualFields = projectVirtualFields;
|
|
4
|
+
const common_1 = require("@appweaver/common");
|
|
5
|
+
const context_1 = require("../context");
|
|
6
|
+
/**
|
|
7
|
+
* Projects virtual field values onto a resource object based on its model definition. Virtual fields with an output
|
|
8
|
+
* value function are evaluated against the resource, constant output values are assigned directly, and remaining
|
|
9
|
+
* required virtual fields receive their default value. Nested relation and file objects are projected recursively
|
|
10
|
+
* using their own model definitions.
|
|
11
|
+
*
|
|
12
|
+
* @param {Object} resource - The resource object to project virtual fields onto.
|
|
13
|
+
* @param {string} resourceName - The name of the resource model describing the object.
|
|
14
|
+
* @return {Object} A copy of the resource object with all virtual field values set.
|
|
15
|
+
*/
|
|
16
|
+
function projectVirtualFields(resource, resourceName) {
|
|
17
|
+
if (!resource) {
|
|
18
|
+
return resource;
|
|
19
|
+
}
|
|
20
|
+
const projectedVirtual = { ...resource };
|
|
21
|
+
const resourceModel = (0, context_1.injectModel)(resourceName, false);
|
|
22
|
+
const relationsModel = resourceModel?.relationsModel;
|
|
23
|
+
const filesModel = resourceModel?.filesModel;
|
|
24
|
+
// Set output or default value for virtual fields
|
|
25
|
+
for (const [fieldName, virtual] of Object.entries(resourceModel?.config?.virtual ?? {})) {
|
|
26
|
+
const outputValue = virtual.output?.value;
|
|
27
|
+
if ((0, common_1.isFunction)(outputValue)) {
|
|
28
|
+
projectedVirtual[fieldName] = outputValue(projectedVirtual);
|
|
29
|
+
}
|
|
30
|
+
else if (outputValue) {
|
|
31
|
+
projectedVirtual[fieldName] = outputValue;
|
|
32
|
+
}
|
|
33
|
+
else if (virtual.required !== false) {
|
|
34
|
+
projectedVirtual[fieldName] =
|
|
35
|
+
virtual.default ?? (0, common_1.defaultScalarValue)(virtual);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
// Recursively project virtual fields for nested relational objects
|
|
39
|
+
for (const key in projectedVirtual) {
|
|
40
|
+
const value = projectedVirtual[key];
|
|
41
|
+
const relationSchema = (0, common_1.extractSchemaProperties)(relationsModel, key);
|
|
42
|
+
const fileSchema = (0, common_1.extractSchemaProperties)(filesModel, key);
|
|
43
|
+
if ((0, common_1.isObject)(value) || ((0, common_1.isArray)(value) && (0, common_1.isObject)(value[0]))) {
|
|
44
|
+
const nestedResourceName = (0, common_1.extractResourceName)(relationSchema ?? fileSchema);
|
|
45
|
+
if (nestedResourceName) {
|
|
46
|
+
projectedVirtual[key] = (0, common_1.isArray)(value)
|
|
47
|
+
? value.map((item) => projectVirtualFields(item, nestedResourceName))
|
|
48
|
+
: projectVirtualFields(value, nestedResourceName);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return projectedVirtual;
|
|
53
|
+
}
|