ramdb2-cli 2.0.0-alpha.10 → 2.0.0-alpha.11

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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # ramdb2-cli
2
2
 
3
+ ## 2.0.0-alpha.11
4
+
5
+ ### Patch Changes
6
+
7
+ - cf18bd4: Dates stored as Unix seconds (D64 of ramdb2, D25 of the client). The directives `@date` (a day, without time zone: the seconds of its midnight UTC) and `@datetime` (an instant) go on an `Int` field; 0 or null is no date. The generated client class lists them in `static dates`. `ramdb2-core` and `ramdb2-client` export the same date functions: `day`, `dayText`, `dateTime`, `dateTimeText`, `today(timeZone)`, `dayOf`, `addDays`, `addMonths`… ramdb2-vue shows them as `YYYY-MM-DD` (`HH:MM:SS`), sorts and filters on the seconds, searches a typed day, month or year, exports real Excel dates and CSV text, and types them with the date input of the browser; option `dates: { timeZone, formatDate, formatDateTime }` of the site. The schema of `ramdb2-cli new` gets `Task.due: Int @date`.
8
+
3
9
  ## 2.0.0-alpha.10
4
10
 
5
11
  No changes in this release.
package/README.md CHANGED
@@ -103,6 +103,8 @@ a directive in the wrong place, a missing or badly typed argument is an error.
103
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
+ | `@date` | field | | an `Int` that is a day of the calendar, without time zone: the Unix seconds of its midnight UTC; 0 or null for no date. ramdb2-vue shows, searches, exports and types it as a date |
107
+ | `@datetime` | field | | an `Int` that is an instant: Unix seconds; 0 or null for no date. Shown and typed in the time zone of the site |
106
108
  | `@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 |
107
109
 
108
110
  ### How the fields are read
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ramdb2-cli",
3
- "version": "2.0.0-alpha.10",
3
+ "version": "2.0.0-alpha.11",
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.10",
31
+ "ramdb2-core": "^2.0.0-alpha.11",
32
32
  "vite": "^8.3.5",
33
33
  "vue": "^3.5.44",
34
34
  "vue-router": "^5.4.0"
package/src/directives.js CHANGED
@@ -36,10 +36,16 @@ directive @private on FIELD_DEFINITION
36
36
  "Field readable only when the permission of the server allows it, for each object (D58): served nullable."
37
37
  directive @restricted on FIELD_DEFINITION
38
38
 
39
+ "An Int that is a day of the calendar, without time zone: the Unix seconds of its midnight UTC; 0 or null for no date (D64). Shown, searched, exported and typed as a date by ramdb2-vue."
40
+ directive @date on FIELD_DEFINITION
41
+
42
+ "An Int that is an instant: Unix seconds; 0 or null for no date (D64). Shown, searched, exported and typed as a date and a time by ramdb2-vue."
43
+ directive @datetime on FIELD_DEFINITION
44
+
39
45
  "Value masked in the logs. Kept in the schema served by Apollo: ramdb2-server reads it."
40
46
  directive @sensitive on FIELD_DEFINITION | INPUT_FIELD_DEFINITION | ARGUMENT_DEFINITION
41
47
  `
42
48
 
43
49
  /** Names of the directives above removed from the schema served by Apollo: all but @sensitive. */
44
- export const DIRECTIVE_NAMES = new Set(['persistent', 'group', 'index', 'field', 'onDelete', 'computed', 'pattern', 'transient', 'private', 'restricted'])
50
+ export const DIRECTIVE_NAMES = new Set(['persistent', 'group', 'index', 'field', 'onDelete', 'computed', 'pattern', 'transient', 'private', 'restricted', 'date', 'datetime'])
45
51
  export const INTERNAL_TYPES = new Set(['RamdbIndexType', 'RamdbOnDelete'])
@@ -75,6 +75,10 @@ function generatedClass(type, model) {
75
75
  lines.push('')
76
76
  lines.push(` static fullText = [${fullText.map(quote).join(', ')}]`)
77
77
  lines.push('')
78
+ // The Int fields that are dates, in Unix seconds (D64 of ramdb2): a day (date) or an instant (datetime)
79
+ const dates = Object.entries(type.dates).filter(([name]) => !privateFields.includes(name))
80
+ lines.push(` static dates = {${dates.length ? ' ' + dates.map(([name, kind]) => `${name}: '${kind}'`).join(', ') + ' ' : ''}}`)
81
+ lines.push('')
78
82
  const relations = [
79
83
  ...type.parents.map(p => ` ${p.name}: { type: '${p.target}', key: '${p.fk}' },`),
80
84
  ...type.children.map(c => ` ${c.name}: { type: '${c.target}', key: '${c.fk}', list: true },`),
package/src/model.js CHANGED
@@ -86,6 +86,8 @@ export class SchemaError extends Error {
86
86
  * @property {Index[]} indexes declared with @index (the inverse indexes of the foreign keys are automatic)
87
87
  * @property {string[]} restricted @restricted fields (D58): stored fields, relations with their foreign key,
88
88
  * computed and @transient fields
89
+ * @property {Record<string, 'date' | 'datetime'>} dates the Int fields of @date and @datetime (D64): stored, computed
90
+ * or @transient
89
91
  *
90
92
  * @typedef {object} Model
91
93
  * @property {Type[]} types
@@ -141,6 +143,7 @@ export function readSchema(source) {
141
143
  transient: [],
142
144
  indexes: [],
143
145
  restricted: [],
146
+ dates: {},
144
147
  _gql: gqlType,
145
148
  }
146
149
  types.push(type)
@@ -169,6 +172,13 @@ export function readSchema(source) {
169
172
  if (isPrivate && (computed !== undefined || transient || name === 'id' || isObjectType(named) || list)) {
170
173
  errors.push(`${at(name)}: @private only goes on a stored scalar field`)
171
174
  }
175
+ // A date is an Int of Unix seconds, whatever the field: stored, computed or @transient (D64)
176
+ const dateKinds = ['date', 'datetime'].filter(kind => values(kind, node) !== undefined)
177
+ if (dateKinds.length > 1) errors.push(`${at(name)}: @date and @datetime exclude each other`)
178
+ else if (dateKinds.length === 1) {
179
+ if (named.name !== 'Int' || list || name === 'id') errors.push(`${at(name)}: @${dateKinds[0]} only goes on an Int field (Unix seconds), not on the id`)
180
+ else type.dates[name] = dateKinds[0]
181
+ }
172
182
  if (values('restricted', node) !== undefined) {
173
183
  if (name === 'id') errors.push(`${at(name)}: the id cannot be @restricted`)
174
184
  else if (isPrivate) errors.push(`${at(name)}: @private and @restricted exclude each other`)
package/src/new.js CHANGED
@@ -148,6 +148,8 @@ type Task @persistent {
148
148
  project: Project!
149
149
  name: String!
150
150
  hours: Float!
151
+ "Due day: the Unix seconds of its midnight UTC, null for no date (@date, D64)"
152
+ due: Int @date
151
153
  }
152
154
 
153
155
  enum UserRole { USER ADMIN }