@yongdall/document 0.1.0 → 0.3.0
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/hooks.yongdall.mjs +59 -0
- package/hooks.yongdall.mjs.map +1 -1
- package/package.json +4 -4
package/hooks.yongdall.mjs
CHANGED
|
@@ -49,6 +49,34 @@ const comparison = {
|
|
|
49
49
|
const eq = {
|
|
50
50
|
label: "=",
|
|
51
51
|
value(field, v, f) {
|
|
52
|
+
if (f.type === "bool") {
|
|
53
|
+
const list = new Set([v].flat().map((v) => {
|
|
54
|
+
if (v == null) return null;
|
|
55
|
+
if (typeof v !== "string") return Boolean(v);
|
|
56
|
+
switch (v.toLowerCase()) {
|
|
57
|
+
case "":
|
|
58
|
+
case "0":
|
|
59
|
+
case "n":
|
|
60
|
+
case "f":
|
|
61
|
+
case "no":
|
|
62
|
+
case "off":
|
|
63
|
+
case "false": return false;
|
|
64
|
+
}
|
|
65
|
+
return true;
|
|
66
|
+
}));
|
|
67
|
+
if (list.size === 0) return null;
|
|
68
|
+
if (list.size >= 3) return null;
|
|
69
|
+
if (list.size === 1) {
|
|
70
|
+
const [value] = list;
|
|
71
|
+
return Where.and(field, "=", value ?? null);
|
|
72
|
+
}
|
|
73
|
+
const [value] = [
|
|
74
|
+
true,
|
|
75
|
+
false,
|
|
76
|
+
null
|
|
77
|
+
].filter((v) => !list.has(v));
|
|
78
|
+
return Where.not(field, "=", value ?? null);
|
|
79
|
+
}
|
|
52
80
|
if (Array.isArray(v) && v.length > 1) return Where.and(field, "in", v);
|
|
53
81
|
const value = (Array.isArray(v) ? v[0] : v) ?? null;
|
|
54
82
|
return Where.and(field, value);
|
|
@@ -60,6 +88,22 @@ const eq = {
|
|
|
60
88
|
const eqArray = {
|
|
61
89
|
label: "=",
|
|
62
90
|
value(field, v, f) {
|
|
91
|
+
if (f.type === "bool") {
|
|
92
|
+
const list = new Set([v].flat().map((v) => {
|
|
93
|
+
if (typeof v !== "string") return Boolean(v);
|
|
94
|
+
switch (v.toLowerCase()) {
|
|
95
|
+
case "":
|
|
96
|
+
case "0":
|
|
97
|
+
case "n":
|
|
98
|
+
case "f":
|
|
99
|
+
case "no":
|
|
100
|
+
case "off":
|
|
101
|
+
case "false": return false;
|
|
102
|
+
}
|
|
103
|
+
return true;
|
|
104
|
+
}));
|
|
105
|
+
return Where.and(field, list);
|
|
106
|
+
}
|
|
63
107
|
const array = Array.isArray(v) ? v : [v];
|
|
64
108
|
return Where.and(field, array);
|
|
65
109
|
},
|
|
@@ -80,6 +124,14 @@ const filters = {
|
|
|
80
124
|
return Where.not(field, value);
|
|
81
125
|
}
|
|
82
126
|
},
|
|
127
|
+
ne: {
|
|
128
|
+
label: "≠",
|
|
129
|
+
value(field, v, f) {
|
|
130
|
+
if (Array.isArray(v) && v.length > 1) return Where.not(field, "in", v);
|
|
131
|
+
const value = (Array.isArray(v) ? v[0] : v) ?? null;
|
|
132
|
+
return Where.not(field, value);
|
|
133
|
+
}
|
|
134
|
+
},
|
|
83
135
|
"in": {
|
|
84
136
|
label: "∈",
|
|
85
137
|
value(field, v, f) {
|
|
@@ -104,6 +156,13 @@ const filters = {
|
|
|
104
156
|
const array = Array.isArray(v) ? v : [v];
|
|
105
157
|
return Where.not(field, array);
|
|
106
158
|
}
|
|
159
|
+
},
|
|
160
|
+
ne: {
|
|
161
|
+
label: "≠",
|
|
162
|
+
value(field, v, f) {
|
|
163
|
+
const array = Array.isArray(v) ? v : [v];
|
|
164
|
+
return Where.not(field, array);
|
|
165
|
+
}
|
|
107
166
|
}
|
|
108
167
|
},
|
|
109
168
|
"i16": comparison,
|
package/hooks.yongdall.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.yongdall.mjs","names":[],"sources":["../../packages/document/hooks/where.mjs"],"sourcesContent":["import { Where } from '@yongdall/model';\nimport { getUser } from '@yongdall/core';\n/** @import { WhereHook } from '@yongdall/core' */\n\n/**\n * @param {*} v\n */\nasync function getUserValue(v) {\n\tif (v == '<ME>') {\n\t\treturn await getUser() || '';\n\t}\n\treturn v ?? null;\n\n}\n/**\n * @param {*} v\n */\nasync function getUserValues(v) {\n\tconst users = [];\n\tfor (const u of Array.isArray(v) ? v : [v]) {\n\t\tusers.push(getUserValue(u));\n\t}\n\treturn Promise.all(users);\n}\n\n/** @type {WhereHook} */\nconst gt = {\n\tlabel: '>',\n\tvalue(field, v, f) {\n\t\tconst value = (Array.isArray(v) ? v[0] : v) ?? null;\n\t\treturn Where.and(field, '<', value);\n\t},\n};\n/** @type {WhereHook} */\nconst ge = {\n\tlabel: '≥',\n\tvalue(field, v, f) {\n\t\tconst value = (Array.isArray(v) ? v[0] : v) ?? null;\n\t\treturn Where.and(field, '>=', value);\n\t},\n};\n\n/** @type {WhereHook} */\nconst lt = {\n\tlabel: '<',\n\tvalue(field, v, f) {\n\t\tconst value = (Array.isArray(v) ? v[0] : v) ?? null;\n\t\treturn Where.and(field, '<', value);\n\t},\n};\n/** @type {WhereHook} */\nconst le = {\n\tlabel: '≤',\n\tvalue(field, v, f) {\n\t\tconst value = (Array.isArray(v) ? v[0] : v) ?? null;\n\t\treturn Where.and(field, '<=', value);\n\t},\n};\n\n/** @type {Record<string, WhereHook>} */\nconst comparison = {\n\t'>': gt,\n\t'>=': ge,\n\t'<': lt,\n\t'<=': le,\n\tgt, ge, lt, le\n};\n\n\n\n/** @type {WhereHook} */\nconst eq = {\n\tlabel: '=',\n\tvalue(field, v, f) {\n\t\tif (Array.isArray(v) && v.length > 1) {
|
|
1
|
+
{"version":3,"file":"hooks.yongdall.mjs","names":[],"sources":["../../packages/document/hooks/where.mjs"],"sourcesContent":["import { Where } from '@yongdall/model';\nimport { getUser } from '@yongdall/core';\n/** @import { WhereHook } from '@yongdall/core' */\n\n/**\n * @param {*} v\n */\nasync function getUserValue(v) {\n\tif (v == '<ME>') {\n\t\treturn await getUser() || '';\n\t}\n\treturn v ?? null;\n\n}\n/**\n * @param {*} v\n */\nasync function getUserValues(v) {\n\tconst users = [];\n\tfor (const u of Array.isArray(v) ? v : [v]) {\n\t\tusers.push(getUserValue(u));\n\t}\n\treturn Promise.all(users);\n}\n\n/** @type {WhereHook} */\nconst gt = {\n\tlabel: '>',\n\tvalue(field, v, f) {\n\t\tconst value = (Array.isArray(v) ? v[0] : v) ?? null;\n\t\treturn Where.and(field, '<', value);\n\t},\n};\n/** @type {WhereHook} */\nconst ge = {\n\tlabel: '≥',\n\tvalue(field, v, f) {\n\t\tconst value = (Array.isArray(v) ? v[0] : v) ?? null;\n\t\treturn Where.and(field, '>=', value);\n\t},\n};\n\n/** @type {WhereHook} */\nconst lt = {\n\tlabel: '<',\n\tvalue(field, v, f) {\n\t\tconst value = (Array.isArray(v) ? v[0] : v) ?? null;\n\t\treturn Where.and(field, '<', value);\n\t},\n};\n/** @type {WhereHook} */\nconst le = {\n\tlabel: '≤',\n\tvalue(field, v, f) {\n\t\tconst value = (Array.isArray(v) ? v[0] : v) ?? null;\n\t\treturn Where.and(field, '<=', value);\n\t},\n};\n\n/** @type {Record<string, WhereHook>} */\nconst comparison = {\n\t'>': gt,\n\t'>=': ge,\n\t'<': lt,\n\t'<=': le,\n\tgt, ge, lt, le\n};\n\n\n\n/** @type {WhereHook} */\nconst eq = {\n\tlabel: '=',\n\tvalue(field, v, f) {\n\t\tif (f.type === 'bool') {\n\t\t\tconst list = new Set([v].flat().map(v => {\n\t\t\t\tif (v == null) { return null; }\n\t\t\t\tif (typeof v !== 'string') { return Boolean(v); }\n\t\t\t\tswitch (v.toLowerCase()) {\n\t\t\t\t\tcase '':\n\t\t\t\t\tcase '0':\n\t\t\t\t\tcase 'n':\n\t\t\t\t\tcase 'f':\n\t\t\t\t\tcase 'no':\n\t\t\t\t\tcase 'off':\n\t\t\t\t\tcase 'false':\n\t\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\treturn true;\n\t\t\t}));\n\t\t\tif (list.size === 0) { return null; }\n\t\t\tif (list.size >= 3) { return null; }\n\n\t\t\tif (list.size === 1) {\n\t\t\t\tconst [value] = list;\n\t\t\t\treturn Where.and(field, '=', value ?? null);\n\t\t\t}\n\t\t\tconst [value] = [true, false, null].filter(v => !list.has(v));\n\t\t\treturn Where.not(field, '=', value ?? null);\n\t\t}\n\t\tif (Array.isArray(v) && v.length > 1) {\n\t\t\treturn Where.and(field, 'in', v);\n\t\t}\n\t\tconst value = (Array.isArray(v) ? v[0] : v) ?? null;\n\t\treturn Where.and(field, value);\n\t},\n\tnot: '!=',\n\tnotLabel: '≠',\n};\n/** @type {WhereHook} */\nconst eqArray = {\n\tlabel: '=',\n\tvalue(field, v, f) {\n\t\tif (f.type === 'bool') {\n\t\t\tconst list = new Set([v].flat().map(v => {\n\t\t\t\tif (typeof v !== 'string') { return Boolean(v); }\n\t\t\t\tswitch (v.toLowerCase()) {\n\t\t\t\t\tcase '':\n\t\t\t\t\tcase '0':\n\t\t\t\t\tcase 'n':\n\t\t\t\t\tcase 'f':\n\t\t\t\t\tcase 'no':\n\t\t\t\t\tcase 'off':\n\t\t\t\t\tcase 'false':\n\t\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\treturn true;\n\t\t\t}));\n\t\t\treturn Where.and(field, list);\n\t\t}\n\n\t\tconst array = Array.isArray(v) ? v : [v];\n\t\treturn Where.and(field, array);\n\t},\n\tnot: '!=',\n\tnotLabel: '≠',\n};\n\n\n/** @type {Record<string, Record<string, WhereHook>>} */\nconst filters = {\n\t'': {\n\t\t'': eq,\n\t\t'=': eq,\n\t\teq,\n\t\t'!=': {\n\t\t\tlabel: '≠',\n\t\t\tvalue(field, v, f) {\n\t\t\t\tif (Array.isArray(v) && v.length > 1) { return Where.not(field, 'in', v); }\n\t\t\t\tconst value = (Array.isArray(v) ? v[0] : v) ?? null;\n\t\t\t\treturn Where.not(field, value);\n\t\t\t},\n\t\t},\n\t\tne: {\n\t\t\tlabel: '≠',\n\t\t\tvalue(field, v, f) {\n\t\t\t\tif (Array.isArray(v) && v.length > 1) { return Where.not(field, 'in', v); }\n\t\t\t\tconst value = (Array.isArray(v) ? v[0] : v) ?? null;\n\t\t\t\treturn Where.not(field, value);\n\t\t\t},\n\t\t},\n\t\t'in': {\n\t\t\tlabel: '∈',\n\t\t\tvalue(field, v, f) {\n\t\t\t\tconst array = Array.isArray(v) ? v : [v];\n\t\t\t\treturn Where.and(field, 'in', array);\n\t\t\t},\n\n\t\t}\n\t\t, 'nin': {\n\t\t\tlabel: '∉', value: (field, v, f) => {\n\t\t\t\tconst array = Array.isArray(v) ? v : [v];\n\t\t\t\treturn Where.not(field, 'in', array);\n\t\t\t}\n\t\t}\n\t}, [`[]`]: {\n\t\t'': eqArray,\n\t\t'=': eqArray,\n\t\t'!=': {\n\t\t\tlabel: '≠',\n\t\t\tvalue(field, v, f) {\n\t\t\t\tconst array = Array.isArray(v) ? v : [v];\n\t\t\t\treturn Where.not(field, array);\n\t\t\t},\n\t\t},\n\t\tne: {\n\t\t\tlabel: '≠',\n\t\t\tvalue(field, v, f) {\n\t\t\t\tconst array = Array.isArray(v) ? v : [v];\n\t\t\t\treturn Where.not(field, array);\n\t\t\t},\n\t\t},\n\t},\n\n\t'i16': comparison,\n\t'i32': comparison,\n\t'i64': comparison,\n\t'f32': comparison,\n\t'f64': comparison,\n\t'decimal': comparison,\n\t'numeric': comparison,\n\t'money': comparison,\n\t'date': comparison,\n\t'time': comparison,\n\t'datetime': comparison,\n\t'timestamp': comparison,\n\t'string': comparison,\n\t'text': comparison,\n\t'char': comparison,\n\t// 'id.user': {\n\t// \t'=': async (field, v, f) => {\n\t// \t\tconst values = [...new Set(await getUserValues(v))];\n\t// \t\tif (values.length > 1) { return Where.and(field, 'in', values); }\n\t// \t\treturn Where.and(field, values[0] ?? null);\n\t// \t}, '!=': async (field, v, f) => {\n\t// \t\tconst values = [...new Set(await getUserValues(v))];\n\t// \t\tif (values.length > 1) { return Where.not(field, 'in', values); }\n\t// \t\treturn Where.not(field, values[0] ?? null);\n\t// \t}, 'in': async (field, v, f) => {\n\t// \t\treturn Where.and(field, 'in', [...new Set(await getUserValues(v))]);\n\t// \t}, 'nin': async (field, v, f) => {\n\t// \t\treturn Where.not(field, 'in', [...new Set(await getUserValues(v))]);\n\t// \t}\n\t// },\n\t// 'id.user[]': {\n\t// \t'=': async (field, v, f) => {\n\t// \t\treturn Where.and(field, await getUserValues(v));\n\t// \t}, '!=': async (field, v, f) => {\n\t// \t\treturn Where.not(field, await getUserValues(v));\n\t// \t}\n\t// }\n\n};\nexport default filters;\n"],"mappings":";;;;;AA0BA,MAAM,KAAK;CACV,OAAO;CACP,MAAM,OAAO,GAAG,GAAG;EAClB,MAAM,SAAS,MAAM,QAAQ,EAAE,GAAG,EAAE,KAAK,MAAM;AAC/C,SAAO,MAAM,IAAI,OAAO,KAAK,MAAM;;CAEpC;;AAED,MAAM,KAAK;CACV,OAAO;CACP,MAAM,OAAO,GAAG,GAAG;EAClB,MAAM,SAAS,MAAM,QAAQ,EAAE,GAAG,EAAE,KAAK,MAAM;AAC/C,SAAO,MAAM,IAAI,OAAO,MAAM,MAAM;;CAErC;;AAGD,MAAM,KAAK;CACV,OAAO;CACP,MAAM,OAAO,GAAG,GAAG;EAClB,MAAM,SAAS,MAAM,QAAQ,EAAE,GAAG,EAAE,KAAK,MAAM;AAC/C,SAAO,MAAM,IAAI,OAAO,KAAK,MAAM;;CAEpC;;AAED,MAAM,KAAK;CACV,OAAO;CACP,MAAM,OAAO,GAAG,GAAG;EAClB,MAAM,SAAS,MAAM,QAAQ,EAAE,GAAG,EAAE,KAAK,MAAM;AAC/C,SAAO,MAAM,IAAI,OAAO,MAAM,MAAM;;CAErC;;AAGD,MAAM,aAAa;CAClB,KAAK;CACL,MAAM;CACN,KAAK;CACL,MAAM;CACN;CAAI;CAAI;CAAI;CACZ;;AAKD,MAAM,KAAK;CACV,OAAO;CACP,MAAM,OAAO,GAAG,GAAG;AAClB,MAAI,EAAE,SAAS,QAAQ;GACtB,MAAM,OAAO,IAAI,IAAI,CAAC,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ClB,MAAM,QAAQ,MAAM,QAAQ,EAAE,GAAG,IAAI,CAAC,EAAE;AACxC,WAAO,MAAM,IAAI,OAAO,MAAM;;GAE/B;EACD;CAED,OAAO;CACP,OAAO;CACP,OAAO;CACP,OAAO;CACP,OAAO;CACP,WAAW;CACX,WAAW;CACX,SAAS;CACT,QAAQ;CACR,QAAQ;CACR,YAAY;CACZ,aAAa;CACb,UAAU;CACV,QAAQ;CACR,QAAQ;CAwBR;AACD,oBAAe"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yongdall/document",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"type": "module",
|
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
"author": "",
|
|
9
9
|
"license": "ISC",
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@yongdall/core": "^0.
|
|
12
|
-
"@yongdall/model": "^0.
|
|
13
|
-
"@yongdall/connection": "^0.
|
|
11
|
+
"@yongdall/core": "^0.3.0",
|
|
12
|
+
"@yongdall/model": "^0.3.0",
|
|
13
|
+
"@yongdall/connection": "^0.3.0"
|
|
14
14
|
},
|
|
15
15
|
"exports": {
|
|
16
16
|
".": "./index.mjs"
|