@yongdall/document 0.1.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 +129 -0
- package/hooks.yongdall.mjs.map +1 -0
- package/index.d.mts +1 -0
- package/index.mjs +0 -0
- package/package.json +18 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { Where } from "@yongdall/model";
|
|
2
|
+
import "@yongdall/core";
|
|
3
|
+
|
|
4
|
+
//#region packages/document/hooks/where.mjs
|
|
5
|
+
/** @type {WhereHook} */
|
|
6
|
+
const gt = {
|
|
7
|
+
label: ">",
|
|
8
|
+
value(field, v, f) {
|
|
9
|
+
const value = (Array.isArray(v) ? v[0] : v) ?? null;
|
|
10
|
+
return Where.and(field, "<", value);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
/** @type {WhereHook} */
|
|
14
|
+
const ge = {
|
|
15
|
+
label: "≥",
|
|
16
|
+
value(field, v, f) {
|
|
17
|
+
const value = (Array.isArray(v) ? v[0] : v) ?? null;
|
|
18
|
+
return Where.and(field, ">=", value);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
/** @type {WhereHook} */
|
|
22
|
+
const lt = {
|
|
23
|
+
label: "<",
|
|
24
|
+
value(field, v, f) {
|
|
25
|
+
const value = (Array.isArray(v) ? v[0] : v) ?? null;
|
|
26
|
+
return Where.and(field, "<", value);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
/** @type {WhereHook} */
|
|
30
|
+
const le = {
|
|
31
|
+
label: "≤",
|
|
32
|
+
value(field, v, f) {
|
|
33
|
+
const value = (Array.isArray(v) ? v[0] : v) ?? null;
|
|
34
|
+
return Where.and(field, "<=", value);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
/** @type {Record<string, WhereHook>} */
|
|
38
|
+
const comparison = {
|
|
39
|
+
">": gt,
|
|
40
|
+
">=": ge,
|
|
41
|
+
"<": lt,
|
|
42
|
+
"<=": le,
|
|
43
|
+
gt,
|
|
44
|
+
ge,
|
|
45
|
+
lt,
|
|
46
|
+
le
|
|
47
|
+
};
|
|
48
|
+
/** @type {WhereHook} */
|
|
49
|
+
const eq = {
|
|
50
|
+
label: "=",
|
|
51
|
+
value(field, v, f) {
|
|
52
|
+
if (Array.isArray(v) && v.length > 1) return Where.and(field, "in", v);
|
|
53
|
+
const value = (Array.isArray(v) ? v[0] : v) ?? null;
|
|
54
|
+
return Where.and(field, value);
|
|
55
|
+
},
|
|
56
|
+
not: "!=",
|
|
57
|
+
notLabel: "≠"
|
|
58
|
+
};
|
|
59
|
+
/** @type {WhereHook} */
|
|
60
|
+
const eqArray = {
|
|
61
|
+
label: "=",
|
|
62
|
+
value(field, v, f) {
|
|
63
|
+
const array = Array.isArray(v) ? v : [v];
|
|
64
|
+
return Where.and(field, array);
|
|
65
|
+
},
|
|
66
|
+
not: "!=",
|
|
67
|
+
notLabel: "≠"
|
|
68
|
+
};
|
|
69
|
+
/** @type {Record<string, Record<string, WhereHook>>} */
|
|
70
|
+
const filters = {
|
|
71
|
+
"": {
|
|
72
|
+
"": eq,
|
|
73
|
+
"=": eq,
|
|
74
|
+
eq,
|
|
75
|
+
"!=": {
|
|
76
|
+
label: "≠",
|
|
77
|
+
value(field, v, f) {
|
|
78
|
+
if (Array.isArray(v) && v.length > 1) return Where.not(field, "in", v);
|
|
79
|
+
const value = (Array.isArray(v) ? v[0] : v) ?? null;
|
|
80
|
+
return Where.not(field, value);
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
"in": {
|
|
84
|
+
label: "∈",
|
|
85
|
+
value(field, v, f) {
|
|
86
|
+
const array = Array.isArray(v) ? v : [v];
|
|
87
|
+
return Where.and(field, "in", array);
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
"nin": {
|
|
91
|
+
label: "∉",
|
|
92
|
+
value: (field, v, f) => {
|
|
93
|
+
const array = Array.isArray(v) ? v : [v];
|
|
94
|
+
return Where.not(field, "in", array);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
[`[]`]: {
|
|
99
|
+
"": eqArray,
|
|
100
|
+
"=": eqArray,
|
|
101
|
+
"!=": {
|
|
102
|
+
label: "≠",
|
|
103
|
+
value(field, v, f) {
|
|
104
|
+
const array = Array.isArray(v) ? v : [v];
|
|
105
|
+
return Where.not(field, array);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
"i16": comparison,
|
|
110
|
+
"i32": comparison,
|
|
111
|
+
"i64": comparison,
|
|
112
|
+
"f32": comparison,
|
|
113
|
+
"f64": comparison,
|
|
114
|
+
"decimal": comparison,
|
|
115
|
+
"numeric": comparison,
|
|
116
|
+
"money": comparison,
|
|
117
|
+
"date": comparison,
|
|
118
|
+
"time": comparison,
|
|
119
|
+
"datetime": comparison,
|
|
120
|
+
"timestamp": comparison,
|
|
121
|
+
"string": comparison,
|
|
122
|
+
"text": comparison,
|
|
123
|
+
"char": comparison
|
|
124
|
+
};
|
|
125
|
+
var where_default = filters;
|
|
126
|
+
|
|
127
|
+
//#endregion
|
|
128
|
+
export { where_default as where };
|
|
129
|
+
//# sourceMappingURL=hooks.yongdall.mjs.map
|
|
@@ -0,0 +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) { return Where.and(field, 'in', v); }\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\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\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},\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},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ED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@yongdall/document",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"keywords": [],
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./index.mjs",
|
|
8
|
+
"author": "",
|
|
9
|
+
"license": "ISC",
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"@yongdall/core": "^0.1.0",
|
|
12
|
+
"@yongdall/model": "^0.1.0",
|
|
13
|
+
"@yongdall/connection": "^0.1.0"
|
|
14
|
+
},
|
|
15
|
+
"exports": {
|
|
16
|
+
".": "./index.mjs"
|
|
17
|
+
}
|
|
18
|
+
}
|