@nuxodin/item 0.6.8 → 0.6.10

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxodin/item",
3
- "version": "0.6.8",
3
+ "version": "0.6.10",
4
4
  "description": "Reactive state library",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -37,12 +37,12 @@ export function schemaFromField(row) {
37
37
  } else if (type === 'date') {
38
38
  prop.type = 'string'
39
39
  prop.format = 'date'
40
- } else if (type.startsWith('time') || dataType.startsWith('time')) {
41
- prop.type = 'string'
42
- prop.format = 'time'
43
40
  } else if (type.startsWith('timestamp') || dataType.startsWith('timestamp')) {
44
41
  prop.type = 'string'
45
42
  prop.format = 'date-time'
43
+ } else if (type.startsWith('time') || dataType.startsWith('time')) {
44
+ prop.type = 'string'
45
+ prop.format = 'time'
46
46
  } else if (type === 'json' || type === 'jsonb') prop.type = 'object'
47
47
  else prop.type = 'string'
48
48
 
@@ -50,7 +50,7 @@ function createIndex(table, name, kind) {
50
50
 
51
51
  async function tableIndexes(query, table) {
52
52
  const primaryRows = await queryRows(query, `
53
- SELECT con.conname, array_agg(a.attname ORDER BY u.ord) AS columns
53
+ SELECT con.conname, json_agg(a.attname ORDER BY u.ord) AS columns
54
54
  FROM pg_constraint con
55
55
  JOIN pg_class t ON t.oid = con.conrelid
56
56
  JOIN pg_namespace n ON n.oid = t.relnamespace
@@ -13,7 +13,12 @@ const capacity = {
13
13
  maxLength: (need, have) => have >= need,
14
14
  }
15
15
 
16
- const structural = ['format', 'contentEncoding', 'x-index', 'default']
16
+ const structural = ['contentEncoding', 'x-index', 'default']
17
+
18
+ // Only these three formats become a column type in any dialect. `email`, `uri` and the rest are
19
+ // the application's business — a column cannot carry them, so they can never need DDL.
20
+ const temporal = new Set(['date', 'time', 'date-time'])
21
+ const columnFormat = (prop) => temporal.has(prop.format) ? prop.format : undefined
17
22
 
18
23
  /** @param dialectStructural properties this dialect renders too, e.g. 'multipleOf' on MySQL. */
19
24
  export function fieldNeedsDdl(next, curr, dialectStructural = []) {
@@ -23,6 +28,7 @@ export function fieldNeedsDdl(next, curr, dialectStructural = []) {
23
28
  if (need !== undefined && have !== undefined && !holds(need, have)) return true
24
29
  }
25
30
  if (schemaType(next) !== schemaType(curr)) return true
31
+ if (columnFormat(next) !== columnFormat(curr)) return true
26
32
  if (!!next['x-autoincrement'] !== !!curr['x-autoincrement']) return true
27
33
  return [...structural, ...dialectStructural].some(prop => next[prop] !== curr[prop])
28
34
  }