@atscript/db-mysql 0.1.168 → 0.1.170

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/dist/plugin.cjs CHANGED
@@ -1,6 +1,96 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_annotation_values = require("./annotation-values-DS1rF0tw.cjs");
2
3
  let _atscript_core = require("@atscript/core");
3
4
  //#region src/plugin/annotations.ts
5
+ /** Common storage engines, offered by completion; any engine the server has is accepted. */
6
+ const ENGINES = [
7
+ "InnoDB",
8
+ "MyISAM",
9
+ "MEMORY",
10
+ "CSV",
11
+ "ARCHIVE",
12
+ "BLACKHOLE",
13
+ "MERGE",
14
+ "FEDERATED",
15
+ "NDB",
16
+ "ROCKSDB",
17
+ "Aria"
18
+ ];
19
+ /** MySQL 8 character sets, offered by completion; any character set the server has is accepted. */
20
+ const CHARSETS = [
21
+ "utf8mb4",
22
+ "utf8mb3",
23
+ "utf8",
24
+ "latin1",
25
+ "ascii",
26
+ "binary",
27
+ "utf16",
28
+ "utf16le",
29
+ "utf32",
30
+ "ucs2",
31
+ "latin2",
32
+ "latin5",
33
+ "latin7",
34
+ "cp1250",
35
+ "cp1251",
36
+ "cp1256",
37
+ "cp1257",
38
+ "cp850",
39
+ "cp852",
40
+ "cp866",
41
+ "cp932",
42
+ "koi8r",
43
+ "koi8u",
44
+ "greek",
45
+ "hebrew",
46
+ "armscii8",
47
+ "geostd8",
48
+ "tis620",
49
+ "big5",
50
+ "gbk",
51
+ "gb2312",
52
+ "gb18030",
53
+ "sjis",
54
+ "ujis",
55
+ "eucjpms",
56
+ "euckr",
57
+ "macroman",
58
+ "macce",
59
+ "dec8",
60
+ "hp8",
61
+ "keybcs2",
62
+ "swe7"
63
+ ];
64
+ const ON_UPDATE_CANDIDATES = [
65
+ {
66
+ value: "CURRENT_TIMESTAMP",
67
+ documentation: "the column's own precision"
68
+ },
69
+ {
70
+ value: "CURRENT_TIMESTAMP(3)",
71
+ documentation: "milliseconds — a TIMESTAMP(3) / DATETIME(3) column"
72
+ },
73
+ {
74
+ value: "CURRENT_TIMESTAMP(6)",
75
+ documentation: "microseconds — a TIMESTAMP(6) / DATETIME(6) column"
76
+ }
77
+ ];
78
+ /**
79
+ * An engine / character set name goes into the DDL as written: only a bare
80
+ * name is accepted at compile time; a name the server does not have fails
81
+ * the schema sync with MySQL's own error.
82
+ */
83
+ function nameProblem(what) {
84
+ return (_token, args) => {
85
+ const arg = args[0];
86
+ if (!arg || require_annotation_values.MYSQL_NAME_RE.test(arg.text)) return [];
87
+ return [{
88
+ message: `@db.mysql.${what} takes a ${what === "engine" ? "storage engine" : "character set"} name (letters, digits, _), got '${arg.text}'`,
89
+ severity: 1,
90
+ range: arg.range
91
+ }];
92
+ };
93
+ }
4
94
  /**
5
95
  * MySQL-specific annotations.
6
96
  *
@@ -12,40 +102,30 @@ let _atscript_core = require("@atscript/core");
12
102
  */
13
103
  const annotations = {
14
104
  engine: new _atscript_core.AnnotationSpec({
15
- description: "Specifies the MySQL storage engine.\n\n**Default:** `\"InnoDB\"`\n\n```atscript\n@db.mysql.engine \"MyISAM\"\nexport interface Logs { ... }\n```",
105
+ description: "Specifies the MySQL storage engine.\n\n**Default:** `\"InnoDB\"`\n\n```atscript\n@db.mysql.engine \"MyISAM\"\nexport interface Logs { ... }\n```\n\nAny engine the server provides is accepted; an unknown one fails the schema sync.",
16
106
  nodeType: ["interface"],
17
107
  passedWhenReferred: false,
18
108
  multiple: false,
19
109
  argument: {
20
110
  name: "engine",
21
111
  type: "string",
22
- values: [
23
- "InnoDB",
24
- "MyISAM",
25
- "MEMORY",
26
- "CSV",
27
- "ARCHIVE"
28
- ],
29
- description: "MySQL storage engine name."
30
- }
112
+ description: "MySQL storage engine name.",
113
+ valueScope: () => ENGINES.map((value) => ({ value }))
114
+ },
115
+ validate: nameProblem("engine")
31
116
  }),
32
117
  charset: new _atscript_core.AnnotationSpec({
33
- description: "Specifies the character set for the table or column.\n\n**Default:** `\"utf8mb4\"`\n\n```atscript\n@db.mysql.charset \"latin1\"\nexport interface Legacy { ... }\n```",
118
+ description: "Specifies the character set for the table or column.\n\n**Default:** `\"utf8mb4\"`\n\n```atscript\n@db.mysql.charset \"latin1\"\nexport interface Legacy { ... }\n```\n\nAny character set the server provides is accepted; an unknown one fails the schema sync.",
34
119
  nodeType: ["interface", "prop"],
35
120
  passedWhenReferred: false,
36
121
  multiple: false,
37
122
  argument: {
38
123
  name: "charset",
39
124
  type: "string",
40
- values: [
41
- "utf8mb4",
42
- "utf8",
43
- "latin1",
44
- "ascii",
45
- "binary"
46
- ],
47
- description: "MySQL character set name."
48
- }
125
+ description: "MySQL character set name.",
126
+ valueScope: () => CHARSETS.map((value) => ({ value }))
127
+ },
128
+ validate: nameProblem("charset")
49
129
  }),
50
130
  collate: new _atscript_core.AnnotationSpec({
51
131
  description: "Specifies a native MySQL collation (overrides portable `@db.column.collate`).\n\n```atscript\n@db.mysql.collate \"utf8mb4_turkish_ci\"\nname: string\n```",
@@ -76,15 +156,24 @@ const annotations = {
76
156
  }
77
157
  }),
78
158
  onUpdate: new _atscript_core.AnnotationSpec({
79
- description: "Sets the MySQL ON UPDATE clause for a column.\n\n```atscript\n@db.mysql.onUpdate \"CURRENT_TIMESTAMP\"\nupdatedAt: number.timestamp\n```",
159
+ description: "Sets the MySQL ON UPDATE clause for a column: `CURRENT_TIMESTAMP`, optionally with a precision. Without one the column's own precision is used; a precision must match the column's (`@db.mysql.type \"TIMESTAMP(3)\"` for `CURRENT_TIMESTAMP(3)`).\n\n```atscript\n@db.mysql.type \"TIMESTAMP(3)\"\n@db.default.now\n@db.mysql.onUpdate \"CURRENT_TIMESTAMP(3)\"\nupdatedAt: number.timestamp\n```",
80
160
  nodeType: ["prop"],
81
161
  passedWhenReferred: false,
82
162
  multiple: false,
83
163
  argument: {
84
164
  name: "expression",
85
165
  type: "string",
86
- values: ["CURRENT_TIMESTAMP"],
87
- description: "Expression to evaluate on row update."
166
+ description: "`CURRENT_TIMESTAMP` or `CURRENT_TIMESTAMP(n)` (n = 0–6; `NOW()`, `LOCALTIMESTAMP` and `LOCALTIME` are synonyms).",
167
+ valueScope: () => ON_UPDATE_CANDIDATES
168
+ },
169
+ validate(_token, args) {
170
+ const arg = args[0];
171
+ if (!arg || require_annotation_values.MYSQL_ON_UPDATE_RE.test(arg.text.trim())) return [];
172
+ return [{
173
+ message: `@db.mysql.onUpdate takes CURRENT_TIMESTAMP, optionally with a precision 0–6 (CURRENT_TIMESTAMP(3)), got '${arg.text}'`,
174
+ severity: 1,
175
+ range: arg.range
176
+ }];
88
177
  }
89
178
  })
90
179
  };
package/dist/plugin.mjs CHANGED
@@ -1,5 +1,95 @@
1
+ import { n as MYSQL_ON_UPDATE_RE, t as MYSQL_NAME_RE } from "./annotation-values-CsjIErsL.mjs";
1
2
  import { AnnotationSpec } from "@atscript/core";
2
3
  //#region src/plugin/annotations.ts
4
+ /** Common storage engines, offered by completion; any engine the server has is accepted. */
5
+ const ENGINES = [
6
+ "InnoDB",
7
+ "MyISAM",
8
+ "MEMORY",
9
+ "CSV",
10
+ "ARCHIVE",
11
+ "BLACKHOLE",
12
+ "MERGE",
13
+ "FEDERATED",
14
+ "NDB",
15
+ "ROCKSDB",
16
+ "Aria"
17
+ ];
18
+ /** MySQL 8 character sets, offered by completion; any character set the server has is accepted. */
19
+ const CHARSETS = [
20
+ "utf8mb4",
21
+ "utf8mb3",
22
+ "utf8",
23
+ "latin1",
24
+ "ascii",
25
+ "binary",
26
+ "utf16",
27
+ "utf16le",
28
+ "utf32",
29
+ "ucs2",
30
+ "latin2",
31
+ "latin5",
32
+ "latin7",
33
+ "cp1250",
34
+ "cp1251",
35
+ "cp1256",
36
+ "cp1257",
37
+ "cp850",
38
+ "cp852",
39
+ "cp866",
40
+ "cp932",
41
+ "koi8r",
42
+ "koi8u",
43
+ "greek",
44
+ "hebrew",
45
+ "armscii8",
46
+ "geostd8",
47
+ "tis620",
48
+ "big5",
49
+ "gbk",
50
+ "gb2312",
51
+ "gb18030",
52
+ "sjis",
53
+ "ujis",
54
+ "eucjpms",
55
+ "euckr",
56
+ "macroman",
57
+ "macce",
58
+ "dec8",
59
+ "hp8",
60
+ "keybcs2",
61
+ "swe7"
62
+ ];
63
+ const ON_UPDATE_CANDIDATES = [
64
+ {
65
+ value: "CURRENT_TIMESTAMP",
66
+ documentation: "the column's own precision"
67
+ },
68
+ {
69
+ value: "CURRENT_TIMESTAMP(3)",
70
+ documentation: "milliseconds — a TIMESTAMP(3) / DATETIME(3) column"
71
+ },
72
+ {
73
+ value: "CURRENT_TIMESTAMP(6)",
74
+ documentation: "microseconds — a TIMESTAMP(6) / DATETIME(6) column"
75
+ }
76
+ ];
77
+ /**
78
+ * An engine / character set name goes into the DDL as written: only a bare
79
+ * name is accepted at compile time; a name the server does not have fails
80
+ * the schema sync with MySQL's own error.
81
+ */
82
+ function nameProblem(what) {
83
+ return (_token, args) => {
84
+ const arg = args[0];
85
+ if (!arg || MYSQL_NAME_RE.test(arg.text)) return [];
86
+ return [{
87
+ message: `@db.mysql.${what} takes a ${what === "engine" ? "storage engine" : "character set"} name (letters, digits, _), got '${arg.text}'`,
88
+ severity: 1,
89
+ range: arg.range
90
+ }];
91
+ };
92
+ }
3
93
  /**
4
94
  * MySQL-specific annotations.
5
95
  *
@@ -11,40 +101,30 @@ import { AnnotationSpec } from "@atscript/core";
11
101
  */
12
102
  const annotations = {
13
103
  engine: new AnnotationSpec({
14
- description: "Specifies the MySQL storage engine.\n\n**Default:** `\"InnoDB\"`\n\n```atscript\n@db.mysql.engine \"MyISAM\"\nexport interface Logs { ... }\n```",
104
+ description: "Specifies the MySQL storage engine.\n\n**Default:** `\"InnoDB\"`\n\n```atscript\n@db.mysql.engine \"MyISAM\"\nexport interface Logs { ... }\n```\n\nAny engine the server provides is accepted; an unknown one fails the schema sync.",
15
105
  nodeType: ["interface"],
16
106
  passedWhenReferred: false,
17
107
  multiple: false,
18
108
  argument: {
19
109
  name: "engine",
20
110
  type: "string",
21
- values: [
22
- "InnoDB",
23
- "MyISAM",
24
- "MEMORY",
25
- "CSV",
26
- "ARCHIVE"
27
- ],
28
- description: "MySQL storage engine name."
29
- }
111
+ description: "MySQL storage engine name.",
112
+ valueScope: () => ENGINES.map((value) => ({ value }))
113
+ },
114
+ validate: nameProblem("engine")
30
115
  }),
31
116
  charset: new AnnotationSpec({
32
- description: "Specifies the character set for the table or column.\n\n**Default:** `\"utf8mb4\"`\n\n```atscript\n@db.mysql.charset \"latin1\"\nexport interface Legacy { ... }\n```",
117
+ description: "Specifies the character set for the table or column.\n\n**Default:** `\"utf8mb4\"`\n\n```atscript\n@db.mysql.charset \"latin1\"\nexport interface Legacy { ... }\n```\n\nAny character set the server provides is accepted; an unknown one fails the schema sync.",
33
118
  nodeType: ["interface", "prop"],
34
119
  passedWhenReferred: false,
35
120
  multiple: false,
36
121
  argument: {
37
122
  name: "charset",
38
123
  type: "string",
39
- values: [
40
- "utf8mb4",
41
- "utf8",
42
- "latin1",
43
- "ascii",
44
- "binary"
45
- ],
46
- description: "MySQL character set name."
47
- }
124
+ description: "MySQL character set name.",
125
+ valueScope: () => CHARSETS.map((value) => ({ value }))
126
+ },
127
+ validate: nameProblem("charset")
48
128
  }),
49
129
  collate: new AnnotationSpec({
50
130
  description: "Specifies a native MySQL collation (overrides portable `@db.column.collate`).\n\n```atscript\n@db.mysql.collate \"utf8mb4_turkish_ci\"\nname: string\n```",
@@ -75,15 +155,24 @@ const annotations = {
75
155
  }
76
156
  }),
77
157
  onUpdate: new AnnotationSpec({
78
- description: "Sets the MySQL ON UPDATE clause for a column.\n\n```atscript\n@db.mysql.onUpdate \"CURRENT_TIMESTAMP\"\nupdatedAt: number.timestamp\n```",
158
+ description: "Sets the MySQL ON UPDATE clause for a column: `CURRENT_TIMESTAMP`, optionally with a precision. Without one the column's own precision is used; a precision must match the column's (`@db.mysql.type \"TIMESTAMP(3)\"` for `CURRENT_TIMESTAMP(3)`).\n\n```atscript\n@db.mysql.type \"TIMESTAMP(3)\"\n@db.default.now\n@db.mysql.onUpdate \"CURRENT_TIMESTAMP(3)\"\nupdatedAt: number.timestamp\n```",
79
159
  nodeType: ["prop"],
80
160
  passedWhenReferred: false,
81
161
  multiple: false,
82
162
  argument: {
83
163
  name: "expression",
84
164
  type: "string",
85
- values: ["CURRENT_TIMESTAMP"],
86
- description: "Expression to evaluate on row update."
165
+ description: "`CURRENT_TIMESTAMP` or `CURRENT_TIMESTAMP(n)` (n = 0–6; `NOW()`, `LOCALTIMESTAMP` and `LOCALTIME` are synonyms).",
166
+ valueScope: () => ON_UPDATE_CANDIDATES
167
+ },
168
+ validate(_token, args) {
169
+ const arg = args[0];
170
+ if (!arg || MYSQL_ON_UPDATE_RE.test(arg.text.trim())) return [];
171
+ return [{
172
+ message: `@db.mysql.onUpdate takes CURRENT_TIMESTAMP, optionally with a precision 0–6 (CURRENT_TIMESTAMP(3)), got '${arg.text}'`,
173
+ severity: 1,
174
+ range: arg.range
175
+ }];
87
176
  }
88
177
  })
89
178
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atscript/db-mysql",
3
- "version": "0.1.168",
3
+ "version": "0.1.170",
4
4
  "description": "MySQL adapter for @atscript/db with mysql2 driver support.",
5
5
  "keywords": [
6
6
  "atscript",
@@ -41,21 +41,21 @@
41
41
  "access": "public"
42
42
  },
43
43
  "dependencies": {
44
- "@atscript/db-sql-tools": "^0.1.168"
44
+ "@atscript/db-sql-tools": "^0.1.170"
45
45
  },
46
46
  "devDependencies": {
47
- "@atscript/core": "^0.2.4",
48
- "@atscript/typescript": "^0.2.4",
49
- "@uniqu/core": "^0.2.0",
47
+ "@atscript/core": "^0.2.7",
48
+ "@atscript/typescript": "^0.2.7",
49
+ "@uniqu/core": "^0.2.1",
50
50
  "mysql2": "^3.11.0",
51
- "unplugin-atscript": "^0.2.4"
51
+ "unplugin-atscript": "^0.2.7"
52
52
  },
53
53
  "peerDependencies": {
54
- "@atscript/core": "^0.2.4",
55
- "@atscript/typescript": "^0.2.4",
56
- "@uniqu/core": "^0.2.0",
54
+ "@atscript/core": "^0.2.7",
55
+ "@atscript/typescript": "^0.2.7",
56
+ "@uniqu/core": "^0.2.1",
57
57
  "mysql2": ">=3.0.0",
58
- "@atscript/db": "^0.1.168"
58
+ "@atscript/db": "^0.1.170"
59
59
  },
60
60
  "peerDependenciesMeta": {
61
61
  "mysql2": {