@cyberskill/shared 1.214.0 → 1.215.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/dist/config/config.util.cjs +1 -1
- package/dist/config/config.util.js +12 -12
- package/dist/config/vitest/vitest.e2e.cjs +1 -1
- package/dist/config/vitest/vitest.e2e.js +6 -6
- package/dist/config/vitest/vitest.unit.cjs +1 -1
- package/dist/config/vitest/vitest.unit.js +5 -5
- package/dist/node/mongo/mongo.util.cjs +2 -2
- package/dist/node/mongo/mongo.util.js +22 -21
- package/dist/util/index.cjs +1 -1
- package/dist/util/index.js +17 -20
- package/dist/util/object/index.cjs +1 -1
- package/dist/util/object/index.js +4 -7
- package/dist/util/object/object.util.cjs +1 -1
- package/dist/util/object/object.util.d.ts +1 -25
- package/dist/util/object/object.util.js +28 -58
- package/dist/util/string/string.util.cjs +1 -1
- package/dist/util/string/string.util.js +1 -1
- package/package.json +3 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const _=require("@antfu/eslint-config"),s=require("lodash-es"),i=require("./config.type.cjs"),y=require("./eslint/index.cjs"),E=require("./vitest/vitest.e2e.cjs"),m=require("./vitest/vitest.unit.cjs");var g=Object.getOwnPropertySymbols,p=Object.prototype.hasOwnProperty,u=Object.prototype.propertyIsEnumerable,T=(e,n)=>{var t={};for(var r in e)p.call(e,r)&&n.indexOf(r)<0&&(t[r]=e[r]);if(e!=null&&g)for(var r of g(e))n.indexOf(r)<0&&u.call(e,r)&&(t[r]=e[r]);return t};const c=(...e)=>{const t=s.merge(y.default,...e.map(o=>o)),{ignores:r}=t,f=T(t,["ignores"]),a=Array.isArray(r)&&r.every(o=>typeof o=="string")?{ignores:r}:void 0,l=[f,...a?[a]:[]];return _({stylistic:{semi:!0,indent:4,quotes:"single"},formatters:{css:!0,html:!0,markdown:"prettier"},yaml:!1,react:!0},...l)},d={[i.E_ConfigType.ESLINT]:e=>c(e),[i.E_ConfigType.COMMITLINT]:e=>s.merge(e),[i.E_ConfigType.LINT_STAGED]:e=>s.merge(e),[i.E_ConfigType.VITEST_REACT_UNIT]:e=>m.vitestUnit(e),[i.E_ConfigType.VITEST_REACT_E2E]:e=>E.vitestE2E(e)};function v(e,...n){const t=d[e];if(!n||n.length===0)return t({});if(!t)throw new Error(`Unknown config type: ${e}`);return t(...n)}exports.mergeConfigs=v;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import l from "@antfu/eslint-config";
|
|
2
|
+
import { merge as a } from "lodash-es";
|
|
2
3
|
import { E_ConfigType as o } from "./config.type.js";
|
|
3
|
-
import
|
|
4
|
+
import p from "./eslint/index.js";
|
|
4
5
|
import { vitestE2E as y } from "./vitest/vitest.e2e.js";
|
|
5
6
|
import { vitestUnit as E } from "./vitest/vitest.unit.js";
|
|
6
|
-
|
|
7
|
-
var f = Object.getOwnPropertySymbols, _ = Object.prototype.hasOwnProperty, T = Object.prototype.propertyIsEnumerable, d = (r, n) => {
|
|
7
|
+
var f = Object.getOwnPropertySymbols, _ = Object.prototype.hasOwnProperty, T = Object.prototype.propertyIsEnumerable, v = (r, n) => {
|
|
8
8
|
var e = {};
|
|
9
9
|
for (var t in r)
|
|
10
10
|
_.call(r, t) && n.indexOf(t) < 0 && (e[t] = r[t]);
|
|
@@ -13,15 +13,15 @@ var f = Object.getOwnPropertySymbols, _ = Object.prototype.hasOwnProperty, T = O
|
|
|
13
13
|
n.indexOf(t) < 0 && T.call(r, t) && (e[t] = r[t]);
|
|
14
14
|
return e;
|
|
15
15
|
};
|
|
16
|
-
const
|
|
16
|
+
const c = (...r) => {
|
|
17
17
|
const e = a(
|
|
18
|
-
|
|
18
|
+
p,
|
|
19
19
|
...r.map((i) => i)
|
|
20
|
-
), { ignores: t } = e, m =
|
|
20
|
+
), { ignores: t } = e, m = v(e, ["ignores"]), s = Array.isArray(t) && t.every((i) => typeof i == "string") ? { ignores: t } : void 0, g = [
|
|
21
21
|
m,
|
|
22
22
|
...s ? [s] : []
|
|
23
23
|
];
|
|
24
|
-
return
|
|
24
|
+
return l(
|
|
25
25
|
{
|
|
26
26
|
stylistic: {
|
|
27
27
|
semi: !0,
|
|
@@ -36,17 +36,17 @@ const v = (...r) => {
|
|
|
36
36
|
yaml: !1,
|
|
37
37
|
react: !0
|
|
38
38
|
},
|
|
39
|
-
...
|
|
39
|
+
...g
|
|
40
40
|
);
|
|
41
|
-
},
|
|
42
|
-
[o.ESLINT]: (r) =>
|
|
41
|
+
}, d = {
|
|
42
|
+
[o.ESLINT]: (r) => c(r),
|
|
43
43
|
[o.COMMITLINT]: (r) => a(r),
|
|
44
44
|
[o.LINT_STAGED]: (r) => a(r),
|
|
45
45
|
[o.VITEST_REACT_UNIT]: (r) => E(r),
|
|
46
46
|
[o.VITEST_REACT_E2E]: (r) => y(r)
|
|
47
47
|
};
|
|
48
48
|
function u(r, ...n) {
|
|
49
|
-
const e =
|
|
49
|
+
const e = d[r];
|
|
50
50
|
if (!n || n.length === 0)
|
|
51
51
|
return e({});
|
|
52
52
|
if (!e)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("@vitejs/plugin-react-swc"),i=require("../../node_modules/.pnpm/vitest@3.2.4_@types_debug@4.1.12_@types_node@24.0.13_@vitest_browser@3.2.4_jiti@2.4.2_j_cac3da623d5688a51c0b1a2270e144db/node_modules/vitest/dist/config.cjs")
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("@vitejs/plugin-react-swc"),i=require("lodash-es"),o=require("../../node_modules/.pnpm/vitest@3.2.4_@types_debug@4.1.12_@types_node@24.0.13_@vitest_browser@3.2.4_jiti@2.4.2_j_cac3da623d5688a51c0b1a2270e144db/node_modules/vitest/dist/config.cjs");function s(e){const r={plugins:[t()],test:{include:["**/*.test.e2e.?(c|m)[jt]s?(x)"],browser:{enabled:!0,provider:"playwright",instances:[{browser:"chromium"},{browser:"firefox"},{browser:"webkit"}]}}};return o.defineConfig(i.merge(r,e))}exports.vitestE2E=s;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import t from "@vitejs/plugin-react-swc";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
function
|
|
5
|
-
const
|
|
2
|
+
import { merge as o } from "lodash-es";
|
|
3
|
+
import { defineConfig as i } from "../../node_modules/.pnpm/vitest@3.2.4_@types_debug@4.1.12_@types_node@24.0.13_@vitest_browser@3.2.4_jiti@2.4.2_j_cac3da623d5688a51c0b1a2270e144db/node_modules/vitest/dist/config.js";
|
|
4
|
+
function f(r) {
|
|
5
|
+
const e = {
|
|
6
6
|
plugins: [t()],
|
|
7
7
|
test: {
|
|
8
8
|
include: ["**/*.test.e2e.?(c|m)[jt]s?(x)"],
|
|
@@ -17,8 +17,8 @@ function m(e) {
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
};
|
|
20
|
-
return o(
|
|
20
|
+
return i(o(e, r));
|
|
21
21
|
}
|
|
22
22
|
export {
|
|
23
|
-
|
|
23
|
+
f as vitestE2E
|
|
24
24
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("@vitejs/plugin-react-swc"),n=require("../../node_modules/.pnpm/vitest@3.2.4_@types_debug@4.1.12_@types_node@24.0.13_@vitest_browser@3.2.4_jiti@2.4.2_j_cac3da623d5688a51c0b1a2270e144db/node_modules/vitest/dist/config.cjs")
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("@vitejs/plugin-react-swc"),n=require("lodash-es"),s=require("../../node_modules/.pnpm/vitest@3.2.4_@types_debug@4.1.12_@types_node@24.0.13_@vitest_browser@3.2.4_jiti@2.4.2_j_cac3da623d5688a51c0b1a2270e144db/node_modules/vitest/dist/config.cjs");function r(e){const t={plugins:[i()],test:{globals:!0,environment:"jsdom",pool:"vmThreads",include:["**/*.test.unit.?(c|m)[jt]s?(x)"],setupFiles:["./vitest.unit.setup.ts"]}};return s.defineConfig(n.merge(t,e))}exports.vitestUnit=r;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import i from "@vitejs/plugin-react-swc";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
function
|
|
2
|
+
import { merge as o } from "lodash-es";
|
|
3
|
+
import { defineConfig as n } from "../../node_modules/.pnpm/vitest@3.2.4_@types_debug@4.1.12_@types_node@24.0.13_@vitest_browser@3.2.4_jiti@2.4.2_j_cac3da623d5688a51c0b1a2270e144db/node_modules/vitest/dist/config.js";
|
|
4
|
+
function u(t) {
|
|
5
5
|
const e = {
|
|
6
6
|
plugins: [i()],
|
|
7
7
|
test: {
|
|
@@ -12,8 +12,8 @@ function p(t) {
|
|
|
12
12
|
setupFiles: ["./vitest.unit.setup.ts"]
|
|
13
13
|
}
|
|
14
14
|
};
|
|
15
|
-
return o(
|
|
15
|
+
return n(o(e, t));
|
|
16
16
|
}
|
|
17
17
|
export {
|
|
18
|
-
|
|
18
|
+
u as vitestUnit
|
|
19
19
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("lodash-es"),v=require("migrate-mongo"),q=require("mongoose"),A=require("mongoose-aggregate-paginate-v2"),b=require("mongoose-paginate-v2"),T=require("uuid"),D=require("../../util/object/object.util.cjs"),x=require("../../util/common/common.util.cjs"),y=require("../fs/fs.util.cjs"),f=require("../path/path.constant.cjs"),C=require("../../util/validate/validate.util.cjs"),S=require("../../util/string/string.util.cjs"),d=require("../../constant/response-status.cjs"),i=require("../log/log.util.cjs");var I=Object.defineProperty,M=Object.defineProperties,w=Object.getOwnPropertyDescriptors,P=Object.getOwnPropertySymbols,j=Object.prototype.hasOwnProperty,F=Object.prototype.propertyIsEnumerable,_=(n,t,e)=>t in n?I(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,h=(n,t)=>{for(var e in t||(t={}))j.call(t,e)&&_(n,e,t[e]);if(P)for(var e of P(t))F.call(t,e)&&_(n,e,t[e]);return n},R=(n,t)=>M(n,w(t)),G=(n,t,e)=>_(n,typeof t!="symbol"?t+"":t,e),o=(n,t,e)=>new Promise((r,s)=>{var u=a=>{try{l(e.next(a))}catch(m){s(m)}},c=a=>{try{l(e.throw(a))}catch(m){s(m)}},l=a=>a.done?r(a.value):Promise.resolve(a.value).then(u,c);l((e=e.apply(n,t)).next())});const g={createGenericFields(){return{id:T.v4(),isDel:!1,createdAt:new Date,updatedAt:new Date}},applyPlugins(n,t){t.filter(e=>typeof e=="function").forEach(e=>n.plugin(e))},applyMiddlewares(n,t){t.forEach(({method:e,pre:r,post:s})=>{e&&r&&n.pre(e,r),e&&s&&n.post(e,s)})},createGenericSchema(n){return new n.Schema({id:{type:String,default:T.v4,unique:!0},isDel:{type:Boolean,default:!1}},{timestamps:!0})},createSchema({mongoose:n,schema:t,virtuals:e=[],standalone:r=!1}){const s=new n.Schema(t);return e.forEach(({name:u,options:c,get:l})=>{const a=s.virtual(u,c);l&&a.get(l)}),r||s.add(g.createGenericSchema(n)),s},createModel({mongoose:n,name:t,schema:e,pagination:r=!1,aggregate:s=!1,virtuals:u=[],middlewares:c=[]}){if(!t)throw new Error("Model name is required.");if(n.models[t])return n.models[t];const l=g.createSchema({mongoose:n,schema:e,virtuals:u});return g.applyPlugins(l,[r&&b,s&&A]),g.applyMiddlewares(l,c),n.model(t,l)},validator:{isRequired(){return function(n){return o(this,null,function*(){return!C.validate.isEmpty(n)})}},isUnique(n){return function(t){return o(this,null,function*(){if(!Array.isArray(n)||n.length===0)throw new Error("Fields must be a non-empty array of strings.");const e={$or:n.map(s=>({[s]:t}))};return!(yield this.constructor.exists(e))})}},matchesRegex(n){return function(t){return o(this,null,function*(){if(!Array.isArray(n)||n.some(e=>!(e instanceof RegExp)))throw new Error("regexArray must be an array of valid RegExp objects.");return n.every(e=>e.test(t))})}}},migrate:R(h({},v),{setConfig:n=>{const t=`// This file is automatically generated by the Cyberskill CLI.
|
|
2
2
|
module.exports = ${JSON.stringify(n,null,4)}`;y.writeFileSync(f.PATH.MIGRATE_MONGO_CONFIG,t);const e=`
|
|
3
3
|
${f.MIGRATE_MONGO_CONFIG}
|
|
4
4
|
`;y.pathExistsSync(f.PATH.GIT_IGNORE)?y.readFileSync(f.PATH.GIT_IGNORE,"utf-8").split(`
|
|
5
|
-
`).includes(f.MIGRATE_MONGO_CONFIG)||y.appendFileSync(f.PATH.GIT_IGNORE,e):y.writeFileSync(f.PATH.GIT_IGNORE,e)}}),regexify(n,t){if(!n)return{};let e=
|
|
5
|
+
`).includes(f.MIGRATE_MONGO_CONFIG)||y.appendFileSync(f.PATH.GIT_IGNORE,e):y.writeFileSync(f.PATH.GIT_IGNORE,e)}}),regexify(n,t){if(!n)return{};let e=p.cloneDeep(n);if(!t||t.length===0)return e;for(const r of t){const s=r.toString().split("."),u=D.getNestedValue(e,s);if(typeof u=="string"&&u.length>0){const c={$regex:`.*${x.regexSearchMapper(u)}.*`,$options:"i"};e=D.setNestedValue(e,s,c)}}return e}};class U{constructor(t,e){G(this,"collection"),this.collection=t.collection(e)}createOne(t){return o(this,null,function*(){try{const e=h(h({},g.createGenericFields()),t);return(yield this.collection.insertOne(e)).acknowledged?{success:!0,message:"Document created successfully",result:e}:{success:!1,message:"Document creation failed",code:d.RESPONSE_STATUS.INTERNAL_SERVER_ERROR.CODE}}catch(e){return i.catchError(e)}})}createMany(t){return o(this,null,function*(){try{const e=t.map(s=>h(h({},g.createGenericFields()),s)),r=yield this.collection.insertMany(e);return r.insertedCount===0?{success:!1,message:"No documents were inserted",code:d.RESPONSE_STATUS.INTERNAL_SERVER_ERROR.CODE}:{success:!0,message:`${r.insertedCount} documents created successfully`,result:e}}catch(e){return i.catchError(e)}})}findOne(t){return o(this,null,function*(){try{const e=yield this.collection.findOne(t);return e?{success:!0,message:"Document found",result:e}:{success:!1,message:"Document not found",code:d.RESPONSE_STATUS.NOT_FOUND.CODE}}catch(e){return i.catchError(e)}})}findAll(){return o(this,arguments,function*(t={}){try{return{success:!0,message:"Documents retrieved successfully",result:yield this.collection.find(t).toArray()}}catch(e){return i.catchError(e)}})}count(){return o(this,arguments,function*(t={}){try{return{success:!0,message:"Count retrieved successfully",result:yield this.collection.countDocuments(t)}}catch(e){return i.catchError(e)}})}updateOne(t,e){return o(this,null,function*(){try{const r=yield this.collection.updateOne(t,{$set:e});return r.matchedCount===0?{success:!1,message:"No documents matched the filter",code:d.RESPONSE_STATUS.INTERNAL_SERVER_ERROR.CODE}:{success:!0,message:"Document updated successfully",result:r}}catch(r){return i.catchError(r)}})}updateMany(t,e){return o(this,null,function*(){try{const r=yield this.collection.updateMany(t,{$set:e});return r.matchedCount===0?{success:!1,message:"No documents matched the filter",code:d.RESPONSE_STATUS.INTERNAL_SERVER_ERROR.CODE}:{success:!0,message:"Documents updated successfully",result:r}}catch(r){return i.catchError(r)}})}deleteOne(t){return o(this,null,function*(){try{const e=yield this.collection.deleteOne(t);return e.deletedCount===0?{success:!1,message:"No documents matched the filter",code:d.RESPONSE_STATUS.INTERNAL_SERVER_ERROR.CODE}:{success:!0,message:"Document deleted successfully",result:e}}catch(e){return i.catchError(e)}})}deleteMany(t){return o(this,null,function*(){try{const e=yield this.collection.deleteMany(t);return e.deletedCount===0?{success:!1,message:"No documents matched the filter",code:d.RESPONSE_STATUS.INTERNAL_SERVER_ERROR.CODE}:{success:!0,message:"Documents deleted successfully",result:e}}catch(e){return i.catchError(e)}})}}class ${constructor(t){this.model=t}getModelName(){return this.model.modelName}findOne(){return o(this,arguments,function*(t={},e={},r={},s){try{const u=this.model.findOne(t,e,r);s&&u.populate(s);const c=yield u.exec();return c?{success:!0,result:c}:{success:!1,message:`No ${this.getModelName()} found.`,code:d.RESPONSE_STATUS.NOT_FOUND.CODE}}catch(u){return i.catchError(u)}})}findAll(){return o(this,arguments,function*(t={},e={},r={},s){try{const u=this.model.find(t,e,r);return s&&u.populate(s),{success:!0,result:yield u.exec()}}catch(u){return i.catchError(u)}})}findPaging(){return o(this,arguments,function*(t={},e={}){try{return{success:!0,result:yield this.model.paginate(t,e)}}catch(r){return i.catchError(r)}})}findPagingAggregate(t){return o(this,arguments,function*(e,r={}){try{return{success:!0,result:yield this.model.aggregatePaginate(this.model.aggregate(e),r)}}catch(s){return i.catchError(s)}})}count(){return o(this,arguments,function*(t={}){try{return{success:!0,result:yield this.model.countDocuments(t)}}catch(e){return i.catchError(e)}})}createOne(t){return o(this,null,function*(){try{return{success:!0,result:yield this.model.create(t)}}catch(e){return i.catchError(e)}})}createMany(t){return o(this,arguments,function*(e,r={}){try{return{success:!0,result:(yield this.model.insertMany(e,r)).map(c=>c instanceof q.Document?c.toObject():null).filter(c=>c!==null)}}catch(s){return i.catchError(s)}})}updateOne(){return o(this,arguments,function*(t={},e={},r={}){try{const s=yield this.model.findOneAndUpdate(t,e,h({new:!0},r)).exec();return s?{success:!0,result:s}:{success:!1,message:`Failed to update ${this.getModelName()}.`,code:d.RESPONSE_STATUS.NOT_FOUND.CODE}}catch(s){return i.catchError(s)}})}updateMany(){return o(this,arguments,function*(t={},e={},r={}){try{return{success:!0,result:yield this.model.updateMany(t,e,r).exec()}}catch(s){return i.catchError(s)}})}deleteOne(){return o(this,arguments,function*(t={},e={}){try{const r=yield this.model.findOneAndDelete(t,e).exec();return r?{success:!0,result:r}:{success:!1,message:`No ${this.getModelName()} found to delete.`,code:d.RESPONSE_STATUS.NOT_FOUND.CODE}}catch(r){return i.catchError(r)}})}deleteMany(){return o(this,arguments,function*(t={},e={}){try{const r=yield this.model.deleteMany(t,e).exec();return r.deletedCount===0?{success:!1,message:"No documents found to delete.",code:d.RESPONSE_STATUS.NOT_FOUND.CODE}:{success:!0,result:r}}catch(r){return i.catchError(r)}})}createShortId(t,e=4){return o(this,null,function*(){try{const s=new Set;for(let u=0;u<10;u++){const c=S.generateShortId(t,u+e);if(!s.has(c)&&(s.add(c),!(yield this.model.exists({shortId:c}))))return{success:!0,result:c}}return{success:!1,message:"Failed to create a unique shortId",code:d.RESPONSE_STATUS.INTERNAL_SERVER_ERROR.CODE}}catch(r){return i.catchError(r)}})}createSlugQuery({slug:t,field:e,isObject:r,filter:s}){const u=h({},s!=null?s:{});return r?R(h({},u),{$or:[{[`slug.${e}`]:t},{slugHistory:{$elemMatch:{[`slug.${e}`]:t}}}]}):R(h({},u),{$or:[{slug:t},{slugHistory:t}]})}createUniqueSlug(t){return o(this,arguments,function*({slug:e,field:r,isObject:s,filter:u}){const c=S.generateSlug(e);let l=c,a=1;for(;yield this.model.exists(this.createSlugQuery({slug:l,field:r,isObject:s,filter:u}));)l=`${c}-${a++}`;return l})}createSlug(t){return o(this,arguments,function*({field:e,from:r,filter:s}){try{const u=r[e];return p.isObject(u)?{success:!0,result:Object.fromEntries(yield Promise.all(Object.entries(u).map(m=>o(this,[m],function*([E,O]){const N=yield this.createUniqueSlug({slug:O,field:E,isObject:!0,filter:s});return[E,N]}))))}:{success:!0,result:yield this.createUniqueSlug({slug:u,field:e,isObject:!1,filter:s})}}catch(u){return i.catchError(u)}})}checkSlug(t){return o(this,arguments,function*({slug:e,field:r,from:s,filter:u}){try{const c=s[r];if(p.isObject(c)){for(const E of Object.values(c)){const O=S.generateSlug(E);if(yield this.model.exists(this.createSlugQuery({slug:O,field:r,isObject:!0,filter:u})))return{success:!0,result:!0}}return{success:!0,result:!1}}const a=S.generateSlug(e);return{success:!0,result:(yield this.model.exists(this.createSlugQuery({slug:a,field:r,isObject:!1,filter:u})))!==null}}catch(c){return i.catchError(c)}})}aggregate(t){return o(this,null,function*(){try{return{success:!0,result:yield this.model.aggregate(t)}}catch(e){return i.catchError(e)}})}}exports.aggregatePaginate=A;exports.mongoosePaginate=b;exports.MongoController=U;exports.MongooseController=$;exports.mongo=g;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import v from "
|
|
2
|
-
import
|
|
1
|
+
import { cloneDeep as v, isObject as S } from "lodash-es";
|
|
2
|
+
import w from "migrate-mongo";
|
|
3
|
+
import { Document as I } from "mongoose";
|
|
3
4
|
import C from "mongoose-aggregate-paginate-v2";
|
|
4
|
-
import { default as
|
|
5
|
-
import
|
|
6
|
-
import { default as
|
|
7
|
-
import { v4 as
|
|
8
|
-
import {
|
|
5
|
+
import { default as ae } from "mongoose-aggregate-paginate-v2";
|
|
6
|
+
import P from "mongoose-paginate-v2";
|
|
7
|
+
import { default as fe } from "mongoose-paginate-v2";
|
|
8
|
+
import { v4 as N } from "uuid";
|
|
9
|
+
import { getNestedValue as M, setNestedValue as A } from "../../util/object/object.util.js";
|
|
9
10
|
import { regexSearchMapper as T } from "../../util/common/common.util.js";
|
|
10
11
|
import { writeFileSync as D, pathExistsSync as j, readFileSync as F, appendFileSync as G } from "../fs/fs.util.js";
|
|
11
12
|
import { PATH as g, MIGRATE_MONGO_CONFIG as x } from "../path/path.constant.js";
|
|
@@ -39,7 +40,7 @@ var V = Object.defineProperty, U = Object.defineProperties, L = Object.getOwnPro
|
|
|
39
40
|
const h = {
|
|
40
41
|
createGenericFields() {
|
|
41
42
|
return {
|
|
42
|
-
id:
|
|
43
|
+
id: N(),
|
|
43
44
|
isDel: !1,
|
|
44
45
|
createdAt: /* @__PURE__ */ new Date(),
|
|
45
46
|
updatedAt: /* @__PURE__ */ new Date()
|
|
@@ -56,7 +57,7 @@ const h = {
|
|
|
56
57
|
createGenericSchema(n) {
|
|
57
58
|
return new n.Schema(
|
|
58
59
|
{
|
|
59
|
-
id: { type: String, default:
|
|
60
|
+
id: { type: String, default: N, unique: !0 },
|
|
60
61
|
isDel: { type: Boolean, default: !1 }
|
|
61
62
|
},
|
|
62
63
|
{ timestamps: !0 }
|
|
@@ -89,7 +90,7 @@ const h = {
|
|
|
89
90
|
return n.models[t];
|
|
90
91
|
const l = h.createSchema({ mongoose: n, schema: e, virtuals: u });
|
|
91
92
|
return h.applyPlugins(l, [
|
|
92
|
-
r &&
|
|
93
|
+
r && P,
|
|
93
94
|
s && C
|
|
94
95
|
]), h.applyMiddlewares(l, c), n.model(t, l);
|
|
95
96
|
},
|
|
@@ -121,7 +122,7 @@ const h = {
|
|
|
121
122
|
};
|
|
122
123
|
}
|
|
123
124
|
},
|
|
124
|
-
migrate: R(f({},
|
|
125
|
+
migrate: R(f({}, w), {
|
|
125
126
|
setConfig: (n) => {
|
|
126
127
|
const t = `// This file is automatically generated by the Cyberskill CLI.
|
|
127
128
|
module.exports = ${JSON.stringify(n, null, 4)}`;
|
|
@@ -136,7 +137,7 @@ ${x}
|
|
|
136
137
|
regexify(n, t) {
|
|
137
138
|
if (!n)
|
|
138
139
|
return {};
|
|
139
|
-
let e =
|
|
140
|
+
let e = v(n);
|
|
140
141
|
if (!t || t.length === 0)
|
|
141
142
|
return e;
|
|
142
143
|
for (const r of t) {
|
|
@@ -152,7 +153,7 @@ ${x}
|
|
|
152
153
|
return e;
|
|
153
154
|
}
|
|
154
155
|
};
|
|
155
|
-
class
|
|
156
|
+
class ce {
|
|
156
157
|
constructor(t, e) {
|
|
157
158
|
J(this, "collection"), this.collection = t.collection(e);
|
|
158
159
|
}
|
|
@@ -305,7 +306,7 @@ class ue {
|
|
|
305
306
|
});
|
|
306
307
|
}
|
|
307
308
|
}
|
|
308
|
-
class
|
|
309
|
+
class oe {
|
|
309
310
|
constructor(t) {
|
|
310
311
|
this.model = t;
|
|
311
312
|
}
|
|
@@ -380,7 +381,7 @@ class ce {
|
|
|
380
381
|
createMany(t) {
|
|
381
382
|
return o(this, arguments, function* (e, r = {}) {
|
|
382
383
|
try {
|
|
383
|
-
return { success: !0, result: (yield this.model.insertMany(e, r)).map((c) => c instanceof
|
|
384
|
+
return { success: !0, result: (yield this.model.insertMany(e, r)).map((c) => c instanceof I ? c.toObject() : null).filter((c) => c !== null) };
|
|
384
385
|
} catch (s) {
|
|
385
386
|
return i(s);
|
|
386
387
|
}
|
|
@@ -485,7 +486,7 @@ class ce {
|
|
|
485
486
|
return o(this, arguments, function* ({ field: e, from: r, filter: s }) {
|
|
486
487
|
try {
|
|
487
488
|
const u = r[e];
|
|
488
|
-
return
|
|
489
|
+
return S(u) ? { success: !0, result: Object.fromEntries(
|
|
489
490
|
yield Promise.all(
|
|
490
491
|
Object.entries(u).map((m) => o(this, [m], function* ([y, p]) {
|
|
491
492
|
const _ = yield this.createUniqueSlug({
|
|
@@ -512,7 +513,7 @@ class ce {
|
|
|
512
513
|
return o(this, arguments, function* ({ slug: e, field: r, from: s, filter: u }) {
|
|
513
514
|
try {
|
|
514
515
|
const c = s[r];
|
|
515
|
-
if (
|
|
516
|
+
if (S(c)) {
|
|
516
517
|
for (const y of Object.values(c)) {
|
|
517
518
|
const p = O(y);
|
|
518
519
|
if (yield this.model.exists(this.createSlugQuery({
|
|
@@ -548,9 +549,9 @@ class ce {
|
|
|
548
549
|
}
|
|
549
550
|
}
|
|
550
551
|
export {
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
552
|
+
ce as MongoController,
|
|
553
|
+
oe as MongooseController,
|
|
554
|
+
ae as aggregatePaginate,
|
|
554
555
|
h as mongo,
|
|
555
|
-
|
|
556
|
+
fe as mongoosePaginate
|
|
556
557
|
};
|
package/dist/util/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./common/common.util.cjs"),t=require("./object/object.util.cjs"),a=require("./serializer/serializer.util.cjs"),e=require("./string/string.util.cjs"),i=require("./validate/validate.util.cjs");exports.mapEnvironment=r.mapEnvironment;exports.regexSearchMapper=r.regexSearchMapper;exports.removeAccent=r.removeAccent;exports.uniqueArray=r.uniqueArray;exports.getNestedValue=t.getNestedValue;exports.isJSON=t.isJSON;exports.setNestedValue=t.setNestedValue;exports.serializer=a.serializer;exports.generateRandomPassword=e.generateRandomPassword;exports.generateShortId=e.generateShortId;exports.generateSlug=e.generateSlug;exports.getFileName=e.getFileName;exports.substringBetween=e.substringBetween;exports.validate=i.validate;
|
package/dist/util/index.js
CHANGED
|
@@ -1,24 +1,21 @@
|
|
|
1
|
-
import { mapEnvironment as t, regexSearchMapper as
|
|
2
|
-
import {
|
|
3
|
-
import { serializer as
|
|
4
|
-
import { generateRandomPassword as
|
|
5
|
-
import { validate as
|
|
1
|
+
import { mapEnvironment as t, regexSearchMapper as a, removeAccent as o, uniqueArray as n } from "./common/common.util.js";
|
|
2
|
+
import { getNestedValue as s, isJSON as g, setNestedValue as i } from "./object/object.util.js";
|
|
3
|
+
import { serializer as d } from "./serializer/serializer.util.js";
|
|
4
|
+
import { generateRandomPassword as u, generateShortId as x, generateSlug as f, getFileName as N, substringBetween as S } from "./string/string.util.js";
|
|
5
|
+
import { validate as v } from "./validate/validate.util.js";
|
|
6
6
|
export {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
g as getNestedValue,
|
|
14
|
-
i as isJson,
|
|
15
|
-
d as isObject,
|
|
7
|
+
u as generateRandomPassword,
|
|
8
|
+
x as generateShortId,
|
|
9
|
+
f as generateSlug,
|
|
10
|
+
N as getFileName,
|
|
11
|
+
s as getNestedValue,
|
|
12
|
+
g as isJSON,
|
|
16
13
|
t as mapEnvironment,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
a as regexSearchMapper,
|
|
15
|
+
o as removeAccent,
|
|
16
|
+
d as serializer,
|
|
17
|
+
i as setNestedValue,
|
|
18
|
+
S as substringBetween,
|
|
22
19
|
n as uniqueArray,
|
|
23
|
-
|
|
20
|
+
v as validate
|
|
24
21
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./object.util.cjs");exports.
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./object.util.cjs");exports.getNestedValue=e.getNestedValue;exports.isJSON=e.isJSON;exports.setNestedValue=e.setNestedValue;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getNestedValue as s, isJSON as N, setNestedValue as a } from "./object.util.js";
|
|
2
2
|
export {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
l as isJson,
|
|
7
|
-
p as isObject,
|
|
8
|
-
r as setNestedValue
|
|
3
|
+
s as getNestedValue,
|
|
4
|
+
N as isJSON,
|
|
5
|
+
a as setNestedValue
|
|
9
6
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var l=Object.defineProperty,c=Object.defineProperties,_=Object.getOwnPropertyDescriptors,u=Object.getOwnPropertySymbols,d=Object.prototype.hasOwnProperty,O=Object.prototype.propertyIsEnumerable,a=(r,e,t)=>e in r?l(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,i=(r,e)=>{for(var t in e||(e={}))d.call(e,t)&&a(r,t,e[t]);if(u)for(var t of u(e))O.call(e,t)&&a(r,t,e[t]);return r},p=(r,e)=>c(r,_(e));function P(r){try{return JSON.parse(r),!0}catch(e){return!1}}function g(r,e){return e.reduce((t,n)=>{if(t&&typeof t=="object"&&n in t)return t[n]},r)}function f(r,e,t){if(e.length===0)return r;const[n,...s]=e;if(s.length===0)return p(i({},r),{[n]:t});const o=r[n];return p(i({},r),{[n]:f(typeof o=="object"&&o!==null?o:{},s,t)})}exports.getNestedValue=g;exports.isJSON=P;exports.setNestedValue=f;
|
|
@@ -1,33 +1,9 @@
|
|
|
1
|
-
import { T_Object } from '../../typescript/index.js';
|
|
2
1
|
/**
|
|
3
2
|
* Check if a string is a valid JSON string.
|
|
4
3
|
* @param str - The string to check.
|
|
5
4
|
* @returns True if the string is a valid JSON string, false otherwise.
|
|
6
5
|
*/
|
|
7
|
-
export declare function
|
|
8
|
-
/**
|
|
9
|
-
* Checks if a value is an object.
|
|
10
|
-
* An object is an object that is not an array, null, or a function.
|
|
11
|
-
* @param val - The value to check.
|
|
12
|
-
* @returns True if the value is an object, false otherwise.
|
|
13
|
-
*/
|
|
14
|
-
export declare function isObject(val: unknown): val is T_Object;
|
|
15
|
-
/**
|
|
16
|
-
* Merges multiple objects deeply.
|
|
17
|
-
* If a property is an array, it will be merged without duplicates.
|
|
18
|
-
* If a property is an object, it will be merged recursively.
|
|
19
|
-
* If a property is a primitive, it will be overwritten.
|
|
20
|
-
* @param objects - The objects to merge.
|
|
21
|
-
* @returns The merged object.
|
|
22
|
-
*/
|
|
23
|
-
export declare function deepMerge(...objects: T_Object[]): T_Object;
|
|
24
|
-
/**
|
|
25
|
-
* This function uses JSON.stringify and JSON.parse to create a deep clone.
|
|
26
|
-
* This method is not suitable for objects with circular references or functions.
|
|
27
|
-
* @param obj - The object to clone.
|
|
28
|
-
* @returns A deep clone of the object.
|
|
29
|
-
*/
|
|
30
|
-
export declare function deepClone<T>(obj: T): T;
|
|
6
|
+
export declare function isJSON(str: string): boolean;
|
|
31
7
|
/**
|
|
32
8
|
* Gets a nested value from an object.
|
|
33
9
|
* @param obj - The object to get the value from.
|
|
@@ -1,73 +1,43 @@
|
|
|
1
|
-
var
|
|
2
|
-
for (var t in
|
|
3
|
-
|
|
4
|
-
if (
|
|
5
|
-
for (var t of
|
|
6
|
-
|
|
7
|
-
return
|
|
8
|
-
},
|
|
9
|
-
function
|
|
1
|
+
var i = Object.defineProperty, _ = Object.defineProperties, l = Object.getOwnPropertyDescriptors, p = Object.getOwnPropertySymbols, c = Object.prototype.hasOwnProperty, O = Object.prototype.propertyIsEnumerable, u = (e, r, t) => r in e ? i(e, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[r] = t, a = (e, r) => {
|
|
2
|
+
for (var t in r || (r = {}))
|
|
3
|
+
c.call(r, t) && u(e, t, r[t]);
|
|
4
|
+
if (p)
|
|
5
|
+
for (var t of p(r))
|
|
6
|
+
O.call(r, t) && u(e, t, r[t]);
|
|
7
|
+
return e;
|
|
8
|
+
}, f = (e, r) => _(e, l(r));
|
|
9
|
+
function P(e) {
|
|
10
10
|
try {
|
|
11
|
-
return JSON.parse(
|
|
12
|
-
} catch (
|
|
11
|
+
return JSON.parse(e), !0;
|
|
12
|
+
} catch (r) {
|
|
13
13
|
return !1;
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
|
-
function
|
|
17
|
-
return
|
|
18
|
-
}
|
|
19
|
-
function P(...r) {
|
|
20
|
-
const e = {};
|
|
21
|
-
for (const t of r.flat())
|
|
22
|
-
for (const [n, o] of Object.entries(t)) {
|
|
23
|
-
const s = e[n];
|
|
24
|
-
if (Array.isArray(o)) {
|
|
25
|
-
const p = Array.isArray(s) ? s : [];
|
|
26
|
-
e[n] = [.../* @__PURE__ */ new Set([...p, ...o])];
|
|
27
|
-
continue;
|
|
28
|
-
}
|
|
29
|
-
if (c(o)) {
|
|
30
|
-
e[n] = P(
|
|
31
|
-
c(s) ? s : {},
|
|
32
|
-
o
|
|
33
|
-
);
|
|
34
|
-
continue;
|
|
35
|
-
}
|
|
36
|
-
e[n] = o;
|
|
37
|
-
}
|
|
38
|
-
return e;
|
|
39
|
-
}
|
|
40
|
-
function w(r) {
|
|
41
|
-
return JSON.parse(JSON.stringify(r));
|
|
42
|
-
}
|
|
43
|
-
function b(r, e) {
|
|
44
|
-
return e.reduce((t, n) => {
|
|
16
|
+
function v(e, r) {
|
|
17
|
+
return r.reduce((t, n) => {
|
|
45
18
|
if (t && typeof t == "object" && n in t)
|
|
46
19
|
return t[n];
|
|
47
|
-
},
|
|
20
|
+
}, e);
|
|
48
21
|
}
|
|
49
|
-
function
|
|
50
|
-
if (
|
|
51
|
-
return
|
|
52
|
-
const [n, ...
|
|
53
|
-
if (
|
|
54
|
-
return a(
|
|
22
|
+
function d(e, r, t) {
|
|
23
|
+
if (r.length === 0)
|
|
24
|
+
return e;
|
|
25
|
+
const [n, ...s] = r;
|
|
26
|
+
if (s.length === 0)
|
|
27
|
+
return f(a({}, e), {
|
|
55
28
|
[n]: t
|
|
56
29
|
});
|
|
57
|
-
const
|
|
58
|
-
return a(
|
|
59
|
-
[n]:
|
|
60
|
-
typeof
|
|
61
|
-
|
|
30
|
+
const o = e[n];
|
|
31
|
+
return f(a({}, e), {
|
|
32
|
+
[n]: d(
|
|
33
|
+
typeof o == "object" && o !== null ? o : {},
|
|
34
|
+
s,
|
|
62
35
|
t
|
|
63
36
|
)
|
|
64
37
|
});
|
|
65
38
|
}
|
|
66
39
|
export {
|
|
67
|
-
|
|
68
|
-
P as
|
|
69
|
-
|
|
70
|
-
v as isJson,
|
|
71
|
-
c as isObject,
|
|
72
|
-
g as setNestedValue
|
|
40
|
+
v as getNestedValue,
|
|
41
|
+
P as isJSON,
|
|
42
|
+
d as setNestedValue
|
|
73
43
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("crypto-js"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("crypto-js"),c=require("lodash-es"),s=require("slugify");var f=Object.defineProperty,u=Object.getOwnPropertySymbols,d=Object.prototype.hasOwnProperty,g=Object.prototype.propertyIsEnumerable,i=(r,e,t)=>e in r?f(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,O=(r,e)=>{for(var t in e||(e={}))d.call(e,t)&&i(r,t,e[t]);if(u)for(var t of u(e))g.call(e,t)&&i(r,t,e[t]);return r};const m=s.default||s;function w(r,e){const t=n=>{var o,l;return m(n!=null?n:"",O({lower:(o=e==null?void 0:e.lower)!=null?o:!0,locale:(l=e==null?void 0:e.locale)!=null?l:"vi"},e))};if(c.isObject(r)){const n={};for(const[o,l]of Object.entries(r))n[o]=t(l);return n}return t(r)}function y(r,e=4){return a.SHA256(r).toString(a.enc.Hex).slice(0,e)}function _(r=8){const e="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+[]{}|;:,.<>?";let t="";for(let n=0;n<r;n++){const o=Math.floor(Math.random()*e.length);t+=e.charAt(o)}return t}function h(r="",e=!1){const t=r.split(/[?#]/)[0]||"",n=t.substring(t.lastIndexOf("/")+1);if(e)return n;const o=n.lastIndexOf(".");return o>0?n.slice(0,o):n}function p(r,e,t){const n=r.indexOf(e);if(n===-1)return"";const o=n+e.length,l=r.indexOf(t,o);return l===-1?"":r.slice(o,l)}exports.generateRandomPassword=_;exports.generateShortId=y;exports.generateSlug=w;exports.getFileName=h;exports.substringBetween=p;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import a from "crypto-js";
|
|
2
|
+
import { isObject as u } from "lodash-es";
|
|
2
3
|
import s from "slugify";
|
|
3
|
-
import { isObject as u } from "../object/object.util.js";
|
|
4
4
|
var c = Object.defineProperty, f = Object.getOwnPropertySymbols, d = Object.prototype.hasOwnProperty, m = Object.prototype.propertyIsEnumerable, i = (e, r, t) => r in e ? c(e, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[r] = t, g = (e, r) => {
|
|
5
5
|
for (var t in r || (r = {}))
|
|
6
6
|
d.call(r, t) && i(e, t, r[t]);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cyberskill/shared",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.215.0",
|
|
5
5
|
"description": "CyberSkill Shared",
|
|
6
6
|
"author": "Stephen Cheng",
|
|
7
7
|
"license": "MIT",
|
|
@@ -244,6 +244,7 @@
|
|
|
244
244
|
"i18next": "25.3.2",
|
|
245
245
|
"jsdom": "26.1.0",
|
|
246
246
|
"localforage": "1.10.0",
|
|
247
|
+
"lodash-es": "4.17.21",
|
|
247
248
|
"migrate-mongo": "12.1.3",
|
|
248
249
|
"mongodb": "6.17.0",
|
|
249
250
|
"mongoose": "8.16.3",
|
|
@@ -282,6 +283,7 @@
|
|
|
282
283
|
"@types/express-useragent": "1.0.5",
|
|
283
284
|
"@types/fs-extra": "11.0.4",
|
|
284
285
|
"@types/graphql-upload": "17.0.0",
|
|
286
|
+
"@types/lodash-es": "4.17.12",
|
|
285
287
|
"@types/migrate-mongo": "10.0.5",
|
|
286
288
|
"@types/node": "24.0.13",
|
|
287
289
|
"@types/node-persist": "3.1.8",
|