velocious 1.0.473 → 1.0.474
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/build/authorization/base-resource.js +99 -0
- package/build/configuration-types.js +3 -2
- package/build/environment-handlers/node/cli/commands/generate/frontend-models.js +1 -1
- package/build/frontend-model-controller.js +12 -12
- package/build/frontend-model-resource/base-resource.js +254 -46
- package/build/frontend-model-resource/velocious-attachment-resource.js +0 -3
- package/build/frontend-models/resource-definition.js +96 -21
- package/build/src/authorization/base-resource.d.ts +41 -0
- package/build/src/authorization/base-resource.d.ts.map +1 -1
- package/build/src/authorization/base-resource.js +88 -1
- package/build/src/configuration-types.d.ts +15 -3
- package/build/src/configuration-types.d.ts.map +1 -1
- package/build/src/configuration-types.js +4 -3
- package/build/src/environment-handlers/node/cli/commands/generate/frontend-models.js +2 -2
- package/build/src/frontend-model-controller.js +13 -13
- package/build/src/frontend-model-resource/base-resource.d.ts +67 -0
- package/build/src/frontend-model-resource/base-resource.d.ts.map +1 -1
- package/build/src/frontend-model-resource/base-resource.js +242 -54
- package/build/src/frontend-model-resource/velocious-attachment-resource.d.ts +0 -2
- package/build/src/frontend-model-resource/velocious-attachment-resource.d.ts.map +1 -1
- package/build/src/frontend-model-resource/velocious-attachment-resource.js +1 -3
- package/build/src/frontend-models/resource-definition.d.ts.map +1 -1
- package/build/src/frontend-models/resource-definition.js +83 -25
- package/package.json +1 -1
- package/scripts/tensorbuzz-retry +21 -0
- package/src/authorization/base-resource.js +99 -0
- package/src/configuration-types.js +3 -2
- package/src/environment-handlers/node/cli/commands/generate/frontend-models.js +1 -1
- package/src/frontend-model-controller.js +12 -12
- package/src/frontend-model-resource/base-resource.js +254 -46
- package/src/frontend-model-resource/velocious-attachment-resource.js +0 -3
- package/src/frontend-models/resource-definition.js +96 -21
|
@@ -5,6 +5,25 @@ import FrontendModelBaseResource from "../frontend-model-resource/base-resource.
|
|
|
5
5
|
import restArgsError from "../utils/rest-args-error.js"
|
|
6
6
|
import {validateFrontendModelResourceCommandName} from "./resource-config-validation.js"
|
|
7
7
|
|
|
8
|
+
const BASE_FRONTEND_MODEL_ABILITY_ACTIONS = ["create", "destroy", "read", "update"]
|
|
9
|
+
const RESOURCE_STATIC_CONFIG_KEYS = new Set([
|
|
10
|
+
"abilities",
|
|
11
|
+
"attachments",
|
|
12
|
+
"attributes",
|
|
13
|
+
"builtInCollectionCommands",
|
|
14
|
+
"builtInMemberCommands",
|
|
15
|
+
"collectionCommands",
|
|
16
|
+
"commands",
|
|
17
|
+
"memberCommands",
|
|
18
|
+
"modelName",
|
|
19
|
+
"ModelClass",
|
|
20
|
+
"primaryKey",
|
|
21
|
+
"relationships",
|
|
22
|
+
"server",
|
|
23
|
+
"SharedResource",
|
|
24
|
+
"translatedAttributes"
|
|
25
|
+
])
|
|
26
|
+
|
|
8
27
|
/**
|
|
9
28
|
* Runs the frontendModelResourcesForBackendProject helper.
|
|
10
29
|
* @param {import("../configuration-types.js").BackendProjectConfiguration} backendProject - Backend project config.
|
|
@@ -50,9 +69,74 @@ export function frontendModelResourceClassFromDefinition(resourceDefinition) {
|
|
|
50
69
|
export function frontendModelResourceConfigurationFromDefinition(resourceDefinition) {
|
|
51
70
|
if (!frontendModelResourceDefinitionIsClass(resourceDefinition)) return null
|
|
52
71
|
|
|
72
|
+
assertResourceConfigIsFrameworkDefined(resourceDefinition)
|
|
73
|
+
|
|
53
74
|
return normalizeFrontendModelResourceConfiguration(resourceDefinition.resourceConfig())
|
|
54
75
|
}
|
|
55
76
|
|
|
77
|
+
/**
|
|
78
|
+
* Ensures resources use declarative static config properties instead of overriding resourceConfig().
|
|
79
|
+
* @param {import("../configuration-types.js").FrontendModelResourceClassType} ResourceClass - Resource class.
|
|
80
|
+
* @param {Set<import("../configuration-types.js").FrontendModelResourceClassType>} [visited] - Already inspected shared resources.
|
|
81
|
+
* @returns {void}
|
|
82
|
+
*/
|
|
83
|
+
function assertResourceConfigIsFrameworkDefined(ResourceClass, visited = new Set()) {
|
|
84
|
+
if (visited.has(ResourceClass)) return
|
|
85
|
+
|
|
86
|
+
visited.add(ResourceClass)
|
|
87
|
+
assertKnownResourceStaticConfigProperties(ResourceClass)
|
|
88
|
+
|
|
89
|
+
const owner = staticMethodOwnerFor(ResourceClass, "resourceConfig")
|
|
90
|
+
|
|
91
|
+
if (owner && owner !== FrontendModelBaseResource) {
|
|
92
|
+
throw new Error(`${ResourceClass.name} overrides static resourceConfig(), which is not supported. Use static resource properties instead.`)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const SharedResource = ResourceClass.sharedResourceClass()
|
|
96
|
+
|
|
97
|
+
if (SharedResource) assertResourceConfigIsFrameworkDefined(SharedResource, visited)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Ensures declarative static resource config does not silently ignore typos or removed keys.
|
|
102
|
+
* @param {import("../configuration-types.js").FrontendModelResourceClassType} ResourceClass - Resource class.
|
|
103
|
+
* @returns {void}
|
|
104
|
+
*/
|
|
105
|
+
function assertKnownResourceStaticConfigProperties(ResourceClass) {
|
|
106
|
+
let currentClass = ResourceClass
|
|
107
|
+
|
|
108
|
+
while (currentClass && currentClass !== FrontendModelBaseResource && currentClass !== Function.prototype) {
|
|
109
|
+
/** @type {Record<string, ?>} */
|
|
110
|
+
const unknownStaticConfig = {}
|
|
111
|
+
|
|
112
|
+
for (const key of Object.keys(currentClass)) {
|
|
113
|
+
if (!RESOURCE_STATIC_CONFIG_KEYS.has(key)) unknownStaticConfig[key] = /** @type {Record<string, ?>} */ (/** @type {unknown} */ (currentClass))[key]
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
restArgsError(unknownStaticConfig)
|
|
117
|
+
|
|
118
|
+
currentClass = Object.getPrototypeOf(currentClass)
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Locates which constructor owns a static method implementation.
|
|
124
|
+
* @param {import("../configuration-types.js").FrontendModelResourceClassType} ResourceClass - Resource class.
|
|
125
|
+
* @param {string} methodName - Method name.
|
|
126
|
+
* @returns {import("../configuration-types.js").FrontendModelResourceClassType | typeof FrontendModelBaseResource | null} - Class that owns the static method.
|
|
127
|
+
*/
|
|
128
|
+
function staticMethodOwnerFor(ResourceClass, methodName) {
|
|
129
|
+
let currentClass = ResourceClass
|
|
130
|
+
|
|
131
|
+
while (currentClass && currentClass !== Function.prototype) {
|
|
132
|
+
if (Object.prototype.hasOwnProperty.call(currentClass, methodName)) return currentClass
|
|
133
|
+
|
|
134
|
+
currentClass = Object.getPrototypeOf(currentClass)
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return null
|
|
138
|
+
}
|
|
139
|
+
|
|
56
140
|
/**
|
|
57
141
|
* Runs normalize frontend model resource configuration.
|
|
58
142
|
* @param {import("../configuration-types.js").FrontendModelResourceConfiguration} resourceConfiguration - Raw resource configuration.
|
|
@@ -102,36 +186,27 @@ function normalizeFrontendModelResourceConfiguration(resourceConfiguration) {
|
|
|
102
186
|
* @returns {Record<string, string>} - Normalized abilities config.
|
|
103
187
|
*/
|
|
104
188
|
function normalizeFrontendModelResourceAbilities(abilities) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
189
|
+
const normalized = defaultCrudAbilities()
|
|
190
|
+
|
|
191
|
+
if (abilities === undefined) return normalized
|
|
108
192
|
|
|
109
193
|
if (!Array.isArray(abilities)) {
|
|
110
194
|
throw new Error("Resource abilities must be an array of action names. Object form is no longer supported.")
|
|
111
195
|
}
|
|
112
196
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
find: "manage",
|
|
118
|
-
index: "manage",
|
|
119
|
-
update: "manage"
|
|
120
|
-
}
|
|
197
|
+
const duplicatedBaseAbilities = abilities.filter((ability) => BASE_FRONTEND_MODEL_ABILITY_ACTIONS.includes(ability))
|
|
198
|
+
|
|
199
|
+
if (duplicatedBaseAbilities.length > 0) {
|
|
200
|
+
throw new Error(`Resource abilities must not include base actions: ${duplicatedBaseAbilities.join(", ")}`)
|
|
121
201
|
}
|
|
122
202
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
203
|
+
for (const ability of abilities) {
|
|
204
|
+
if (typeof ability !== "string" || ability.length < 1) {
|
|
205
|
+
throw new Error("Resource abilities entries must be non-empty strings.")
|
|
206
|
+
}
|
|
127
207
|
|
|
128
|
-
|
|
129
|
-
if (abilities.includes("destroy")) normalized.destroy = "destroy"
|
|
130
|
-
if (abilities.includes("read")) {
|
|
131
|
-
normalized.find = "read"
|
|
132
|
-
normalized.index = "read"
|
|
208
|
+
normalized[ability] = ability
|
|
133
209
|
}
|
|
134
|
-
if (abilities.includes("update")) normalized.update = "update"
|
|
135
210
|
|
|
136
211
|
return normalized
|
|
137
212
|
}
|