ramdb2-cli 2.0.0-alpha.6 → 2.0.0-alpha.7
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/CHANGELOG.md +6 -0
- package/README.md +2 -1
- package/package.json +2 -2
- package/src/directives.js +2 -2
- package/src/generate/classes.js +13 -0
- package/src/generate/client.js +3 -0
- package/src/model.js +9 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# ramdb2-cli
|
|
2
2
|
|
|
3
|
+
## 2.0.0-alpha.7
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 8fa4d07: `@transient(getter: true)`: a getter of the class gives the value of the field, so a query filters and sorts on it (`static transientGetters`), and `RdbCrud` sorts its column by default. ramdb2-server refuses to start when the getter is missing, and refuses in a query a `@transient` resolved by GraphQL only (D62).
|
|
8
|
+
|
|
3
9
|
## 2.0.0-alpha.6
|
|
4
10
|
|
|
5
11
|
No changes in this release.
|
package/README.md
CHANGED
|
@@ -100,7 +100,7 @@ a directive in the wrong place, a missing or badly typed argument is an error.
|
|
|
100
100
|
| `@onDelete` | list | `action: CASCADE \| SET_ZERO \| RESTRICT \| NOTHING` | deletion policy of these objects |
|
|
101
101
|
| `@computed` | field | `depends: [String!]!` | a cached value, with the paths it depends on |
|
|
102
102
|
| `@pattern` | field | `regex: String!`, `message: String` | a validation rule |
|
|
103
|
-
| `@transient` | field | | a field of the API that is not stored |
|
|
103
|
+
| `@transient` | field | `getter: Boolean = false` | a field of the API that is not stored. `getter: true`: a getter of the class gives its value (written in the extended class), so a query filters and sorts on it, and ramdb2-server checks the getter at start. A scalar without arguments. Not indexed: a query reads the getter on every candidate object |
|
|
104
104
|
| `@sensitive` | field | | its value is masked in the logs of ramdb2-server (`"[REDACTED]"`) |
|
|
105
105
|
| `@private` | field | | stored and read by your code, but absent from the API: neither read, written nor queried (a password hash). Not with `!` when it would be required, nor with a FULLTEXT index |
|
|
106
106
|
| `@restricted` | field | | read through the API only when its permission allows it, object by object (`permissions.<Type>.fields` of ramdb2-server); served nullable. On a stored field, an object relation (with its foreign key), a computed or `@transient` field. A computed field that depends on it must be `@restricted` too |
|
|
@@ -263,6 +263,7 @@ as for `generate`). It writes, in `--dest`:
|
|
|
263
263
|
API.
|
|
264
264
|
- `transient`: the `@transient` fields of a scalar type (scalar, enum, custom scalar, list of them), always loaded
|
|
265
265
|
with the object. One of an object type, or with a required argument, is left out with a warning.
|
|
266
|
+
- `transientGetters`: the `@transient(getter: true)` fields, sorted by default in a `RdbCrud`.
|
|
266
267
|
- `fullText`: the fields of the `FULLTEXT` index, in the order of the schema (`[]` without one), for a search with `$text`.
|
|
267
268
|
- `generatedRules`: the same rules as the server (`required`, `pattern`, `oneOf`), plus `requiredKey('idProject')`
|
|
268
269
|
for a required object relation.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ramdb2-cli",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.7",
|
|
4
4
|
"description": "Code generator and project scaffolding for ramdb2 and ramdb2-server",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": "./src/index.js",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@vitejs/plugin-vue": "^6.0.10",
|
|
31
|
-
"ramdb2-core": "^2.0.0-alpha.
|
|
31
|
+
"ramdb2-core": "^2.0.0-alpha.7",
|
|
32
32
|
"vite": "^8.3.5",
|
|
33
33
|
"vue": "^3.5.44",
|
|
34
34
|
"vue-router": "^5.4.0"
|
package/src/directives.js
CHANGED
|
@@ -27,8 +27,8 @@ directive @computed(depends: [String!]!) on FIELD_DEFINITION
|
|
|
27
27
|
"Validation rule: the value must match the regular expression."
|
|
28
28
|
directive @pattern(regex: String!, message: String) on FIELD_DEFINITION
|
|
29
29
|
|
|
30
|
-
"Field of a persistent type that is not stored: resolved elsewhere."
|
|
31
|
-
directive @transient on FIELD_DEFINITION
|
|
30
|
+
"Field of a persistent type that is not stored: resolved elsewhere. getter: a getter of the class gives its value, so a query can filter and sort on it (D62)."
|
|
31
|
+
directive @transient(getter: Boolean = false) on FIELD_DEFINITION
|
|
32
32
|
|
|
33
33
|
"Field stored and readable in code, but absent from the GraphQL API: neither read, written nor queried (D47)."
|
|
34
34
|
directive @private on FIELD_DEFINITION
|
package/src/generate/classes.js
CHANGED
|
@@ -45,6 +45,12 @@ function generatedClass(type, model, code) {
|
|
|
45
45
|
lines.push(' // @restricted: read through the API only when permissions.<Type>.fields allows it (D58)')
|
|
46
46
|
lines.push(` static restrictedFields = [${type.restricted.map(quote).join(', ')}]`)
|
|
47
47
|
}
|
|
48
|
+
if (type.transient.length > 0) {
|
|
49
|
+
lines.push('')
|
|
50
|
+
lines.push(' // @transient: not stored. Those of transientGetters are getters of the class, filtered and sorted by a query (D62)')
|
|
51
|
+
lines.push(` static transient = [${type.transient.map(t => quote(t.name)).join(', ')}]`)
|
|
52
|
+
lines.push(` static transientGetters = [${type.transient.filter(t => t.getter).map(t => quote(t.name)).join(', ')}]`)
|
|
53
|
+
}
|
|
48
54
|
if (type.children.length > 0) {
|
|
49
55
|
lines.push('')
|
|
50
56
|
lines.push(' // The list relations: the table of their objects and the foreign key that points here')
|
|
@@ -271,6 +277,13 @@ function extendedClass(type) {
|
|
|
271
277
|
lines.push('')
|
|
272
278
|
lines.push(' // Integrity rules checked by delete(): (values, obj) => "" | message')
|
|
273
279
|
lines.push(' static deleteRules = []')
|
|
280
|
+
for (const transient of type.transient.filter(t => t.getter)) {
|
|
281
|
+
lines.push('')
|
|
282
|
+
lines.push(` /** @returns {${transient.jsType}} @transient(getter: true): read by GraphQL and by the queries (D62) */`)
|
|
283
|
+
lines.push(` get ${transient.name}() {`)
|
|
284
|
+
lines.push(` throw new Error('${type.name}.${transient.name} is not written yet')`)
|
|
285
|
+
lines.push(' }')
|
|
286
|
+
}
|
|
274
287
|
for (const computed of type.computed) {
|
|
275
288
|
lines.push('')
|
|
276
289
|
lines.push(` /** @returns {${computed.jsType}} depends on ${computed.depends.join(', ')} */`)
|
package/src/generate/client.js
CHANGED
|
@@ -70,6 +70,9 @@ function generatedClass(type, model) {
|
|
|
70
70
|
lines.push('')
|
|
71
71
|
lines.push(` static transient = [${transient.map(t => quote(t.name)).join(', ')}]`)
|
|
72
72
|
lines.push('')
|
|
73
|
+
lines.push(' // Getters of the server class: filtered and sorted by a query (D62 of ramdb2)')
|
|
74
|
+
lines.push(` static transientGetters = [${transient.filter(t => t.getter).map(t => quote(t.name)).join(', ')}]`)
|
|
75
|
+
lines.push('')
|
|
73
76
|
lines.push(` static fullText = [${fullText.map(quote).join(', ')}]`)
|
|
74
77
|
lines.push('')
|
|
75
78
|
const relations = [
|
package/src/model.js
CHANGED
|
@@ -64,6 +64,8 @@ export class SchemaError extends Error {
|
|
|
64
64
|
* @property {string | undefined} description
|
|
65
65
|
* @property {boolean} scalar scalar, enum, custom scalar or a list of them (a type of another layer is a scalar)
|
|
66
66
|
* @property {string[]} requiredArgs arguments without a default value
|
|
67
|
+
* @property {boolean} getter @transient(getter: true): a getter of the class gives its value, a query filters and
|
|
68
|
+
* sorts on it (D62)
|
|
67
69
|
*
|
|
68
70
|
* @typedef {object} Index
|
|
69
71
|
* @property {string} name
|
|
@@ -158,7 +160,8 @@ export function readSchema(source) {
|
|
|
158
160
|
const list = isListType(isNonNullType(gqlField.type) ? gqlField.type.ofType : gqlField.type)
|
|
159
161
|
const description = gqlField.description ?? undefined
|
|
160
162
|
const computed = values('computed', node)
|
|
161
|
-
const
|
|
163
|
+
const transientArgs = values('transient', node)
|
|
164
|
+
const transient = transientArgs !== undefined
|
|
162
165
|
const pattern = values('pattern', node)
|
|
163
166
|
const onDelete = values('onDelete', node)
|
|
164
167
|
const field = values('field', node)
|
|
@@ -189,7 +192,12 @@ export function readSchema(source) {
|
|
|
189
192
|
description,
|
|
190
193
|
scalar: isLeafType(named),
|
|
191
194
|
requiredArgs: gqlField.args.filter(arg => isNonNullType(arg.type) && arg.defaultValue === undefined).map(arg => arg.name),
|
|
195
|
+
getter: transientArgs.getter === true,
|
|
192
196
|
})
|
|
197
|
+
// A getter reads the object alone: one scalar value, no argument (filtered and sorted by the engine)
|
|
198
|
+
if (transientArgs.getter === true && (!isLeafType(named) || list || gqlField.args.length > 0)) {
|
|
199
|
+
errors.push(`${at(name)}: @transient(getter: true) only goes on a scalar field without arguments`)
|
|
200
|
+
}
|
|
193
201
|
continue
|
|
194
202
|
}
|
|
195
203
|
if (name === 'id') {
|