gina 0.0.9-p91c → 0.1.1-alpha.3
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/INSTALL.md +46 -0
- package/{core/asset/html/static.html → Icon/r} +0 -0
- package/LICENSE +1 -1
- package/README-4Contributors.md +96 -0
- package/README.md +296 -104
- package/bin/cli +287 -0
- package/bin/cli-debug +60 -0
- package/bin/cmd +184 -0
- package/bin/gina +180 -0
- package/config/logger.json +17 -0
- package/doc/framework/cli/doc.json +9 -0
- package/doc/framework/index.md +60 -0
- package/framework/v0.1.1-alpha.3/AUTHORS +7 -0
- package/{core/utils/lib/inherits → framework/v0.1.1-alpha.3}/LICENSE +1 -1
- package/framework/v0.1.1-alpha.3/VERSION +1 -0
- package/{core/locales/dist/language/en.json → framework/v0.1.1-alpha.3/core/asset/html/nolayout.html} +0 -0
- package/{core/locales/dist/language/fr.json → framework/v0.1.1-alpha.3/core/asset/html/static.html} +0 -0
- package/{core → framework/v0.1.1-alpha.3/core}/asset/img/android-chrome-192x192.png +0 -0
- package/{core → framework/v0.1.1-alpha.3/core}/asset/img/android-chrome-512x512.png +0 -0
- package/{core → framework/v0.1.1-alpha.3/core}/asset/img/apple-touch-icon.png +0 -0
- package/{core → framework/v0.1.1-alpha.3/core}/asset/img/favicon-16x16.png +0 -0
- package/{core → framework/v0.1.1-alpha.3/core}/asset/img/favicon-32x32.png +0 -0
- package/{core → framework/v0.1.1-alpha.3/core}/asset/img/favicon.ico +0 -0
- package/framework/v0.1.1-alpha.3/core/asset/js/plugin/dist/gina.js +20904 -0
- package/framework/v0.1.1-alpha.3/core/asset/js/plugin/dist/gina.js.map +56 -0
- package/framework/v0.1.1-alpha.3/core/asset/js/plugin/dist/gina.min.css +1 -0
- package/framework/v0.1.1-alpha.3/core/asset/js/plugin/dist/gina.min.css.map +1 -0
- package/framework/v0.1.1-alpha.3/core/asset/js/plugin/dist/gina.min.js +736 -0
- package/framework/v0.1.1-alpha.3/core/asset/js/plugin/dist/gina.min.js.map +56 -0
- package/framework/v0.1.1-alpha.3/core/asset/js/plugin/dist/gina.onload.min.js +5 -0
- package/framework/v0.1.1-alpha.3/core/asset/js/plugin/dist/gina.onload.min.js.map +8 -0
- package/framework/v0.1.1-alpha.3/core/asset/js/plugin/readme.md +192 -0
- package/framework/v0.1.1-alpha.3/core/asset/js/plugin/uuid.json +23 -0
- package/framework/v0.1.1-alpha.3/core/config.js +2308 -0
- package/framework/v0.1.1-alpha.3/core/connectors/couchbase/index.js +757 -0
- package/framework/v0.1.1-alpha.3/core/connectors/couchbase/lib/connector.js +20 -0
- package/framework/v0.1.1-alpha.3/core/connectors/couchbase/lib/connector.v2.js +429 -0
- package/framework/v0.1.1-alpha.3/core/connectors/couchbase/lib/connector.v3.js +432 -0
- package/framework/v0.1.1-alpha.3/core/connectors/couchbase/lib/n1ql.js +14 -0
- package/framework/v0.1.1-alpha.3/core/connectors/couchbase/lib/session-store.js +21 -0
- package/framework/v0.1.1-alpha.3/core/connectors/couchbase/lib/session-store.v2.js +258 -0
- package/framework/v0.1.1-alpha.3/core/connectors/couchbase/lib/session-store.v3.js +341 -0
- package/{core → framework/v0.1.1-alpha.3/core}/controller/controller.framework.js +3 -2
- package/framework/v0.1.1-alpha.3/core/controller/controller.js +3990 -0
- package/{core → framework/v0.1.1-alpha.3/core}/controller/index.js +5 -5
- package/framework/v0.1.1-alpha.3/core/deps/busboy/.travis.yml +17 -0
- package/framework/v0.1.1-alpha.3/core/deps/busboy/LICENSE +19 -0
- package/framework/v0.1.1-alpha.3/core/deps/busboy/README.md +225 -0
- package/framework/v0.1.1-alpha.3/core/deps/busboy/deps/encoding/encoding-indexes.js +73 -0
- package/framework/v0.1.1-alpha.3/core/deps/busboy/deps/encoding/encoding.js +2391 -0
- package/framework/v0.1.1-alpha.3/core/deps/busboy/lib/main.js +89 -0
- package/framework/v0.1.1-alpha.3/core/deps/busboy/lib/types/multipart.js +328 -0
- package/framework/v0.1.1-alpha.3/core/deps/busboy/lib/types/urlencoded.js +214 -0
- package/framework/v0.1.1-alpha.3/core/deps/busboy/lib/utils.js +191 -0
- package/framework/v0.1.1-alpha.3/core/deps/busboy/package.json +69 -0
- package/framework/v0.1.1-alpha.3/core/deps/swig-client/swig-2.0.0.min.js +5 -0
- package/{core → framework/v0.1.1-alpha.3/core}/dev/index.js +5 -5
- package/{core → framework/v0.1.1-alpha.3/core}/dev/lib/class.js +1 -1
- package/{core → framework/v0.1.1-alpha.3/core}/dev/lib/factory.js +1 -1
- package/{core → framework/v0.1.1-alpha.3/core}/dev/lib/tools.js +0 -0
- package/framework/v0.1.1-alpha.3/core/gna.js +1070 -0
- package/{core → framework/v0.1.1-alpha.3/core}/locales/README.md +41 -2
- package/{core → framework/v0.1.1-alpha.3/core}/locales/currency.json +0 -0
- package/{core/plugins/README.md → framework/v0.1.1-alpha.3/core/locales/dist/language/en.json} +0 -0
- package/{core/plugins/lib/intl/README.md → framework/v0.1.1-alpha.3/core/locales/dist/language/fr.json} +0 -0
- package/{core → framework/v0.1.1-alpha.3/core}/locales/dist/region/en.json +0 -0
- package/framework/v0.1.1-alpha.3/core/locales/dist/region/fr.json +9492 -0
- package/{core → framework/v0.1.1-alpha.3/core}/locales/index.js +5 -4
- package/{core → framework/v0.1.1-alpha.3/core}/locales/src/make.js +15 -12
- package/{core → framework/v0.1.1-alpha.3/core}/locales/src/resources/currency.csv +0 -0
- package/{core → framework/v0.1.1-alpha.3/core}/locales/src/resources/region.csv +0 -0
- package/{core → framework/v0.1.1-alpha.3/core}/locales/src/resources/region.mapping.json +0 -0
- package/{core → framework/v0.1.1-alpha.3/core}/mime.types +0 -0
- package/{core → framework/v0.1.1-alpha.3/core}/model/entity.js +156 -196
- package/{core → framework/v0.1.1-alpha.3/core}/model/index.js +67 -48
- package/{core → framework/v0.1.1-alpha.3/core}/model/template/entityFactory.js +2 -2
- package/{core → framework/v0.1.1-alpha.3/core}/model/template/index.js +8 -10
- package/{core/plugins/lib/storage → framework/v0.1.1-alpha.3/core/plugins}/README.md +0 -0
- package/{core → framework/v0.1.1-alpha.3/core}/plugins/index.js +3 -3
- package/{core/plugins/lib/validator → framework/v0.1.1-alpha.3/core/plugins/lib/file}/README.md +0 -0
- package/{core/plugins/lib/intl → framework/v0.1.1-alpha.3/core/plugins/lib/file}/build.json +0 -0
- package/framework/v0.1.1-alpha.3/core/plugins/lib/file/package.json +25 -0
- package/{core/utils/lib/collection → framework/v0.1.1-alpha.3/core/plugins/lib/intl}/README.md +0 -0
- package/{core/plugins/lib/storage → framework/v0.1.1-alpha.3/core/plugins/lib/intl}/build.json +0 -0
- package/{core → framework/v0.1.1-alpha.3/core}/plugins/lib/intl/package.json +3 -3
- package/{core → framework/v0.1.1-alpha.3/core}/plugins/lib/intl/src/main.js +17 -1
- package/{core/utils/lib/routing → framework/v0.1.1-alpha.3/core/plugins/lib/storage}/README.md +0 -0
- package/{core/plugins/lib/validator → framework/v0.1.1-alpha.3/core/plugins/lib/storage}/build.json +0 -0
- package/{core → framework/v0.1.1-alpha.3/core}/plugins/lib/storage/package.json +2 -2
- package/{core → framework/v0.1.1-alpha.3/core}/plugins/lib/storage/src/main.js +91 -85
- package/{core/utils/lib/url → framework/v0.1.1-alpha.3/core/plugins/lib/validator}/README.md +0 -0
- package/{core/utils/lib/collection → framework/v0.1.1-alpha.3/core/plugins/lib/validator}/build.json +0 -0
- package/{core → framework/v0.1.1-alpha.3/core}/plugins/lib/validator/package.json +3 -3
- package/framework/v0.1.1-alpha.3/core/plugins/lib/validator/src/form-validator.js +1762 -0
- package/framework/v0.1.1-alpha.3/core/plugins/lib/validator/src/main.js +6917 -0
- package/framework/v0.1.1-alpha.3/core/router.js +664 -0
- package/framework/v0.1.1-alpha.3/core/server.express.js +213 -0
- package/framework/v0.1.1-alpha.3/core/server.isaac.js +386 -0
- package/framework/v0.1.1-alpha.3/core/server.js +3010 -0
- package/{core → framework/v0.1.1-alpha.3/core}/status.codes +8 -0
- package/framework/v0.1.1-alpha.3/core/template/boilerplate/bundle/config/app.json +6 -0
- package/framework/v0.1.1-alpha.3/core/template/boilerplate/bundle/config/routing.json +11 -0
- package/framework/v0.1.1-alpha.3/core/template/boilerplate/bundle/config/settings.json +9 -0
- package/framework/v0.1.1-alpha.3/core/template/boilerplate/bundle/config/settings.server.json +30 -0
- package/framework/v0.1.1-alpha.3/core/template/boilerplate/bundle/config/templates.json +42 -0
- package/framework/v0.1.1-alpha.3/core/template/boilerplate/bundle/controllers/controller.content.js +39 -0
- package/framework/v0.1.1-alpha.3/core/template/boilerplate/bundle/controllers/controller.js +30 -0
- package/framework/v0.1.1-alpha.3/core/template/boilerplate/bundle/controllers/setup.js +111 -0
- package/{core/template/samples → framework/v0.1.1-alpha.3/core/template/boilerplate}/bundle/index.js +0 -0
- package/{core/template/samples/bundle → framework/v0.1.1-alpha.3/core/template/boilerplate/bundle_namespace}/controllers/controller.js +9 -7
- package/{core/template/views → framework/v0.1.1-alpha.3/core/template/boilerplate/bundle_public}/css/default.css +0 -0
- package/{core/template/views → framework/v0.1.1-alpha.3/core/template/boilerplate/bundle_public}/css/vendor/readme.md +0 -0
- package/{core/template/views → framework/v0.1.1-alpha.3/core/template/boilerplate/bundle_public}/favicon.ico +0 -0
- package/framework/v0.1.1-alpha.3/core/template/boilerplate/bundle_public/js/vendor/readme.md +1 -0
- package/framework/v0.1.1-alpha.3/core/template/boilerplate/bundle_public/readme.md +1 -0
- package/framework/v0.1.1-alpha.3/core/template/boilerplate/bundle_templates/handlers/main.js +24 -0
- package/{core/template/views/html/default.html → framework/v0.1.1-alpha.3/core/template/boilerplate/bundle_templates/html/homepage.html} +0 -0
- package/{core/template/views/html/layout.html → framework/v0.1.1-alpha.3/core/template/boilerplate/bundle_templates/html/layout/main.html} +2 -2
- package/{core → framework/v0.1.1-alpha.3/core}/template/command/gina.bat.tpl +0 -0
- package/{core → framework/v0.1.1-alpha.3/core}/template/command/gina.tpl +1 -1
- package/framework/v0.1.1-alpha.3/core/template/conf/env.json +76 -0
- package/{core/template/conf/project.json → framework/v0.1.1-alpha.3/core/template/conf/manifest.json} +1 -0
- package/{core → framework/v0.1.1-alpha.3/core}/template/conf/package.json +2 -2
- package/framework/v0.1.1-alpha.3/core/template/conf/settings.json +92 -0
- package/framework/v0.1.1-alpha.3/core/template/conf/statics.json +10 -0
- package/framework/v0.1.1-alpha.3/core/template/conf/templates.json +37 -0
- package/{core → framework/v0.1.1-alpha.3/core}/template/error/client/json/401.json +0 -0
- package/{core → framework/v0.1.1-alpha.3/core}/template/error/client/json/403.json +0 -0
- package/{core → framework/v0.1.1-alpha.3/core}/template/error/client/json/404.json +0 -0
- package/{core → framework/v0.1.1-alpha.3/core}/template/error/server/html/50x.html +0 -0
- package/{core → framework/v0.1.1-alpha.3/core}/template/error/server/json/500.json +0 -0
- package/{core → framework/v0.1.1-alpha.3/core}/template/error/server/json/503.json +0 -0
- package/{core/utils/lib/routing/build.json → framework/v0.1.1-alpha.3/core/template/extensions/logger/config.json} +0 -0
- package/{core/utils → framework/v0.1.1-alpha.3}/helpers/console.js +3 -3
- package/{core/utils → framework/v0.1.1-alpha.3}/helpers/context.js +240 -49
- package/framework/v0.1.1-alpha.3/helpers/dateFormat.js +528 -0
- package/framework/v0.1.1-alpha.3/helpers/index.js +79 -0
- package/framework/v0.1.1-alpha.3/helpers/json/README.md +0 -0
- package/framework/v0.1.1-alpha.3/helpers/json/package.json +20 -0
- package/framework/v0.1.1-alpha.3/helpers/json/src/main.js +97 -0
- package/{core/utils → framework/v0.1.1-alpha.3}/helpers/path.js +342 -140
- package/framework/v0.1.1-alpha.3/helpers/plugins/README.md +4 -0
- package/framework/v0.1.1-alpha.3/helpers/plugins/package.json +20 -0
- package/framework/v0.1.1-alpha.3/helpers/plugins/src/api-error.js +160 -0
- package/framework/v0.1.1-alpha.3/helpers/plugins/src/main.js +32 -0
- package/framework/v0.1.1-alpha.3/helpers/prototypes.js +218 -0
- package/{core/utils → framework/v0.1.1-alpha.3}/helpers/task.js +49 -29
- package/{core/utils → framework/v0.1.1-alpha.3}/helpers/text.js +7 -7
- package/framework/v0.1.1-alpha.3/lib/archiver/README.md +0 -0
- package/framework/v0.1.1-alpha.3/lib/archiver/build.json +0 -0
- package/framework/v0.1.1-alpha.3/lib/archiver/package.json +20 -0
- package/framework/v0.1.1-alpha.3/lib/archiver/src/dep/jszip.min.js +15 -0
- package/framework/v0.1.1-alpha.3/lib/archiver/src/main.js +499 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/aliases.json +13 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/bundle/add.js +507 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/bundle/arguments.json +4 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/bundle/copy.js +15 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/bundle/cp.js +2 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/bundle/help.js +28 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/bundle/help.txt +67 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/bundle/list.js +129 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/bundle/remove.js +229 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/bundle/rename.js +4 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/bundle/restart.js +235 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/bundle/rm.js +2 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/bundle/start.js +394 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/bundle/status.js +3 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/bundle/stop.js +232 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/env/add.js +436 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/env/get.js +62 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/env/help.js +28 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/env/help.txt +33 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/env/link-dev.js +80 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/env/list.js +111 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/env/remove.js +150 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/env/rm.js +2 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/env/set.js +57 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/env/unset.js +44 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/env/use.js +79 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/framework/dot.js +70 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/framework/get.js +0 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/framework/help.js +39 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/framework/help.txt +31 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/framework/init.js +514 -0
- package/{core/utils/lib/cmd → framework/v0.1.1-alpha.3/lib/cmd/framework}/msg.json +3 -3
- package/framework/v0.1.1-alpha.3/lib/cmd/framework/open.js +50 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/framework/restart.js +124 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/framework/set.js +161 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/framework/start.js +96 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/framework/status.js +72 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/framework/stop.js +159 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/framework/tail.js +183 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/framework/update.js +0 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/framework/version.js +44 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/gina-dev.1.md +66 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/gina-framework.1.md +100 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/gina.1.md +79 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/helper.js +1147 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/index.js +170 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/msg.json +20 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/port/help.js +28 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/port/help.txt +31 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/port/inc/scan.js +108 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/port/list.js +176 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/port/set.js +0 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/project/add.js +528 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/project/arguments.json +9 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/project/build.js +115 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/project/help.js +28 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/project/help.txt +76 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/project/import.js +2 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/project/list.js +55 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/project/move.js +0 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/project/remove.js +144 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/project/rename.js +162 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/project/restart.js +0 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/project/rm.js +2 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/project/start.js +0 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/project/status.js +3 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/project/stop.js +0 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/protocol/help.js +27 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/protocol/help.txt +57 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/protocol/list.js +239 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/protocol/set.js +631 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/scope/help.js +28 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/scope/help.txt +33 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/scope/link-local.js +80 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/scope/list.js +116 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/scope/remove.js +150 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/scope/rm.js +2 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/scope/set.js +57 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/scope/unset.js +44 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/scope/use.js +79 -0
- package/framework/v0.1.1-alpha.3/lib/cmd/view/add.js +311 -0
- package/framework/v0.1.1-alpha.3/lib/collection/README.md +5 -0
- package/framework/v0.1.1-alpha.3/lib/collection/build.json +0 -0
- package/{core/utils → framework/v0.1.1-alpha.3}/lib/collection/package.json +2 -2
- package/framework/v0.1.1-alpha.3/lib/collection/src/main.js +1459 -0
- package/{core/utils → framework/v0.1.1-alpha.3}/lib/config.js +49 -34
- package/framework/v0.1.1-alpha.3/lib/cron/README.md +7 -0
- package/framework/v0.1.1-alpha.3/lib/cron/package.json +20 -0
- package/framework/v0.1.1-alpha.3/lib/cron/src/main.js +176 -0
- package/{core/utils → framework/v0.1.1-alpha.3}/lib/generator/index.js +8 -4
- package/framework/v0.1.1-alpha.3/lib/index.js +116 -0
- package/framework/v0.1.1-alpha.3/lib/inherits/LICENSE +19 -0
- package/{core/utils → framework/v0.1.1-alpha.3}/lib/inherits/README.md +0 -0
- package/{core/utils → framework/v0.1.1-alpha.3}/lib/inherits/example/inheriting_eventemitter.js +0 -0
- package/{core/utils → framework/v0.1.1-alpha.3}/lib/inherits/example/protected_inheritance.js +0 -0
- package/{core/utils → framework/v0.1.1-alpha.3}/lib/inherits/example/simple_inheritance.js +0 -0
- package/{core/utils → framework/v0.1.1-alpha.3}/lib/inherits/example/super_attribute_overridden_by_child_on_init.js +0 -0
- package/{core/utils → framework/v0.1.1-alpha.3}/lib/inherits/package.json +2 -2
- package/{core/utils → framework/v0.1.1-alpha.3}/lib/inherits/src/main.js +18 -19
- package/framework/v0.1.1-alpha.3/lib/logger/README.md +7 -0
- package/framework/v0.1.1-alpha.3/lib/logger/package.json +20 -0
- package/framework/v0.1.1-alpha.3/lib/logger/src/containers/default/index.js +55 -0
- package/framework/v0.1.1-alpha.3/lib/logger/src/containers/file/index.js +251 -0
- package/framework/v0.1.1-alpha.3/lib/logger/src/containers/file/lib/logrotator/README.md +100 -0
- package/framework/v0.1.1-alpha.3/lib/logger/src/containers/file/lib/logrotator/index.js +274 -0
- package/framework/v0.1.1-alpha.3/lib/logger/src/containers/mq/index.js +52 -0
- package/framework/v0.1.1-alpha.3/lib/logger/src/containers/mq/listener.js +302 -0
- package/framework/v0.1.1-alpha.3/lib/logger/src/containers/mq/speaker.js +118 -0
- package/framework/v0.1.1-alpha.3/lib/logger/src/helper.js +131 -0
- package/framework/v0.1.1-alpha.3/lib/logger/src/main.js +739 -0
- package/{core/utils → framework/v0.1.1-alpha.3}/lib/math/index.js +58 -35
- package/{core/utils → framework/v0.1.1-alpha.3}/lib/merge/README.md +5 -0
- package/{core/utils → framework/v0.1.1-alpha.3}/lib/merge/example/merge.js +1 -1
- package/{core/utils → framework/v0.1.1-alpha.3}/lib/merge/example/merge_2_literal objects.js +0 -0
- package/{core/utils → framework/v0.1.1-alpha.3}/lib/merge/example/merge_and_preserve_first.js +2 -0
- package/{core/utils → framework/v0.1.1-alpha.3}/lib/merge/package.json +2 -2
- package/framework/v0.1.1-alpha.3/lib/merge/src/main.js +531 -0
- package/{core/utils → framework/v0.1.1-alpha.3}/lib/model.js +42 -19
- package/framework/v0.1.1-alpha.3/lib/proc.js +518 -0
- package/framework/v0.1.1-alpha.3/lib/routing/README.md +0 -0
- package/framework/v0.1.1-alpha.3/lib/routing/build.json +0 -0
- package/{core/utils → framework/v0.1.1-alpha.3}/lib/routing/package.json +2 -2
- package/framework/v0.1.1-alpha.3/lib/routing/src/main.js +1492 -0
- package/framework/v0.1.1-alpha.3/lib/session-store.js +33 -0
- package/{core/utils → framework/v0.1.1-alpha.3}/lib/shell.js +43 -30
- package/framework/v0.1.1-alpha.3/lib/swig-filters/README.md +0 -0
- package/framework/v0.1.1-alpha.3/lib/swig-filters/package.json +20 -0
- package/framework/v0.1.1-alpha.3/lib/swig-filters/src/main.js +322 -0
- package/framework/v0.1.1-alpha.3/lib/url/README.md +0 -0
- package/{core/utils → framework/v0.1.1-alpha.3}/lib/url/index.js +2 -1
- package/{core/utils → framework/v0.1.1-alpha.3}/lib/url/mocks.json +0 -0
- package/{core/utils → framework/v0.1.1-alpha.3}/lib/url/routing.json +9 -9
- package/{core/utils → framework/v0.1.1-alpha.3}/lib/url/test.js +0 -0
- package/{core/utils → framework/v0.1.1-alpha.3}/lib/validator.js +7 -7
- package/framework/v0.1.1-alpha.3/package.json +14 -0
- package/package.json +35 -33
- package/resources/etc/init.d/debian/gina +117 -0
- package/resources/home/framework/env.json +34 -0
- package/resources/home/framework/locals.json +14 -0
- package/resources/home/framework/project.json +48 -0
- package/resources/home/framework/projects.json +6 -0
- package/resources/home/main.json +47 -0
- package/resources/home/settings.json +22 -0
- package/resources/home/user/extensions/logger/default/config.json +77 -0
- package/resources/home/user/extensions/logger/file/config.json +11 -0
- package/resources/img/android-chrome-192x192.png +0 -0
- package/resources/img/android-chrome-512x512.png +0 -0
- package/resources/img/apple-touch-icon.png +0 -0
- package/resources/img/favicon-16x16.png +0 -0
- package/resources/img/favicon-32x32.png +0 -0
- package/resources/img/favicon.ico +0 -0
- package/resources/package.json.template +50 -0
- package/script/lib.js +24 -0
- package/script/post_install.js +449 -157
- package/script/pre_install.js +277 -36
- package/script/prepare_version.js +425 -0
- package/utils/helper.js +438 -0
- package/utils/prototypes.js +239 -0
- package/utils/prototypes.json_clone.js +175 -0
- package/.npmignore +0 -6
- package/MIDDLEWARE +0 -1
- package/SUCCESS +0 -1
- package/VERSION +0 -1
- package/core/asset/html/nolayout.html +0 -1
- package/core/asset/js/plugin/build.dev.json +0 -28
- package/core/asset/js/plugin/build.json +0 -31
- package/core/asset/js/plugin/dist/gina.min.css +0 -1
- package/core/asset/js/plugin/dist/gina.min.css.map +0 -1
- package/core/asset/js/plugin/dist/gina.min.js +0 -13732
- package/core/asset/js/plugin/dist/gina.min.js.map +0 -42
- package/core/asset/js/plugin/dist/gina.onload.min.js +0 -3
- package/core/asset/js/plugin/dist/gina.onload.min.js.map +0 -8
- package/core/asset/js/plugin/readme.md +0 -152
- package/core/asset/js/plugin/src/gina/main.js +0 -132
- package/core/asset/js/plugin/src/gina/popin/css/design.css +0 -23
- package/core/asset/js/plugin/src/gina/popin/css/main.css +0 -1112
- package/core/asset/js/plugin/src/gina/popin/css/popin.css +0 -3
- package/core/asset/js/plugin/src/gina/popin/css/popin.css.map +0 -1
- package/core/asset/js/plugin/src/gina/popin/doc/TOC.md +0 -29
- package/core/asset/js/plugin/src/gina/popin/doc/css.md +0 -162
- package/core/asset/js/plugin/src/gina/popin/doc/extend.md +0 -663
- package/core/asset/js/plugin/src/gina/popin/doc/faq.md +0 -46
- package/core/asset/js/plugin/src/gina/popin/doc/html.md +0 -227
- package/core/asset/js/plugin/src/gina/popin/doc/js.md +0 -37
- package/core/asset/js/plugin/src/gina/popin/doc/misc.md +0 -178
- package/core/asset/js/plugin/src/gina/popin/doc/usage.md +0 -130
- package/core/asset/js/plugin/src/gina/popin/main.js +0 -783
- package/core/asset/js/plugin/src/gina/popin/sass/config.sass +0 -37
- package/core/asset/js/plugin/src/gina/popin/sass/gina-design.sass +0 -622
- package/core/asset/js/plugin/src/gina/popin/sass/gina-popin.sass +0 -54
- package/core/asset/js/plugin/src/gina/popin/sass/helper.scss +0 -73
- package/core/asset/js/plugin/src/gina/toolbar/.npmignore +0 -19
- package/core/asset/js/plugin/src/gina/toolbar/css/toolbar.css +0 -433
- package/core/asset/js/plugin/src/gina/toolbar/css/toolbar.css.map +0 -1
- package/core/asset/js/plugin/src/gina/toolbar/index.html +0 -285
- package/core/asset/js/plugin/src/gina/toolbar/index.kit +0 -120
- package/core/asset/js/plugin/src/gina/toolbar/jquery-3.1.0.min.js +0 -4
- package/core/asset/js/plugin/src/gina/toolbar/main.js +0 -693
- package/core/asset/js/plugin/src/gina/toolbar/mock.gina.json +0 -1
- package/core/asset/js/plugin/src/gina/toolbar/mock.user.json +0 -1
- package/core/asset/js/plugin/src/gina/toolbar/readme.md +0 -7
- package/core/asset/js/plugin/src/gina/toolbar/sass/toolbar.sass +0 -563
- package/core/asset/js/plugin/src/gina/toolbar/svg-src/Info-color.svg +0 -1
- package/core/asset/js/plugin/src/gina/toolbar/svg-src/Info-grey.svg +0 -1
- package/core/asset/js/plugin/src/gina/toolbar/svg-src/error-color.svg +0 -1
- package/core/asset/js/plugin/src/gina/toolbar/svg-src/error-grey.svg +0 -1
- package/core/asset/js/plugin/src/gina/toolbar/svg-src/info-optim.svg +0 -13
- package/core/asset/js/plugin/src/gina/toolbar/svg-src/logo-gina.svg +0 -1
- package/core/asset/js/plugin/src/gina/toolbar/svg-src/settings-big.svg +0 -1
- package/core/asset/js/plugin/src/gina/toolbar/svg-src/settings.afdesign +0 -0
- package/core/asset/js/plugin/src/gina/toolbar/svg-src/settings.svg +0 -1
- package/core/asset/js/plugin/src/gina/toolbar/svg-src/stripe-calendar-optim.svg +0 -1
- package/core/asset/js/plugin/src/gina/toolbar/svg-src/stripe-calendar.svg +0 -1
- package/core/asset/js/plugin/src/gina/toolbar/svg-src/stripe-card-optim.svg +0 -1
- package/core/asset/js/plugin/src/gina/toolbar/svg-src/stripe-card.svg +0 -1
- package/core/asset/js/plugin/src/gina/toolbar/svg-src/stripe-lock-optim.svg +0 -1
- package/core/asset/js/plugin/src/gina/toolbar/svg-src/stripe-lock.svg +0 -1
- package/core/asset/js/plugin/src/gina/toolbar/svg-src/warning-color.svg +0 -1
- package/core/asset/js/plugin/src/gina/toolbar/svg-src/warning-grey.svg +0 -1
- package/core/asset/js/plugin/src/gina/toolbar/test.jpg +0 -0
- package/core/asset/js/plugin/src/gina/toolbar/toolbar.html +0 -104
- package/core/asset/js/plugin/src/gina/utils/dom.js +0 -24
- package/core/asset/js/plugin/src/gina/utils/events.js +0 -201
- package/core/asset/js/plugin/src/gina/utils/loader.js +0 -57
- package/core/asset/js/plugin/src/main.js +0 -235
- package/core/asset/js/plugin/src/vendor/jquery/1.11.1-css-event_alias.min.js +0 -5
- package/core/asset/js/plugin/src/vendor/jquery/1.12.4.min.js +0 -5
- package/core/asset/js/plugin/src/vendor/jquery/2.1.1-css-event_alias-sizzle.min.js +0 -4
- package/core/asset/js/plugin/src/vendor/jquery/README.md +0 -14
- package/core/asset/js/plugin/src/vendor/jquery/slim-3.1.1.min.js +0 -4
- package/core/config.js +0 -1225
- package/core/controller/controller.js +0 -1860
- package/core/gna.js +0 -908
- package/core/plugins/lib/validator/src/form-validator.js +0 -789
- package/core/plugins/lib/validator/src/main.js +0 -2056
- package/core/router.js +0 -717
- package/core/server.js +0 -1363
- package/core/template/conf/env.json +0 -70
- package/core/template/conf/settings.json +0 -48
- package/core/template/conf/statics.json +0 -6
- package/core/template/conf/views.json +0 -16
- package/core/template/samples/bundle/config/app.json +0 -4
- package/core/template/samples/bundle/config/routing.json +0 -9
- package/core/template/samples/bundle/controllers/setup.js +0 -33
- package/core/template/views/js/vendor/readme.md +0 -1
- package/core/template/views/readme.md +0 -1
- package/core/utils/helpers/dateFormat.js +0 -264
- package/core/utils/helpers/index.js +0 -202
- package/core/utils/index.js +0 -75
- package/core/utils/lib/cmd/app.js +0 -686
- package/core/utils/lib/cmd/basic.help.txt +0 -40
- package/core/utils/lib/cmd/basic.js +0 -141
- package/core/utils/lib/cmd/gina-add-bundle.js +0 -328
- package/core/utils/lib/cmd/gina-add-views.js +0 -99
- package/core/utils/lib/cmd/gina-build.js +0 -218
- package/core/utils/lib/cmd/gina-clean.js +0 -26
- package/core/utils/lib/cmd/gina-connect.js +0 -176
- package/core/utils/lib/cmd/gina-delete-bundle.js +0 -176
- package/core/utils/lib/cmd/gina-deploy.js +0 -452
- package/core/utils/lib/cmd/gina-init-project.js +0 -83
- package/core/utils/lib/cmd/gina-start-bundle.js +0 -3
- package/core/utils/lib/cmd/gina-start.js +0 -3
- package/core/utils/lib/cmd/index.js +0 -157
- package/core/utils/lib/cmd/project.js +0 -14
- package/core/utils/lib/collection/src/main.js +0 -650
- package/core/utils/lib/logger/containers/file.js +0 -11
- package/core/utils/lib/logger/index.js +0 -260
- package/core/utils/lib/merge/src/main.js +0 -344
- package/core/utils/lib/proc.js +0 -416
- package/core/utils/lib/routing/src/main.js +0 -165
- package/documentation/css/default.css +0 -3
- package/documentation/html/home.html +0 -6
- package/documentation/html/inc/_footer.html +0 -5
- package/documentation/html/layout.html +0 -21
- package/documentation/img/debug-conf1.png +0 -0
- package/documentation/img/debug-conf2.png +0 -0
- package/documentation/img/debug-conf3.png +0 -0
- package/documentation/img/debug-conf4.png +0 -0
- package/documentation/img/debug-conf5.png +0 -0
- package/documentation/img/debug-conf6.png +0 -0
- package/documentation/img/debug-conf7.png +0 -0
- package/documentation/img/debug-new1.png +0 -0
- package/documentation/img/debug-new2.png +0 -0
- package/documentation/img/debug-start.png +0 -0
- package/documentation/md/api/controller/main.md +0 -74
- package/migration_note.md +0 -7
- package/package-lock.json +0 -611
- package/script/pre_publish.js +0 -207
- package/tutorial/Commands/README.md +0 -56
- package/tutorial/Commands/add-bundle-result.png +0 -0
- package/tutorial/Commands/add-bundle.png +0 -0
- package/tutorial/Commands/delete-bundle.png +0 -0
- package/tutorial/Commands/help.png +0 -0
- package/tutorial/Commands/init-project.png +0 -0
- package/tutorial/Commands/start-bundle-result.png +0 -0
- package/tutorial/Commands/start-bundle-stop.png +0 -0
- package/tutorial/Commands/start-bundle.png +0 -0
- package/tutorial/Commands/version.png +0 -0
- package/tutorial/ETC/README.md +0 -74
- package/tutorial/ETC/add-bundle-result.png +0 -0
- package/tutorial/ETC/add-bundle.png +0 -0
- package/tutorial/ETC/init-project.png +0 -0
- package/tutorial/Install/README.md +0 -54
- package/tutorial/Install/git-get.png +0 -0
- package/tutorial/Install/git-install-end.png +0 -0
- package/tutorial/Install/git-install-result.png +0 -0
- package/tutorial/Install/git-install-start.png +0 -0
- package/tutorial/Install/install-end.png +0 -0
- package/tutorial/Install/install-result.png +0 -0
- package/tutorial/Install/install-start.png +0 -0
- package/tutorial/WebStorm/README.md +0 -30
- package/tutorial/WebStorm/closure-compiler.png +0 -0
- package/tutorial/WebStorm/sass.png +0 -0
|
@@ -0,0 +1,1459 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
if ( typeof(module) !== 'undefined' && module.exports ) {
|
|
3
|
+
var lib = require('../../index');
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Collection cLass
|
|
8
|
+
* Allows you to handle your own collections as you would normaly with mongodb
|
|
9
|
+
* Dependencies :
|
|
10
|
+
* - lib/merge
|
|
11
|
+
* - uuid
|
|
12
|
+
*
|
|
13
|
+
*
|
|
14
|
+
* @param {array} collection
|
|
15
|
+
* @param {object} [options]
|
|
16
|
+
*
|
|
17
|
+
* @returns {object} instance
|
|
18
|
+
*
|
|
19
|
+
* Collection.length will return result length : dont't use .count() which is going to include functions to the count
|
|
20
|
+
*
|
|
21
|
+
* Collection::find
|
|
22
|
+
* @param {object} filter
|
|
23
|
+
* eg.: { uid: 'someUID' }
|
|
24
|
+
* eg.: { type: 'not null', country: 'France' } // `AND` clause
|
|
25
|
+
* NB.: To filter `not empty`, use { type: '!=""' }
|
|
26
|
+
* eg.: { country: 'The Hashemite Kingdom of Jordan' }, { country: 'Libanon'} // `OR` clause
|
|
27
|
+
* eg.: { 'obj.prop': true }
|
|
28
|
+
* eg.: { 'contacts[*].name': 'Doe' } // `WITHIN` (array|collection) clause
|
|
29
|
+
* eg.: { lastUpdate: '>= 2016-12-01T00:00:00' } // also available for date comparison `=`, `<`, `>`
|
|
30
|
+
* eg.: { activity: null }
|
|
31
|
+
* eg.: { isActive: false }
|
|
32
|
+
*
|
|
33
|
+
* @returns {array} result
|
|
34
|
+
*
|
|
35
|
+
* Collection::findOne
|
|
36
|
+
* @param {object} filter
|
|
37
|
+
* @returns {object|array|string} result
|
|
38
|
+
*
|
|
39
|
+
* Collection::update
|
|
40
|
+
* @param {object} filter
|
|
41
|
+
* @param {object} set
|
|
42
|
+
*
|
|
43
|
+
* @returns {array} result
|
|
44
|
+
* rasult.toRaw() will give result without chaining & _uuid
|
|
45
|
+
*
|
|
46
|
+
* */
|
|
47
|
+
function Collection(content, options) {
|
|
48
|
+
|
|
49
|
+
var isGFFCtx = ( ( typeof(module) !== 'undefined' ) && module.exports ) ? false : true;
|
|
50
|
+
var uuid = (isGFFCtx) ? require('vendor/uuid') : require('uuid');
|
|
51
|
+
var merge = (isGFFCtx) ? require('utils/merge') : require('../../../lib/merge');
|
|
52
|
+
|
|
53
|
+
// defined search option rules
|
|
54
|
+
var searchOptionRules = {
|
|
55
|
+
isCaseSensitive: {
|
|
56
|
+
false: {
|
|
57
|
+
re: '^%s$',
|
|
58
|
+
modifiers: 'i'
|
|
59
|
+
},
|
|
60
|
+
true: {
|
|
61
|
+
re: '^%s$'
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
var withOrClause = false;
|
|
66
|
+
var notInSearchModeEnabled = false;
|
|
67
|
+
|
|
68
|
+
var localSearchOptions = null;
|
|
69
|
+
|
|
70
|
+
var defaultOptions = {
|
|
71
|
+
useLocalStorage: false,
|
|
72
|
+
locale: 'en', // TODO - get settigs.region, or user.region
|
|
73
|
+
searchOptionRules: searchOptionRules
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
options = (typeof(options) == 'object') ? merge(options, defaultOptions) : defaultOptions;
|
|
79
|
+
|
|
80
|
+
var keywords = ['not null']; // TODO - null, exists (`true` if property is defined)
|
|
81
|
+
var tryEval = function(condition) {
|
|
82
|
+
try {
|
|
83
|
+
return eval(condition);
|
|
84
|
+
} catch(err) {
|
|
85
|
+
throw new Error('Could not evaluate condition `'+ condition +'`.\n' + err.stack );
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (typeof(content) == 'undefined' || content == '' || content == null)
|
|
90
|
+
content = [];
|
|
91
|
+
|
|
92
|
+
if ( !Array.isArray(content) )
|
|
93
|
+
throw new Error('`new Collection([content] [, options] )`: `content` argument must be an Array !');
|
|
94
|
+
|
|
95
|
+
content = (content) ? JSON.clone(content) : []; // original content -> not to be touched
|
|
96
|
+
|
|
97
|
+
// Indexing : uuids are generated for each entry
|
|
98
|
+
var searchIndex = [], idx = 0;
|
|
99
|
+
for (var entry = 0, entryLen = content.length; entry < entryLen; ++entry) {
|
|
100
|
+
if (!content[entry]) {
|
|
101
|
+
content[entry] = {};
|
|
102
|
+
}
|
|
103
|
+
content[entry]._uuid = uuid.v4();
|
|
104
|
+
// To avoid duplicate entries
|
|
105
|
+
searchIndex[idx] = content[entry]._uuid;
|
|
106
|
+
++idx;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
var instance = content;
|
|
110
|
+
/**
|
|
111
|
+
* Set local search option for the current collection method call
|
|
112
|
+
*
|
|
113
|
+
* eg.:
|
|
114
|
+
* var recCollection = new Collection(arrayCollection);
|
|
115
|
+
* var rec = recCollection
|
|
116
|
+
* .setSearchOption('name', 'isCaseSensitive', false)
|
|
117
|
+
* .find({ city: 'cap Town' });
|
|
118
|
+
*
|
|
119
|
+
* eg.:
|
|
120
|
+
* var recCollection = new Collection(arrayCollection);
|
|
121
|
+
* var searchOptions = {
|
|
122
|
+
* name: {
|
|
123
|
+
* isCaseSensitive: false
|
|
124
|
+
* }
|
|
125
|
+
* };
|
|
126
|
+
* var rec = recCollection
|
|
127
|
+
* .setSearchOption(searchOptions)
|
|
128
|
+
* .find({ city: 'cap Town' }); *
|
|
129
|
+
*
|
|
130
|
+
* @param {object|string} searchOptionObject or searchOptionTargetedProperty
|
|
131
|
+
* @param {string} [searchRule]
|
|
132
|
+
* @param {boolean} [searchRuleValue] - true to enable, false to disabled
|
|
133
|
+
*
|
|
134
|
+
* @returns {object} instance with local search options
|
|
135
|
+
*/
|
|
136
|
+
instance['setSearchOption'] = function() {
|
|
137
|
+
|
|
138
|
+
if (!arguments.length)
|
|
139
|
+
throw new Error('searchOption cannot be left blank');
|
|
140
|
+
|
|
141
|
+
if (arguments.length > 3 || arguments.length < 3 && arguments.length > 1)
|
|
142
|
+
throw new Error('argument length mismatch');
|
|
143
|
+
|
|
144
|
+
var i = 0
|
|
145
|
+
, len = arguments.length
|
|
146
|
+
;
|
|
147
|
+
|
|
148
|
+
if (arguments.length == 1) {
|
|
149
|
+
if ( typeof(arguments[0]) != 'object' )
|
|
150
|
+
throw new Error('searchOption must be an object');
|
|
151
|
+
|
|
152
|
+
for (var prop in arguments[0]) {
|
|
153
|
+
if ( typeof(searchOptionRules[prop]) == 'undefined' )
|
|
154
|
+
throw new Error(arguments[1] + ' is not an allowed searchOption !');
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
localSearchOptions = arguments[0];
|
|
158
|
+
} else {
|
|
159
|
+
|
|
160
|
+
if ( !localSearchOptions )
|
|
161
|
+
localSearchOptions = {};
|
|
162
|
+
|
|
163
|
+
for (; i < len; ++i) {
|
|
164
|
+
if ( typeof(searchOptionRules[arguments[1]]) == 'undefined' )
|
|
165
|
+
throw new Error(arguments[1] + ' is not an allowed searchOption !');
|
|
166
|
+
|
|
167
|
+
if (typeof(localSearchOptions[arguments[0]]) == 'undefined')
|
|
168
|
+
localSearchOptions[arguments[0]] = {};
|
|
169
|
+
|
|
170
|
+
if ( /true|false/i.test(arguments[2]) ) {
|
|
171
|
+
localSearchOptions[arguments[0]][arguments[1]] = /true/i.test(arguments[2]) ? true : false
|
|
172
|
+
} else {
|
|
173
|
+
localSearchOptions[arguments[0]][arguments[1]] = arguments[2]
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return instance
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
instance['find'] = function() {
|
|
183
|
+
// reset
|
|
184
|
+
withOrClause = false;
|
|
185
|
+
|
|
186
|
+
if ( typeof(arguments[arguments.length-1]) == 'boolean' ) {
|
|
187
|
+
withOrClause = arguments[arguments.length-1];
|
|
188
|
+
delete arguments[arguments.length-1];
|
|
189
|
+
--arguments.length;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
var filtersStr = null;
|
|
193
|
+
var filters = null;
|
|
194
|
+
var filtersCount = null;
|
|
195
|
+
try {
|
|
196
|
+
filtersStr = JSON.stringify(arguments);
|
|
197
|
+
filters = JSON.parse(filtersStr);
|
|
198
|
+
filtersCount = filters.count();
|
|
199
|
+
} catch( filtersError) {
|
|
200
|
+
throw new Error('filter must be an object\n'+ filtersError.stack);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if ( typeof(filters) != 'undefined' && filtersCount > 0 ) {
|
|
204
|
+
|
|
205
|
+
if (filtersCount > 1) {
|
|
206
|
+
withOrClause = true;
|
|
207
|
+
}
|
|
208
|
+
// checking filter : this should be forbidden -> { type: 'red', type: 'orange'}
|
|
209
|
+
// var filtersFields = null;
|
|
210
|
+
// for (let f = 0, fLen = filters.count(); f < fLen; f++) {
|
|
211
|
+
// filtersFields = {};
|
|
212
|
+
// for (let fField in filters[f]) {
|
|
213
|
+
// if ( typeof(filtersFields[ fField ]) != 'undefined' ) {
|
|
214
|
+
// throw new Error('Filter field can only be defined once inside a filter object !\n`Field '+ fField +'` is already defined : '+ filters[f])
|
|
215
|
+
// }
|
|
216
|
+
// filtersFields[ fField ] = true;
|
|
217
|
+
// }
|
|
218
|
+
// }
|
|
219
|
+
|
|
220
|
+
var filter = null
|
|
221
|
+
, condition = null
|
|
222
|
+
, i = 0
|
|
223
|
+
//, tmpContent = ( Array.isArray(this) && !withOrClause) ? this : JSON.clone(content)
|
|
224
|
+
, tmpContent = ( Array.isArray(this) ) ? this : JSON.clone(content)
|
|
225
|
+
, resultObj = {}
|
|
226
|
+
, result = []
|
|
227
|
+
, localeLowerCase = ''
|
|
228
|
+
, re = null
|
|
229
|
+
, field = null
|
|
230
|
+
, fieldWithin = null
|
|
231
|
+
, value = null
|
|
232
|
+
, searchOptions = localSearchOptions
|
|
233
|
+
, searchOptionRules = options.searchOptionRules
|
|
234
|
+
;
|
|
235
|
+
|
|
236
|
+
var matched = null
|
|
237
|
+
, filterIsArray = null
|
|
238
|
+
, searchResult = [];
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Regular Search
|
|
242
|
+
* @param {object} filter
|
|
243
|
+
* @param {string} field
|
|
244
|
+
* @param {strine|number|date} _content
|
|
245
|
+
* @param {number} matched
|
|
246
|
+
*/
|
|
247
|
+
var search = function(filter, field, _content, matched, searchOptionRules) {
|
|
248
|
+
var reValidCount = null, searchOptCount = null;
|
|
249
|
+
if (filter === null && _content === null) { // null case
|
|
250
|
+
|
|
251
|
+
++matched;
|
|
252
|
+
|
|
253
|
+
} else if (
|
|
254
|
+
filter
|
|
255
|
+
&& keywords.indexOf(localeLowerCase) > -1
|
|
256
|
+
&& localeLowerCase == 'not null'
|
|
257
|
+
&& typeof(_content) != 'undefined'
|
|
258
|
+
&& typeof(_content) !== 'object'
|
|
259
|
+
&& _content != 'null'
|
|
260
|
+
&& _content != 'undefined'
|
|
261
|
+
) {
|
|
262
|
+
|
|
263
|
+
if (result.indexOf(_content) < 0) {
|
|
264
|
+
++matched;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
} else if (
|
|
268
|
+
typeof(_content) != 'undefined'
|
|
269
|
+
&& typeof(_content) !== 'object'
|
|
270
|
+
&& /(<|>|=)/.test(filter)
|
|
271
|
+
&& !/undefined|function/.test(typeof(_content))
|
|
272
|
+
) { // with operations
|
|
273
|
+
let originalFilter = filter;
|
|
274
|
+
let condition = _content + filter;
|
|
275
|
+
if ( typeof(filter) == 'string' && typeof(_content) == 'string' ) {
|
|
276
|
+
let comparedValue = filter.replace(/^(<=|>=|!==|!=|===|!==)/g, '');
|
|
277
|
+
if ( typeof(_content) == 'string' && !/^\"(.*)\"$/.test(comparedValue) ) {
|
|
278
|
+
filter = filter.replace(comparedValue, '\"'+ comparedValue + '\"');
|
|
279
|
+
}
|
|
280
|
+
condition = '\"'+_content+'\"' + filter;
|
|
281
|
+
// restoring in case of datetime eval
|
|
282
|
+
filter = originalFilter;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// looking for a datetime ?
|
|
286
|
+
if (
|
|
287
|
+
/(\d{4})\-(\d{2})\-(\d{2})(\s+|T)(\d{2}):(\d{2}):(\d{2})/.test(_content)
|
|
288
|
+
&& /(\d{4})\-(\d{2})\-(\d{2})(\s+|T)(\d{2}):(\d{2}):(\d{2})/.test(filter)
|
|
289
|
+
) {
|
|
290
|
+
|
|
291
|
+
if (tryEval(_content.replace(/(\d{4})\-(\d{2})\-(\d{2})(\s+|T)(\d{2}):(\d{2}):(\d{2})/, 'new Date("$&")') + filter.replace(/(\d{4})\-(\d{2})\-(\d{2})(\s+|T)(\d{2}):(\d{2}):(\d{2})/, 'new Date("$&")'))) {
|
|
292
|
+
++matched;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
} else if (tryEval(condition)) {
|
|
296
|
+
++matched;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
} else if (
|
|
300
|
+
typeof(_content) != 'undefined'
|
|
301
|
+
&& typeof(_content) !== 'object'
|
|
302
|
+
&& _content === filter
|
|
303
|
+
&& !searchOptions
|
|
304
|
+
||
|
|
305
|
+
typeof(_content) != 'undefined'
|
|
306
|
+
&& typeof(_content) !== 'object'
|
|
307
|
+
&& _content === filter
|
|
308
|
+
&& typeof(searchOptions[field]) == 'undefined'
|
|
309
|
+
) {
|
|
310
|
+
|
|
311
|
+
++matched;
|
|
312
|
+
} else if (
|
|
313
|
+
typeof(_content) != 'undefined'
|
|
314
|
+
&& typeof(_content) !== 'object'
|
|
315
|
+
&& searchOptions
|
|
316
|
+
&& typeof(searchOptions[field]) != 'undefined'
|
|
317
|
+
) {
|
|
318
|
+
|
|
319
|
+
reValidCount = 0;
|
|
320
|
+
searchOptCount = searchOptions[field].count();
|
|
321
|
+
for ( var rule in searchOptions[field]) {
|
|
322
|
+
searchOptionRules[rule][searchOptions[field][rule]].re = searchOptionRules[rule][searchOptions[field][rule]].re.replace(/\%s/, filter);
|
|
323
|
+
|
|
324
|
+
if (searchOptionRules[rule][searchOptions[field][rule]].modifiers) {
|
|
325
|
+
re = new RegExp(searchOptionRules[rule][searchOptions[field][rule]].re, searchOptionRules[rule][searchOptions[field][rule]].modifiers);
|
|
326
|
+
} else {
|
|
327
|
+
re = new RegExp(searchOptionRules[rule][searchOptions[field][rule]].re);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
if ( re.test(_content) ) {
|
|
331
|
+
++reValidCount
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
if (reValidCount == searchOptCount) {
|
|
336
|
+
++matched;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
return {
|
|
341
|
+
matched: matched
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
var searchThroughProp = function(filter, f, _content, matched) {
|
|
346
|
+
|
|
347
|
+
var field = f.split(/\./g);
|
|
348
|
+
field = field[field.length - 1];
|
|
349
|
+
re = new RegExp('("' + field + '":\\w+)');
|
|
350
|
+
|
|
351
|
+
var value = null;
|
|
352
|
+
|
|
353
|
+
try {
|
|
354
|
+
if ( _content )
|
|
355
|
+
value = eval('_content.'+f);
|
|
356
|
+
} catch (err) {
|
|
357
|
+
// Nothing to do
|
|
358
|
+
// means that the field is not available in the collection
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
if (value /** && value.length > 0*/) {
|
|
364
|
+
if ( Array.isArray(value) )
|
|
365
|
+
value = value[1].split(/:/)[1];
|
|
366
|
+
else if ( typeof(value) == 'string' && /\:/.test(value) )
|
|
367
|
+
value = value.split(/:/)[1];
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
if (/(<|>|=)/.test(filter)) {
|
|
371
|
+
|
|
372
|
+
// looking for a datetime ?
|
|
373
|
+
if (
|
|
374
|
+
/(\d{4})\-(\d{2})\-(\d{2})(\s+|T)(\d{2}):(\d{2}):(\d{2})/.test(value)
|
|
375
|
+
&& /(\d{4})\-(\d{2})\-(\d{2})(\s+|T)(\d{2}):(\d{2}):(\d{2})/.test(filter)
|
|
376
|
+
) {
|
|
377
|
+
|
|
378
|
+
if (tryEval(value.replace(/(\d{4})\-(\d{2})\-(\d{2})(\s+|T)(\d{2}):(\d{2}):(\d{2})/, 'new Date("$&")') + filter.replace(/(\d{4})\-(\d{2})\-(\d{2})(\s+|T)(\d{2}):(\d{2}):(\d{2})/, 'new Date("$&")'))) {
|
|
379
|
+
|
|
380
|
+
++matched;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
} else if (tryEval(value + filter)) {
|
|
384
|
+
|
|
385
|
+
++matched;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
} else {
|
|
389
|
+
if (value == filter) {
|
|
390
|
+
++matched;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
return {
|
|
397
|
+
matched: matched
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
// if one of the entry matches the given filter, tag the whole entry as matched
|
|
402
|
+
var searchWithin = function(filter, f, _content, matched, i) {
|
|
403
|
+
|
|
404
|
+
var collectionName = null
|
|
405
|
+
, collection = null
|
|
406
|
+
, arr = null
|
|
407
|
+
, field = null;
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
arr = f.split(/\[\*\]/g);
|
|
411
|
+
collectionName = arr[0].replace(/\[\*\]/, '');// only take the first collection
|
|
412
|
+
collection = _content[ collectionName ];
|
|
413
|
+
|
|
414
|
+
|
|
415
|
+
field = arr[1];
|
|
416
|
+
if (/^\./.test(field) )
|
|
417
|
+
field = field.substr(1);
|
|
418
|
+
|
|
419
|
+
var subMatched = 0;
|
|
420
|
+
if (collection) {
|
|
421
|
+
|
|
422
|
+
for (var c = 0, cLen = collection.length; c < cLen; ++c) {
|
|
423
|
+
// cases with _filter.prop
|
|
424
|
+
if (/\./.test(field)) {
|
|
425
|
+
|
|
426
|
+
searchResult = searchThroughProp(filter, field, collection[c], subMatched);
|
|
427
|
+
subMatched = searchResult.matched;
|
|
428
|
+
|
|
429
|
+
} else { // normal case
|
|
430
|
+
|
|
431
|
+
searchResult = search(filter, field, collection[c], subMatched, searchOptionRules);
|
|
432
|
+
subMatched = searchResult.matched;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
if (subMatched > 0) break;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
return {
|
|
440
|
+
matched: (matched + subMatched)
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
|
|
445
|
+
for (var o in tmpContent) {
|
|
446
|
+
|
|
447
|
+
if (!tmpContent[o]) {
|
|
448
|
+
tmpContent[o] = {}
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
if (!/undefined|function/.test( typeof(tmpContent[o]))) {
|
|
452
|
+
|
|
453
|
+
for (let l = 0, lLen = filters.count(); l<lLen; ++l) {
|
|
454
|
+
filter = filters[l];
|
|
455
|
+
condition = filter.count();
|
|
456
|
+
// for each condition
|
|
457
|
+
matched = 0;
|
|
458
|
+
|
|
459
|
+
for (var f in filter) {
|
|
460
|
+
if ( typeof(filter[f]) == 'undefined' ) throw new Error('filter `'+f+'` cannot be left undefined');
|
|
461
|
+
|
|
462
|
+
localeLowerCase = ( filter[f] !== null && !/(boolean|number)/.test(typeof(filter[f])) ) ? filter[f].toLocaleLowerCase() : filter[f];
|
|
463
|
+
|
|
464
|
+
// cases with tmpContent.prop
|
|
465
|
+
if (/\./.test(f)) {
|
|
466
|
+
//JSON.stringify(tmpContent[o]).match(/("gross":\w+)/)[1].split(/:/)[1]
|
|
467
|
+
|
|
468
|
+
// detect if array|collection case
|
|
469
|
+
if (/\[\*\]/.test(f)) {
|
|
470
|
+
|
|
471
|
+
searchResult = searchWithin(filter[f], f, tmpContent[o], matched, 0);
|
|
472
|
+
matched = searchResult.matched;
|
|
473
|
+
|
|
474
|
+
} else {
|
|
475
|
+
|
|
476
|
+
searchResult = searchThroughProp(filter[f], f, tmpContent[o], matched);
|
|
477
|
+
matched = searchResult.matched;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
} else { // normal case
|
|
481
|
+
|
|
482
|
+
searchResult = search(filter[f], f, tmpContent[o][f], matched, searchOptionRules);
|
|
483
|
+
matched = searchResult.matched;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
if (matched == condition ) { // all conditions must be fulfilled to match
|
|
488
|
+
// `this` {Array} is the result of the previous search or the current content
|
|
489
|
+
// TODO - Add a switch
|
|
490
|
+
if (
|
|
491
|
+
withOrClause
|
|
492
|
+
&& notInSearchModeEnabled
|
|
493
|
+
&& searchIndex.indexOf(tmpContent[o]._uuid) < 0
|
|
494
|
+
|| notInSearchModeEnabled
|
|
495
|
+
|| !withOrClause
|
|
496
|
+
) {
|
|
497
|
+
//console.debug('searchIndex ', searchIndex);
|
|
498
|
+
if (!withOrClause || withOrClause && result.indexOf(tmpContent[o]._uuid) < 0 || notInSearchModeEnabled) {
|
|
499
|
+
result[i] = tmpContent[o];
|
|
500
|
+
++i;
|
|
501
|
+
}
|
|
502
|
+
} else if (
|
|
503
|
+
withOrClause
|
|
504
|
+
&& !notInSearchModeEnabled
|
|
505
|
+
) {
|
|
506
|
+
if (result.indexOf(tmpContent[o]._uuid) < 0) {
|
|
507
|
+
result[i] = tmpContent[o];
|
|
508
|
+
++i;
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
} else {
|
|
518
|
+
result = content
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
// reset localSearchOptions for nest calls
|
|
522
|
+
localSearchOptions = null;
|
|
523
|
+
|
|
524
|
+
// TODO - remove this
|
|
525
|
+
//if (withOrClause) {
|
|
526
|
+
// merging with previous result
|
|
527
|
+
//console.debug('withOrClause: supposed to merge ? \nnotInSearchModeEnabled: '+notInSearchModeEnabled+'\nResult: ' +result)//+'\nThis: '+ this.toRaw();
|
|
528
|
+
// if (!notInSearchModeEnabled) {
|
|
529
|
+
// result = merge(this, result);
|
|
530
|
+
// }
|
|
531
|
+
// TODO - remove this part
|
|
532
|
+
// Removed this on 2021-01-21 because it was causing duplicate content
|
|
533
|
+
//result = merge(this, result, true)
|
|
534
|
+
//}
|
|
535
|
+
|
|
536
|
+
// chaining
|
|
537
|
+
//result._options = instance._options;
|
|
538
|
+
//result.setSearchOption = instance.setSearchOption;
|
|
539
|
+
|
|
540
|
+
result.insert = instance.insert;
|
|
541
|
+
result.notIn = instance.notIn;
|
|
542
|
+
result.find = this.find;
|
|
543
|
+
result.update = instance.update;
|
|
544
|
+
result.replace = instance.replace;
|
|
545
|
+
result.or = instance.or;
|
|
546
|
+
result.findOne = instance.findOne;
|
|
547
|
+
result.limit = instance.limit;
|
|
548
|
+
result.orderBy = instance.orderBy;
|
|
549
|
+
result.delete = instance.delete;
|
|
550
|
+
result.toRaw = instance.toRaw;
|
|
551
|
+
result.filter = instance.filter;
|
|
552
|
+
|
|
553
|
+
return result
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
/**
|
|
557
|
+
* findOne
|
|
558
|
+
*
|
|
559
|
+
* E.g.:
|
|
560
|
+
* - new Collection(projects).findOne({name: 'My Project'})
|
|
561
|
+
* - new Collection(projects)
|
|
562
|
+
* .setSearchOption({name: { isCaseSensitive: false }})
|
|
563
|
+
* .findOne({name: 'my project'})
|
|
564
|
+
*
|
|
565
|
+
*
|
|
566
|
+
* Available options :
|
|
567
|
+
* isCaseSensitive: [true|false] - set to true by default
|
|
568
|
+
*
|
|
569
|
+
* @param {object} filter
|
|
570
|
+
*
|
|
571
|
+
* @returns {object} result
|
|
572
|
+
*
|
|
573
|
+
*/
|
|
574
|
+
instance['findOne'] = function() {
|
|
575
|
+
var key = null // comparison key
|
|
576
|
+
, result = null
|
|
577
|
+
, filters = null
|
|
578
|
+
//, uuidSearchModeEnabled = true
|
|
579
|
+
;
|
|
580
|
+
|
|
581
|
+
if ( typeof(arguments[arguments.length-1]) == 'string' ) {
|
|
582
|
+
key = arguments[arguments.length - 1];
|
|
583
|
+
delete arguments[arguments.length - 1];
|
|
584
|
+
--arguments.length;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
// if ( typeof(arguments[arguments.length-1]) == 'boolean' ) {
|
|
588
|
+
// uuidSearchModeEnabled = arguments[arguments.length - 1]
|
|
589
|
+
// delete arguments[arguments.length - 1];
|
|
590
|
+
// --arguments.length;
|
|
591
|
+
// }
|
|
592
|
+
|
|
593
|
+
if (arguments.length > 0) {
|
|
594
|
+
filters = arguments;
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
|
|
598
|
+
if ( typeof(filters) == 'undefined' || !filters || typeof(filters) != 'object' ) {
|
|
599
|
+
throw new Error('[ Collection ][ findOne ] `filters` argument must be defined: Array or Filter Object(s) expected');
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
// If an operation (find, insert ...) has been executed, get the previous result; if not, get the whole collection
|
|
603
|
+
//var currentResult = JSON.clone( (Array.isArray(this)) ? this : content );
|
|
604
|
+
var currentResult = null;
|
|
605
|
+
var foundResults = null;
|
|
606
|
+
if ( Array.isArray(arguments[0]) ) {
|
|
607
|
+
foundResults = arguments[0];
|
|
608
|
+
} else {
|
|
609
|
+
foundResults = instance.find.apply(this, arguments) || [];
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
if (foundResults.length > 0) {
|
|
613
|
+
currentResult = foundResults.limit(1).toRaw()[0];
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
result = currentResult;
|
|
617
|
+
return result
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
|
|
621
|
+
instance['or'] = function () {
|
|
622
|
+
arguments[arguments.length] = true;
|
|
623
|
+
++arguments.length;
|
|
624
|
+
|
|
625
|
+
return instance.find.apply(this, arguments);
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
instance['limit'] = function(resultLimit) {
|
|
629
|
+
if ( typeof(resultLimit) == 'undefined' || typeof(resultLimit) != 'number' ) {
|
|
630
|
+
throw new Error('[Collection::result->limit(resultLimit)] : `resultLimit` parametter must by a `number`')
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
var result = Array.isArray(this) ? this : JSON.clone(content);
|
|
634
|
+
|
|
635
|
+
//resultLimit
|
|
636
|
+
result = result.splice(0, resultLimit);
|
|
637
|
+
|
|
638
|
+
// chaining
|
|
639
|
+
result.insert = instance.insert;
|
|
640
|
+
result.update = instance.update;
|
|
641
|
+
result.replace = instance.replace;
|
|
642
|
+
result.notIn = instance.notIn;
|
|
643
|
+
result.findOne = instance.findOne;
|
|
644
|
+
result.orderBy = instance.orderBy;
|
|
645
|
+
result.max = instance.max;
|
|
646
|
+
result.delete = instance.delete;
|
|
647
|
+
result.toRaw = instance.toRaw;
|
|
648
|
+
result.filter = instance.filter;
|
|
649
|
+
|
|
650
|
+
return result
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
/**
|
|
654
|
+
* notIn
|
|
655
|
+
* Works like a filter to match results by `excluding` through given `filters` !!
|
|
656
|
+
*
|
|
657
|
+
* filter can be like
|
|
658
|
+
* { car: 'toyota' }
|
|
659
|
+
* { car: 'toyota', color: 'red' }
|
|
660
|
+
*
|
|
661
|
+
* You can pass more than one filter
|
|
662
|
+
* { car: 'toyota', color: 'red' }, { car: 'porche' }
|
|
663
|
+
*
|
|
664
|
+
* .notIn(filter) // AND syntax
|
|
665
|
+
* .notIn(filter1, filter2, filter3) // OR syntax
|
|
666
|
+
* .notIn(filter, 'id') where `id` is the uuid used for the DIFF - `_uuid
|
|
667
|
+
* .noIn(collectionObj, 'id')
|
|
668
|
+
*
|
|
669
|
+
* By default, Collection use its own internal `_uuid` to search and compare.
|
|
670
|
+
* This mode is called `uuidSearchModeEnabled`, and it is by default set to `true`.
|
|
671
|
+
* If you want to disable this mode in order to MATCH/DIFF by forcing check on every single filter
|
|
672
|
+
* of the resultset :
|
|
673
|
+
* .notIn(filter, false) where false must be a real boolean
|
|
674
|
+
*
|
|
675
|
+
*
|
|
676
|
+
*
|
|
677
|
+
* @param {object|array} filters|arrayToFilter - works like find filterss
|
|
678
|
+
* @param {string} [key] - unique id for comparison; faster when provided
|
|
679
|
+
*/
|
|
680
|
+
instance['notIn'] = function(){
|
|
681
|
+
|
|
682
|
+
var arrayToFilter = null // [] those that we don't want in the result
|
|
683
|
+
, key = null // string comparison key
|
|
684
|
+
, result = null
|
|
685
|
+
, filters = null
|
|
686
|
+
, uuidSearchModeEnabled = true
|
|
687
|
+
;
|
|
688
|
+
|
|
689
|
+
if ( typeof(arguments[arguments.length-1]) == 'string' ) {
|
|
690
|
+
key = arguments[arguments.length - 1];
|
|
691
|
+
delete arguments[arguments.length - 1];
|
|
692
|
+
--arguments.length;
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
if ( typeof(arguments[arguments.length-1]) == 'boolean' ) {
|
|
696
|
+
uuidSearchModeEnabled = arguments[arguments.length - 1]
|
|
697
|
+
delete arguments[arguments.length - 1];
|
|
698
|
+
--arguments.length;
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
if (arguments.length > 0) {
|
|
702
|
+
filters = arguments;
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
|
|
706
|
+
if ( typeof(filters) == 'undefined' || !filters || typeof(filters) != 'object' ) {
|
|
707
|
+
throw new Error('[ Collection ][ notIn ] `filters` argument must be defined: Array or Filter Object(s) expected');
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
// If an operation (find, insert ...) has been executed, get the previous result; if not, get the whole collection
|
|
711
|
+
var currentResult = JSON.clone( (Array.isArray(this)) ? this : content );
|
|
712
|
+
|
|
713
|
+
var foundResults = null;
|
|
714
|
+
if ( Array.isArray(arguments[0]) ) {
|
|
715
|
+
foundResults = arguments[0];
|
|
716
|
+
} else {
|
|
717
|
+
notInSearchModeEnabled = true;
|
|
718
|
+
foundResults = instance.find.apply(this, arguments) || [];
|
|
719
|
+
notInSearchModeEnabled = false;
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
|
|
723
|
+
if (foundResults.length > 0) {
|
|
724
|
+
|
|
725
|
+
// check key
|
|
726
|
+
if (
|
|
727
|
+
uuidSearchModeEnabled
|
|
728
|
+
&& key
|
|
729
|
+
&& typeof(foundResults[0]) == 'undefined'
|
|
730
|
+
&& typeof(foundResults[0][key]) == 'undefined'
|
|
731
|
+
) {
|
|
732
|
+
throw new Error('[ Collection ][ notIn ] `key` not valid');
|
|
733
|
+
} else if ( uuidSearchModeEnabled && !key && typeof(foundResults[0]['_uuid']) != 'undefined' ) {
|
|
734
|
+
key = '_uuid'
|
|
735
|
+
} else if ( typeof(foundResults[0]['id']) != 'undefined' ) {
|
|
736
|
+
key = 'id';
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
if ( !key || typeof(foundResults[0][key]) == 'undefined' ) {
|
|
740
|
+
throw new Error('No comparison key defined !')
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
// fast search with key
|
|
744
|
+
var r = 0
|
|
745
|
+
, rLen = foundResults.length
|
|
746
|
+
, c = 0
|
|
747
|
+
, cLen = currentResult.length
|
|
748
|
+
, f = 0
|
|
749
|
+
, fLen = filters.count()
|
|
750
|
+
, keyLen = null
|
|
751
|
+
, matched = 0
|
|
752
|
+
, fullFiltersMatched = 0
|
|
753
|
+
;
|
|
754
|
+
if ( uuidSearchModeEnabled && typeof(currentResult[c]) != 'undefined' && currentResult[c].hasOwnProperty(key) ) {
|
|
755
|
+
// for every single result found
|
|
756
|
+
for (; r < rLen; ++r) {
|
|
757
|
+
|
|
758
|
+
if (!currentResult.length) break;
|
|
759
|
+
|
|
760
|
+
c = 0; cLen = currentResult.length;
|
|
761
|
+
for (; c < cLen; ++c) {
|
|
762
|
+
if ( typeof(currentResult[c]) == 'undefined' || typeof(foundResults[r]) == 'undefined' ) {
|
|
763
|
+
continue
|
|
764
|
+
}
|
|
765
|
+
// when matched, we want to remove those not in current result
|
|
766
|
+
if (currentResult[c][key] === foundResults[r][key]) {
|
|
767
|
+
currentResult.splice(c,1);
|
|
768
|
+
break;
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
} else if ( typeof(currentResult[c]) == 'undefined' ) { //empty source case
|
|
773
|
+
// means that since we don't have a source to compare, current === found
|
|
774
|
+
currentResult = JSON.clone(foundResults);
|
|
775
|
+
|
|
776
|
+
} else { // search based on provided filters
|
|
777
|
+
// for every single result found
|
|
778
|
+
for (; r < rLen; ++r) {
|
|
779
|
+
if (!currentResult.length) break;
|
|
780
|
+
|
|
781
|
+
//onRemoved:
|
|
782
|
+
c = 0; cLen = currentResult.length;
|
|
783
|
+
for (; c < cLen; ++c) { // current results
|
|
784
|
+
|
|
785
|
+
if ( typeof (currentResult[c]) != 'undefined' ) {
|
|
786
|
+
|
|
787
|
+
// for each filter
|
|
788
|
+
fullFiltersMatched = 0;
|
|
789
|
+
f = 0;
|
|
790
|
+
for (; f < fLen; ++f ) {
|
|
791
|
+
if ( typeof(filters[f]) == 'undefined' ) throw new Error('filter `'+f+'` cannot be left undefined');
|
|
792
|
+
|
|
793
|
+
keyLen = filters[f].count();
|
|
794
|
+
matched = 0;
|
|
795
|
+
for (key in filters[f]) {
|
|
796
|
+
if ( currentResult[c].hasOwnProperty(key) && currentResult[c][key] === foundResults[r][key] ) {
|
|
797
|
+
++matched;
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
if (matched == keyLen) {
|
|
801
|
+
++fullFiltersMatched
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
if (fullFiltersMatched) {
|
|
806
|
+
currentResult.splice(c,1);
|
|
807
|
+
//break onRemoved;
|
|
808
|
+
break;
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
result = currentResult;
|
|
819
|
+
result.notIn = instance.notIn;
|
|
820
|
+
result.limit = instance.limit;
|
|
821
|
+
result.find = instance.find;
|
|
822
|
+
result.findOne = instance.findOne;
|
|
823
|
+
result.insert = instance.insert;
|
|
824
|
+
result.replace = instance.replace;
|
|
825
|
+
result.update = instance.update;
|
|
826
|
+
result.orderBy = instance.orderBy;
|
|
827
|
+
result.max = instance.max;
|
|
828
|
+
result.delete = instance.delete;
|
|
829
|
+
result.toRaw = instance.toRaw;
|
|
830
|
+
result.filter = instance.filter;
|
|
831
|
+
|
|
832
|
+
return result
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
instance['insert'] = function (set) {
|
|
836
|
+
|
|
837
|
+
var result = null;
|
|
838
|
+
if ( typeof(set) !== 'object' ) {
|
|
839
|
+
throw new Error('filter must be an object');
|
|
840
|
+
} else {
|
|
841
|
+
|
|
842
|
+
var tmpContent = Array.isArray(this) ? this : content;
|
|
843
|
+
|
|
844
|
+
// Indexing;
|
|
845
|
+
set._uuid = uuid.v4();
|
|
846
|
+
tmpContent.push(set);
|
|
847
|
+
|
|
848
|
+
result = tmpContent;
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
// chaining
|
|
852
|
+
result.limit = instance.limit;
|
|
853
|
+
result.find = instance.find;
|
|
854
|
+
result.findOne = instance.findOne;
|
|
855
|
+
result.update = instance.update;
|
|
856
|
+
result.replace = instance.replace;
|
|
857
|
+
result.orderBy = instance.orderBy;
|
|
858
|
+
result.max = instance.max;
|
|
859
|
+
result.notIn = instance.notIn;
|
|
860
|
+
result.delete = instance.delete;
|
|
861
|
+
result.toRaw = instance.toRaw;
|
|
862
|
+
result.filter = instance.filter;
|
|
863
|
+
|
|
864
|
+
return result
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
/**
|
|
868
|
+
* update
|
|
869
|
+
*
|
|
870
|
+
* @param {object} filter
|
|
871
|
+
* @param {object} set
|
|
872
|
+
*
|
|
873
|
+
* @returns {objet} instance
|
|
874
|
+
*/
|
|
875
|
+
instance['update'] = function() {
|
|
876
|
+
var key = '_uuid' // comparison key is _uuid by default
|
|
877
|
+
, result = null
|
|
878
|
+
, filters = null
|
|
879
|
+
, set = null
|
|
880
|
+
//, uuidSearchModeEnabled = true
|
|
881
|
+
;
|
|
882
|
+
|
|
883
|
+
// comparison key : _uuid by default, but can be set to id
|
|
884
|
+
if ( typeof(arguments[arguments.length-1]) == 'string' ) {
|
|
885
|
+
key = arguments[arguments.length - 1];
|
|
886
|
+
delete arguments[arguments.length - 1];
|
|
887
|
+
--arguments.length;
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
if ( typeof(arguments[arguments.length-1]) == 'object' ) {
|
|
891
|
+
set = arguments[arguments.length - 1];
|
|
892
|
+
delete arguments[arguments.length - 1];
|
|
893
|
+
--arguments.length
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
// if ( typeof(arguments[arguments.length-1]) == 'boolean' ) {
|
|
897
|
+
// uuidSearchModeEnabled = arguments[arguments.length - 1]
|
|
898
|
+
// delete arguments[arguments.length - 1];
|
|
899
|
+
// --arguments.length;
|
|
900
|
+
// }
|
|
901
|
+
|
|
902
|
+
if (arguments.length > 0) {
|
|
903
|
+
filters = arguments;
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
|
|
907
|
+
if ( typeof(filters) == 'undefined' || !filters || typeof(filters) != 'object' ) {
|
|
908
|
+
throw new Error('[ Collection ][ update ] `filters` argument must be defined: Array or Filter Object(s) expected');
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
if ( typeof(set) == 'undefined' || !set || typeof(set) != 'object' ) {
|
|
912
|
+
throw new Error('[ Collection ][ update ] `set` argument must be defined: Object expected');
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
// If an operation (find, insert ...) has been executed, get the previous result; if not, get the whole collection
|
|
916
|
+
var foundResults = null;
|
|
917
|
+
if ( Array.isArray(arguments[0]) ) {
|
|
918
|
+
foundResults = arguments[0];
|
|
919
|
+
} else {
|
|
920
|
+
foundResults = instance.find.apply(this, arguments) || [];
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
result = Array.isArray(this) ? this : JSON.clone(content);
|
|
924
|
+
if (foundResults.length > 0 ) {
|
|
925
|
+
var arr = foundResults.toRaw();
|
|
926
|
+
for (var a = 0, aLen = arr.length; a < aLen; ++a) {
|
|
927
|
+
arr[a] = merge( JSON.clone(set), arr[a]);
|
|
928
|
+
for (var r = 0, rLen = result.length; r < rLen; ++r) {
|
|
929
|
+
if ( typeof(result[r][key]) == 'undefined' && key == '_uuid' && typeof(result[r]['id']) != 'undefined' ) {
|
|
930
|
+
key = 'id';
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
if ( result[r][key] == arr[a][key] ) {
|
|
934
|
+
result[r] = arr[a];
|
|
935
|
+
break;
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
// chaining
|
|
942
|
+
result.limit = instance.limit;
|
|
943
|
+
result.find = instance.find;
|
|
944
|
+
result.findOne = instance.findOne;
|
|
945
|
+
result.insert = instance.insert;
|
|
946
|
+
result.update = instance.update;
|
|
947
|
+
result.replace = instance.replace;
|
|
948
|
+
result.orderBy = instance.orderBy;
|
|
949
|
+
result.max = instance.max;
|
|
950
|
+
result.notIn = instance.notIn;
|
|
951
|
+
result.delete = instance.delete;
|
|
952
|
+
result.toRaw = instance.toRaw;
|
|
953
|
+
result.filter = instance.filter;
|
|
954
|
+
|
|
955
|
+
return result
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
|
|
959
|
+
instance['replace'] = function() {
|
|
960
|
+
var key = '_uuid' // comparison key
|
|
961
|
+
, result = null
|
|
962
|
+
, filters = null
|
|
963
|
+
, set = null
|
|
964
|
+
//, uuidSearchModeEnabled = true
|
|
965
|
+
;
|
|
966
|
+
|
|
967
|
+
|
|
968
|
+
if ( typeof(arguments[arguments.length-1]) == 'string' ) {
|
|
969
|
+
key = arguments[arguments.length - 1];
|
|
970
|
+
delete arguments[arguments.length - 1];
|
|
971
|
+
--arguments.length;
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
if ( typeof(arguments[arguments.length-1]) == 'object' ) {
|
|
975
|
+
set = arguments[arguments.length - 1];
|
|
976
|
+
delete arguments[arguments.length - 1];
|
|
977
|
+
--arguments.length;
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
// if ( typeof(arguments[arguments.length-1]) == 'boolean' ) {
|
|
981
|
+
// uuidSearchModeEnabled = arguments[arguments.length - 1]
|
|
982
|
+
// delete arguments[arguments.length - 1];
|
|
983
|
+
// --arguments.length;
|
|
984
|
+
// }
|
|
985
|
+
|
|
986
|
+
if (arguments.length > 0) {
|
|
987
|
+
filters = arguments;
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
|
|
991
|
+
if ( typeof(filters) == 'undefined' || !filters || typeof(filters) != 'object' ) {
|
|
992
|
+
throw new Error('[ Collection ][ update ] `filters` argument must be defined: Array or Filter Object(s) expected');
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
if ( typeof(set) == 'undefined' || !set || typeof(set) != 'object' ) {
|
|
996
|
+
throw new Error('[ Collection ][ update ] `set` argument must be defined: Object expected');
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
// If an operation (find, insert ...) has been executed, get the previous result; if not, get the whole collection
|
|
1000
|
+
//var currentResult = JSON.clone( (Array.isArray(this)) ? this : content );
|
|
1001
|
+
var currentResult = null;
|
|
1002
|
+
var foundResults = null;
|
|
1003
|
+
if ( Array.isArray(arguments[0]) ) {
|
|
1004
|
+
foundResults = arguments[0];
|
|
1005
|
+
} else {
|
|
1006
|
+
foundResults = instance.find.apply(this, arguments) || [];
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
result = Array.isArray(this) ? this : JSON.clone(content);
|
|
1010
|
+
if (foundResults.length > 0 ) {
|
|
1011
|
+
var arr = foundResults.toRaw();
|
|
1012
|
+
for (var a = 0, aLen = arr.length; a < aLen; ++a) {
|
|
1013
|
+
arr[a] = JSON.clone(set);
|
|
1014
|
+
for (var r = 0, rLen = result.length; r < rLen; ++r) {
|
|
1015
|
+
if ( typeof(result[r][key]) == 'undefined' && key == '_uuid' && typeof(result[r]['id']) != 'undefined' ) {
|
|
1016
|
+
key = 'id';
|
|
1017
|
+
} else if (typeof(result[r][key]) == 'undefined' && key == '_uuid') {
|
|
1018
|
+
throw new Error('No comparison key defined !')
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
if ( result[r][key] == arr[a][key] ) {
|
|
1022
|
+
result[r] = arr[a];
|
|
1023
|
+
break;
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
|
|
1029
|
+
// chaining
|
|
1030
|
+
result.limit = instance.limit;
|
|
1031
|
+
result.find = instance.find;
|
|
1032
|
+
result.findOne = instance.findOne;
|
|
1033
|
+
result.insert = instance.insert;
|
|
1034
|
+
result.update = instance.update;
|
|
1035
|
+
result.replace = instance.replace;
|
|
1036
|
+
result.orderBy = instance.orderBy;
|
|
1037
|
+
result.max = instance.max;
|
|
1038
|
+
result.notIn = instance.notIn;
|
|
1039
|
+
result.delete = instance.delete;
|
|
1040
|
+
result.toRaw = instance.toRaw;
|
|
1041
|
+
result.filter = instance.filter;
|
|
1042
|
+
|
|
1043
|
+
return result
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
/**
|
|
1047
|
+
* .delete({ key: 2 })
|
|
1048
|
+
* .delete({ name: 'Jordan' }, ''id) where id will be use as the `uuid` to compare records
|
|
1049
|
+
*
|
|
1050
|
+
* AND syntax
|
|
1051
|
+
* .delete({ car: 'toyota', color: 'red' })
|
|
1052
|
+
*
|
|
1053
|
+
* OR syntax
|
|
1054
|
+
* .delete({ car: 'toyota', color: red }, { car: 'ford' } ) // will delete all `toyota red cars` & all `ford cars`
|
|
1055
|
+
*
|
|
1056
|
+
* N.B.: will not affect current result - just returning the DIFF
|
|
1057
|
+
* If you
|
|
1058
|
+
* @param {object} filter - samme as `.find(filter)`
|
|
1059
|
+
* @param {string|boolean} [ uuid | disabled ] - by default, Collection is using its internal _uuid
|
|
1060
|
+
* If you want to delete without key comparison, disable `uuid` search mode
|
|
1061
|
+
* .delete({ name: 'Jordan' }, false)
|
|
1062
|
+
*
|
|
1063
|
+
* @returns {array} result
|
|
1064
|
+
*/
|
|
1065
|
+
instance['delete'] = function() {
|
|
1066
|
+
|
|
1067
|
+
var result = instance.notIn.apply(this, arguments);
|
|
1068
|
+
|
|
1069
|
+
result.limit = instance.limit;
|
|
1070
|
+
result.find = instance.find;
|
|
1071
|
+
result.findOne = instance.findOne;
|
|
1072
|
+
result.insert = instance.insert;
|
|
1073
|
+
result.update = instance.update;
|
|
1074
|
+
result.replace = instance.replace;
|
|
1075
|
+
result.orderBy = instance.orderBy;
|
|
1076
|
+
result.max = instance.max;
|
|
1077
|
+
result.notIn = instance.notIn;
|
|
1078
|
+
result.toRaw = instance.toRaw;
|
|
1079
|
+
result.filter = instance.filter;
|
|
1080
|
+
result.delete = this.delete;
|
|
1081
|
+
|
|
1082
|
+
return result
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1085
|
+
|
|
1086
|
+
var sortKeywords = [ 'asc', 'desc' ];
|
|
1087
|
+
/**
|
|
1088
|
+
* sort
|
|
1089
|
+
*
|
|
1090
|
+
* @param {object|array} filter
|
|
1091
|
+
* */
|
|
1092
|
+
instance['orderBy'] = function () {
|
|
1093
|
+
|
|
1094
|
+
if ( typeof(arguments) == 'undefined' || arguments.length < 1)
|
|
1095
|
+
throw new Error('[ Collection->orderBy(filter) ] where `filter` must not be empty or null' );
|
|
1096
|
+
|
|
1097
|
+
var filter = null;
|
|
1098
|
+
if ( arguments.length == 1 ) {
|
|
1099
|
+
filter = arguments[0];
|
|
1100
|
+
} else {
|
|
1101
|
+
// converting arguments into array
|
|
1102
|
+
filter = new Array(arguments.length);
|
|
1103
|
+
for (var f = 0, fLen = filter.length; f < fLen; ++f) {
|
|
1104
|
+
filter[f] = arguments[f]
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
var variableContent = (Array.isArray(this)) ? this : JSON.clone(content);
|
|
1109
|
+
return sortResult(filter, variableContent.toRaw())
|
|
1110
|
+
}
|
|
1111
|
+
|
|
1112
|
+
/**
|
|
1113
|
+
* max
|
|
1114
|
+
* E.g:
|
|
1115
|
+
* myCollection.max({ order: 'not null'})
|
|
1116
|
+
* => 5
|
|
1117
|
+
* myCollection.max({ createAt: 'not null'})
|
|
1118
|
+
* => '2021-12-31T23:59:59'
|
|
1119
|
+
* myCollection.max({ firstName: 'not null'})
|
|
1120
|
+
* => 'Zora'
|
|
1121
|
+
*
|
|
1122
|
+
* @param {object|array} filter
|
|
1123
|
+
*
|
|
1124
|
+
* @returns {number|date|string}
|
|
1125
|
+
* */
|
|
1126
|
+
instance['max'] = function () {
|
|
1127
|
+
if ( typeof(arguments) == 'undefined' || arguments.length < 1)
|
|
1128
|
+
throw new Error('[ Collection->max(filter) ] where `filter` must not be empty or null' );
|
|
1129
|
+
|
|
1130
|
+
var filter = null;
|
|
1131
|
+
if (
|
|
1132
|
+
arguments.length > 1
|
|
1133
|
+
|| Array.isArray(arguments[0])
|
|
1134
|
+
|| typeof(arguments[0]) == 'object' && arguments[0].count() > 1
|
|
1135
|
+
) {
|
|
1136
|
+
throw new Error('[ Collection->max(filter) ] only accept one filter length, and fileter count must be equal to 1' );
|
|
1137
|
+
}
|
|
1138
|
+
filter = arguments[0];
|
|
1139
|
+
try {
|
|
1140
|
+
var key = Object.keys(filter)[0];
|
|
1141
|
+
var subFilter = {};
|
|
1142
|
+
subFilter[key] = 'desc';
|
|
1143
|
+
return instance['find'](filter).orderBy(subFilter).limit(1)[0][key];
|
|
1144
|
+
} catch (err) {
|
|
1145
|
+
throw err
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
/**
|
|
1150
|
+
* sortResult
|
|
1151
|
+
* ref.:
|
|
1152
|
+
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort
|
|
1153
|
+
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare#Browser_compatibility
|
|
1154
|
+
*
|
|
1155
|
+
* e.g.:
|
|
1156
|
+
* .orderBy({ name: 'asc' })
|
|
1157
|
+
*
|
|
1158
|
+
* // overriding filters -> last filter is always right
|
|
1159
|
+
* .orderBy([ { updatedAt : 'desc'}, { name: 'asc' } ])
|
|
1160
|
+
*
|
|
1161
|
+
* // sorting boolean
|
|
1162
|
+
* .orderBy({ isActive: 'desc'}) => will display all active(TRUE) first
|
|
1163
|
+
* NB.: Boolean are 0 (FALSE) or 1 (TRUE)
|
|
1164
|
+
*
|
|
1165
|
+
* // combining filters -> the first one is always right
|
|
1166
|
+
* .orderBy({ updatedAt : 'desc'}, { name: 'asc' })
|
|
1167
|
+
*
|
|
1168
|
+
* @param {object|array} filter
|
|
1169
|
+
* */
|
|
1170
|
+
var sortResult = function (filter, content) {
|
|
1171
|
+
if ( typeof(filter) != 'object') {
|
|
1172
|
+
throw new Error('`filter` parametter must be an object or an array')
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
var condition = filter.count()
|
|
1176
|
+
, sortOp = {}
|
|
1177
|
+
, multiSortOp = null
|
|
1178
|
+
, sortRecursive = null
|
|
1179
|
+
, key = null
|
|
1180
|
+
, prop = null
|
|
1181
|
+
, result = []
|
|
1182
|
+
;
|
|
1183
|
+
|
|
1184
|
+
if (condition == 0) return null;
|
|
1185
|
+
|
|
1186
|
+
|
|
1187
|
+
// asc
|
|
1188
|
+
sortOp['asc'] = function (prop, content) {
|
|
1189
|
+
|
|
1190
|
+
var mapped = content.map(function(obj, i) {
|
|
1191
|
+
var _m = {};
|
|
1192
|
+
_m.index = i;
|
|
1193
|
+
_m[prop] = obj[prop];
|
|
1194
|
+
return _m;
|
|
1195
|
+
});
|
|
1196
|
+
|
|
1197
|
+
mapped.sort(function onAscSort(a, b) {
|
|
1198
|
+
|
|
1199
|
+
|
|
1200
|
+
var _compare = function(a, b) {
|
|
1201
|
+
// handle booleans
|
|
1202
|
+
if ( /^(true|false)$/i.test(a) ) {
|
|
1203
|
+
a = ( /true/i.test(a) ) ? 1 : 0;
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1206
|
+
if ( /^(true|false)$/i.test(b) ) {
|
|
1207
|
+
b = ( /true/i.test(b) ) ? 1 : 0;
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1210
|
+
|
|
1211
|
+
if ( typeof(a) == 'string' && a != '' || typeof(b) == 'string' ) {
|
|
1212
|
+
|
|
1213
|
+
if ( typeof(a) == 'number' ) {
|
|
1214
|
+
a = ''+a; // cast to string
|
|
1215
|
+
}
|
|
1216
|
+
if ( typeof(b) == 'number' ) {
|
|
1217
|
+
b = ''+b; // cast to string
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1220
|
+
return a.localeCompare(b, undefined, {sensitivity: 'case', caseFirst: 'upper'})
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1223
|
+
if (a > b) {
|
|
1224
|
+
return 1;
|
|
1225
|
+
}
|
|
1226
|
+
if (a < b) {
|
|
1227
|
+
return -1;
|
|
1228
|
+
}
|
|
1229
|
+
// a must be equal to b
|
|
1230
|
+
return 0;
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1233
|
+
|
|
1234
|
+
if ( typeof(a) == 'object' ) {
|
|
1235
|
+
return _compare(a[prop], b[prop])
|
|
1236
|
+
}
|
|
1237
|
+
|
|
1238
|
+
return _compare(a, b)
|
|
1239
|
+
|
|
1240
|
+
});
|
|
1241
|
+
|
|
1242
|
+
return mapped.map(function(m, index, result){
|
|
1243
|
+
return content[m.index];
|
|
1244
|
+
});
|
|
1245
|
+
}
|
|
1246
|
+
|
|
1247
|
+
// desc
|
|
1248
|
+
sortOp['desc'] = function (prop, content) {
|
|
1249
|
+
return sortOp['asc'](prop, content).reverse()
|
|
1250
|
+
}
|
|
1251
|
+
|
|
1252
|
+
multiSortOp = function(content, filter) {
|
|
1253
|
+
|
|
1254
|
+
var props = [], keys = [];
|
|
1255
|
+
|
|
1256
|
+
if ( Array.isArray(filter) ) {
|
|
1257
|
+
for (var f = 0, fLen = filter.length; f < fLen; ++f) {
|
|
1258
|
+
props[f] = Object.keys(filter[f])[0];
|
|
1259
|
+
keys[f] = filter[f][ props[f]] ;
|
|
1260
|
+
}
|
|
1261
|
+
} else {
|
|
1262
|
+
var f = 0;
|
|
1263
|
+
for (var flt in filter) {
|
|
1264
|
+
props[f] = flt;
|
|
1265
|
+
keys[f] = filter[flt] ;
|
|
1266
|
+
++f;
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
|
|
1270
|
+
|
|
1271
|
+
|
|
1272
|
+
sortRecursive = function(a, b, columns, order_by, index) {
|
|
1273
|
+
|
|
1274
|
+
var direction = order_by[index] == 'desc' ? 1 : 0;
|
|
1275
|
+
|
|
1276
|
+
var res = null, x = null, y = null;
|
|
1277
|
+
|
|
1278
|
+
if ( typeof(a[columns[index]]) == 'string' && a[columns[index]] != '' ) {
|
|
1279
|
+
|
|
1280
|
+
res = a[columns[index]].localeCompare(b[columns[index]]);
|
|
1281
|
+
|
|
1282
|
+
if ( direction == 0 && res != 0 ) {
|
|
1283
|
+
return res < 0 ? -1 : 1
|
|
1284
|
+
} else if (res != 0) {
|
|
1285
|
+
return res < 0 ? 1 : -1
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
// a must be equal to b
|
|
1289
|
+
return columns.length - 1 > index ? sortRecursive(a, b, columns, order_by, index + 1) : 0;
|
|
1290
|
+
|
|
1291
|
+
} else if (typeof (a[columns[index]]) == 'number' || typeof(b[columns[index]]) == 'number' ) {
|
|
1292
|
+
|
|
1293
|
+
res = (''+ a[columns[index]]).localeCompare((''+ b[columns[index]]), undefined, { numeric: true });
|
|
1294
|
+
|
|
1295
|
+
if (direction == 0 && res != 0) {
|
|
1296
|
+
return res < 0 ? -1 : 1
|
|
1297
|
+
} else if (res != 0) {
|
|
1298
|
+
return res < 0 ? 1 : -1
|
|
1299
|
+
}
|
|
1300
|
+
|
|
1301
|
+
// a must be equal to b
|
|
1302
|
+
return columns.length - 1 > index ? sortRecursive(a, b, columns, order_by, index + 1) : 0;
|
|
1303
|
+
|
|
1304
|
+
} else if ( typeof(a[columns[index]]) == 'boolean' || typeof (b[columns[index]]) == 'boolean' ) {
|
|
1305
|
+
|
|
1306
|
+
if ( typeof(a[columns[index]]) == 'boolean' ) {
|
|
1307
|
+
x = (a[columns[index]]) ? 1 : 0;
|
|
1308
|
+
}
|
|
1309
|
+
|
|
1310
|
+
if ( typeof(b[columns[index]]) == 'boolean' ) {
|
|
1311
|
+
y = (b[columns[index]]) ? 1 : 0;
|
|
1312
|
+
}
|
|
1313
|
+
|
|
1314
|
+
if (x > y) {
|
|
1315
|
+
return direction == 0 ? 1 : -1;
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1318
|
+
if (x < y) {
|
|
1319
|
+
return direction == 0 ? -1: 1;
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1322
|
+
// a must be equal to b
|
|
1323
|
+
return columns.length - 1 > index ? sortRecursive(a, b, columns, order_by, index + 1) : 0;
|
|
1324
|
+
|
|
1325
|
+
} else {
|
|
1326
|
+
|
|
1327
|
+
if (a[columns[index]] > b[columns[index]]) {
|
|
1328
|
+
return direction == 0 ? 1 : -1;
|
|
1329
|
+
}
|
|
1330
|
+
|
|
1331
|
+
if (a[columns[index]] < b[columns[index]]) {
|
|
1332
|
+
return direction == 0 ? -1 : 1;
|
|
1333
|
+
}
|
|
1334
|
+
// a must be equal to b
|
|
1335
|
+
return columns.length - 1 > index ? sortRecursive(a, b, columns, order_by, index + 1) : 0;
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
|
|
1339
|
+
return content.sort(function onMultiSort(a, b) {
|
|
1340
|
+
return sortRecursive(a, b, props, keys, 0);
|
|
1341
|
+
});
|
|
1342
|
+
// return mapped.map(function(m, index, result){
|
|
1343
|
+
// return content[m.index];
|
|
1344
|
+
// });
|
|
1345
|
+
}
|
|
1346
|
+
|
|
1347
|
+
if ( Array.isArray(filter) || filter.count() > 1 ) {
|
|
1348
|
+
|
|
1349
|
+
result = multiSortOp(content, filter);
|
|
1350
|
+
|
|
1351
|
+
} else {
|
|
1352
|
+
|
|
1353
|
+
prop = Object.keys(filter)[0];
|
|
1354
|
+
key = filter[prop];
|
|
1355
|
+
|
|
1356
|
+
result = sortOp[key](prop, content);
|
|
1357
|
+
}
|
|
1358
|
+
|
|
1359
|
+
|
|
1360
|
+
|
|
1361
|
+
// chaining
|
|
1362
|
+
result.find = instance.find;
|
|
1363
|
+
result.findOne = instance.findOne;
|
|
1364
|
+
result.limit = instance.limit;
|
|
1365
|
+
result.notIn = instance.notIn;
|
|
1366
|
+
result.insert = instance.insert;
|
|
1367
|
+
result.update = instance.update;
|
|
1368
|
+
result.replace = instance.replace;
|
|
1369
|
+
result.delete = instance.delete;
|
|
1370
|
+
result.orderBy = instance.orderBy;
|
|
1371
|
+
result.max = instance.max;
|
|
1372
|
+
result.toRaw = instance.toRaw;
|
|
1373
|
+
result.filter = instance.filter;
|
|
1374
|
+
|
|
1375
|
+
return result
|
|
1376
|
+
};
|
|
1377
|
+
|
|
1378
|
+
/**
|
|
1379
|
+
* toRaw
|
|
1380
|
+
* Transform result into a clean format (without _uuid)
|
|
1381
|
+
*
|
|
1382
|
+
* @returns {array} result
|
|
1383
|
+
* */
|
|
1384
|
+
instance['toRaw'] = function() {
|
|
1385
|
+
|
|
1386
|
+
var result = ( Array.isArray(this) ) ? this : content;
|
|
1387
|
+
// cleanup
|
|
1388
|
+
for (var i = 0, len = result.length; i < len; ++i) {
|
|
1389
|
+
if (result[i]._uuid)
|
|
1390
|
+
delete result[i]._uuid;
|
|
1391
|
+
}
|
|
1392
|
+
|
|
1393
|
+
return JSON.clone(result);
|
|
1394
|
+
}
|
|
1395
|
+
|
|
1396
|
+
/**
|
|
1397
|
+
* filter
|
|
1398
|
+
* Reduce record propName
|
|
1399
|
+
* @param {string|array} filter
|
|
1400
|
+
* e.g: 'id'
|
|
1401
|
+
* e.g: ['id', 'name']
|
|
1402
|
+
*
|
|
1403
|
+
* @returns {array} rawFilteredResult
|
|
1404
|
+
* */
|
|
1405
|
+
instance['filter'] = function(filter) {
|
|
1406
|
+
|
|
1407
|
+
if ( typeof(filter) == 'undefined' ) {
|
|
1408
|
+
throw new Error('`filter` parametter must be a string or an array.');
|
|
1409
|
+
}
|
|
1410
|
+
var result = ( Array.isArray(this) ) ? this : content;
|
|
1411
|
+
if ( !result.length ) {
|
|
1412
|
+
return []
|
|
1413
|
+
}
|
|
1414
|
+
var i = 0, len = result.length;
|
|
1415
|
+
var rawFilteredResult = [], fCount = 0;
|
|
1416
|
+
|
|
1417
|
+
if ( Array.isArray(filter) ) {
|
|
1418
|
+
var f = null, fLen = filter.length, wrote = null;
|
|
1419
|
+
for (; i < len; ++i) {
|
|
1420
|
+
wrote = false;
|
|
1421
|
+
f = 0;
|
|
1422
|
+
for (; f < fLen; ++f) {
|
|
1423
|
+
if ( typeof(result[i][ filter[f] ]) != 'undefined' ) {
|
|
1424
|
+
if ( typeof(rawFilteredResult[fCount]) == 'undefined' ) {
|
|
1425
|
+
rawFilteredResult[fCount] = {}
|
|
1426
|
+
}
|
|
1427
|
+
rawFilteredResult[fCount][ filter[f] ] = result[i][ filter[f] ];
|
|
1428
|
+
wrote = true;
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
if (wrote)
|
|
1432
|
+
++fCount;
|
|
1433
|
+
}
|
|
1434
|
+
} else {
|
|
1435
|
+
for (; i < len; ++i) {
|
|
1436
|
+
if ( typeof(result[i][filter]) != 'undefined' ) {
|
|
1437
|
+
if ( typeof(rawFilteredResult[fCount]) == 'undefined' ) {
|
|
1438
|
+
rawFilteredResult[fCount] = {}
|
|
1439
|
+
}
|
|
1440
|
+
rawFilteredResult[fCount][filter] = result[i][filter];
|
|
1441
|
+
++fCount;
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
}
|
|
1445
|
+
|
|
1446
|
+
return JSON.clone(rawFilteredResult);
|
|
1447
|
+
}
|
|
1448
|
+
|
|
1449
|
+
|
|
1450
|
+
return instance;
|
|
1451
|
+
};
|
|
1452
|
+
|
|
1453
|
+
if ( ( typeof(module) !== 'undefined' ) && module.exports ) {
|
|
1454
|
+
// Publish as node.js module
|
|
1455
|
+
module.exports = Collection
|
|
1456
|
+
} else if ( typeof(define) === 'function' && define.amd) {
|
|
1457
|
+
// Publish as AMD module
|
|
1458
|
+
define(function() { return Collection })
|
|
1459
|
+
}
|