@nullix/zod-mongoose-studio 1.0.13 → 2.0.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/.output/nitro.json +1 -1
- package/.output/public/_nuxt/{Db4IAypj.js → 0J_bLG6U.js} +1 -1
- package/.output/public/_nuxt/{Y39o1QEi.js → 5KLjKHc1.js} +1 -1
- package/.output/public/_nuxt/{B4zoPYF-.js → B2UrsJHg.js} +1 -1
- package/.output/public/_nuxt/{BSqjh6Vk.js → BC5hGokz.js} +1 -1
- package/.output/public/_nuxt/{BS4yU4O0.js → BJwN20Xm.js} +1 -1
- package/.output/public/_nuxt/{D8_n84hl.js → BMgDPqps.js} +1 -1
- package/.output/public/_nuxt/{CqNsQbt9.js → B_sGF2qN.js} +1 -1
- package/.output/public/_nuxt/{NAqlztEN.js → BeaJ7I-K.js} +10 -10
- package/.output/public/_nuxt/{WZ0WK9cR.js → BkE1sm_1.js} +1 -1
- package/.output/public/_nuxt/{kBtP64Rx.js → CADbZwE5.js} +1 -1
- package/.output/public/_nuxt/{B8qGaxNm.js → CB0WRoVi.js} +1 -1
- package/.output/public/_nuxt/{BV6uALfO.js → CCh0PVV0.js} +1 -1
- package/.output/public/_nuxt/{CP9Z7-_9.js → Cr0GW7rA.js} +1 -1
- package/.output/public/_nuxt/{DeCqoVOS.js → DJe7Wxdv.js} +1 -1
- package/.output/public/_nuxt/{dBZQW7JD.js → DRBrUaE5.js} +1 -1
- package/.output/public/_nuxt/{Db19R32y.js → DV2n9B6m.js} +1 -1
- package/.output/public/_nuxt/{CvnpbYw0.js → DVD-jGiv.js} +1 -1
- package/.output/public/_nuxt/{BWajNATZ.js → Dk9qGA5X.js} +3 -3
- package/.output/public/_nuxt/builds/latest.json +1 -1
- package/.output/public/_nuxt/builds/meta/dc761332-547d-4953-b51d-b2d453009b48.json +1 -0
- package/.output/public/_nuxt/error-404.64pZEiDn.css +1 -0
- package/.output/public/_nuxt/error-500.DHOpI0Ir.css +1 -0
- package/.output/public/_nuxt/{BoHhCIKW.js → koEZfutw.js} +3 -3
- package/.output/public/_nuxt/{B_782F4p.js → r6LdR7DN.js} +1 -1
- package/.output/public/_nuxt/{BEI71c6K.js → rEfOp38p.js} +1 -1
- package/.output/server/chunks/_/error-500.mjs.map +1 -1
- package/.output/server/chunks/build/client.precomputed.mjs +1 -1
- package/.output/server/chunks/build/{error-404-8tbBXju4.mjs → error-404-BN-7rNE4.mjs} +4 -4
- package/.output/server/chunks/build/error-404-BN-7rNE4.mjs.map +1 -0
- package/.output/server/chunks/build/error-404-styles.Byx46oLR.mjs +8 -0
- package/.output/server/chunks/build/error-404-styles.Byx46oLR.mjs.map +1 -0
- package/.output/server/chunks/build/{error-500-DxFsom1i.mjs → error-500-DhIQ-2yt.mjs} +4 -4
- package/.output/server/chunks/build/error-500-DhIQ-2yt.mjs.map +1 -0
- package/.output/server/chunks/build/error-500-styles.BL3UT0Wa.mjs +8 -0
- package/.output/server/chunks/build/error-500-styles.BL3UT0Wa.mjs.map +1 -0
- package/.output/server/chunks/build/{index-BB-Clavm.mjs → index-Dnrh1ePF.mjs} +1 -1
- package/.output/server/chunks/build/index-Dnrh1ePF.mjs.map +1 -0
- package/.output/server/chunks/build/server.mjs +9 -9
- package/.output/server/chunks/build/styles.mjs +4 -4
- package/.output/server/chunks/nitro/nitro.mjs +333 -333
- package/.output/server/chunks/nitro/nitro.mjs.map +1 -1
- package/.output/server/chunks/routes/renderer.mjs.map +1 -1
- package/.output/server/node_modules/bson/lib/bson.cjs +157 -48
- package/.output/server/node_modules/bson/package.json +9 -11
- package/.output/server/node_modules/kareem/index.js +228 -343
- package/.output/server/node_modules/kareem/package.json +3 -3
- package/.output/server/node_modules/mongodb/lib/bson.js +27 -5
- package/.output/server/node_modules/mongodb/lib/bulk/common.js +7 -9
- package/.output/server/node_modules/mongodb/lib/change_stream.js +91 -39
- package/.output/server/node_modules/mongodb/lib/client-side-encryption/auto_encrypter.js +21 -14
- package/.output/server/node_modules/mongodb/lib/client-side-encryption/client_encryption.js +2 -5
- package/.output/server/node_modules/mongodb/lib/client-side-encryption/errors.js +3 -1
- package/.output/server/node_modules/mongodb/lib/client-side-encryption/mongocryptd_manager.js +1 -1
- package/.output/server/node_modules/mongodb/lib/client-side-encryption/state_machine.js +1 -0
- package/.output/server/node_modules/mongodb/lib/cmap/auth/aws4.js +161 -0
- package/.output/server/node_modules/mongodb/lib/cmap/auth/aws_temporary_credentials.js +11 -58
- package/.output/server/node_modules/mongodb/lib/cmap/auth/gssapi.js +4 -6
- package/.output/server/node_modules/mongodb/lib/cmap/auth/mongo_credentials.js +2 -16
- package/.output/server/node_modules/mongodb/lib/cmap/auth/mongodb_aws.js +14 -23
- package/.output/server/node_modules/mongodb/lib/cmap/auth/mongodb_oidc/azure_machine_workflow.js +3 -3
- package/.output/server/node_modules/mongodb/lib/cmap/auth/mongodb_oidc/gcp_machine_workflow.js +3 -3
- package/.output/server/node_modules/mongodb/lib/cmap/auth/mongodb_oidc/k8s_machine_workflow.js +4 -3
- package/.output/server/node_modules/mongodb/lib/cmap/auth/mongodb_oidc/token_machine_workflow.js +4 -3
- package/.output/server/node_modules/mongodb/lib/cmap/auth/mongodb_oidc.js +4 -4
- package/.output/server/node_modules/mongodb/lib/cmap/auth/plain.js +1 -1
- package/.output/server/node_modules/mongodb/lib/cmap/auth/providers.js +0 -1
- package/.output/server/node_modules/mongodb/lib/cmap/auth/scram.js +53 -40
- package/.output/server/node_modules/mongodb/lib/cmap/commands.js +46 -39
- package/.output/server/node_modules/mongodb/lib/cmap/connect.js +35 -3
- package/.output/server/node_modules/mongodb/lib/cmap/connection.js +36 -32
- package/.output/server/node_modules/mongodb/lib/cmap/connection_pool.js +67 -67
- package/.output/server/node_modules/mongodb/lib/cmap/connection_pool_events.js +3 -3
- package/.output/server/node_modules/mongodb/lib/cmap/errors.js +1 -1
- package/.output/server/node_modules/mongodb/lib/cmap/handshake/client_metadata.js +15 -13
- package/.output/server/node_modules/mongodb/lib/cmap/metrics.js +3 -3
- package/.output/server/node_modules/mongodb/lib/cmap/wire_protocol/compression.js +26 -10
- package/.output/server/node_modules/mongodb/lib/cmap/wire_protocol/constants.js +3 -1
- package/.output/server/node_modules/mongodb/lib/cmap/wire_protocol/on_data.js +0 -1
- package/.output/server/node_modules/mongodb/lib/cmap/wire_protocol/on_demand/document.js +9 -9
- package/.output/server/node_modules/mongodb/lib/cmap/wire_protocol/responses.js +2 -2
- package/.output/server/node_modules/mongodb/lib/collection.js +1 -1
- package/.output/server/node_modules/mongodb/lib/connection_string.js +30 -15
- package/.output/server/node_modules/mongodb/lib/cursor/abstract_cursor.js +17 -34
- package/.output/server/node_modules/mongodb/lib/cursor/change_stream_cursor.js +2 -2
- package/.output/server/node_modules/mongodb/lib/cursor/find_cursor.js +37 -26
- package/.output/server/node_modules/mongodb/lib/cursor/run_command_cursor.js +1 -1
- package/.output/server/node_modules/mongodb/lib/db.js +6 -7
- package/.output/server/node_modules/mongodb/lib/deps.js +0 -13
- package/.output/server/node_modules/mongodb/lib/error.js +7 -10
- package/.output/server/node_modules/mongodb/lib/gridfs/download.js +7 -6
- package/.output/server/node_modules/mongodb/lib/gridfs/index.js +9 -9
- package/.output/server/node_modules/mongodb/lib/gridfs/upload.js +17 -23
- package/.output/server/node_modules/mongodb/lib/index.js +2 -4
- package/.output/server/node_modules/mongodb/lib/mongo_client.js +58 -67
- package/.output/server/node_modules/mongodb/lib/mongo_client_auth_providers.js +0 -6
- package/.output/server/node_modules/mongodb/lib/mongo_logger.js +11 -5
- package/.output/server/node_modules/mongodb/lib/mongo_types.js +1 -2
- package/.output/server/node_modules/mongodb/lib/operations/aggregate.js +0 -3
- package/.output/server/node_modules/mongodb/lib/operations/create_collection.js +0 -1
- package/.output/server/node_modules/mongodb/lib/operations/drop.js +8 -9
- package/.output/server/node_modules/mongodb/lib/operations/end_sessions.js +34 -0
- package/.output/server/node_modules/mongodb/lib/operations/execute_operation.js +121 -45
- package/.output/server/node_modules/mongodb/lib/operations/operation.js +1 -0
- package/.output/server/node_modules/mongodb/lib/read_preference.js +10 -14
- package/.output/server/node_modules/mongodb/lib/runtime_adapters.js +32 -0
- package/.output/server/node_modules/mongodb/lib/sdam/monitor.js +8 -8
- package/.output/server/node_modules/mongodb/lib/sdam/server.js +55 -43
- package/.output/server/node_modules/mongodb/lib/sdam/server_description.js +1 -1
- package/.output/server/node_modules/mongodb/lib/sdam/server_selection.js +135 -72
- package/.output/server/node_modules/mongodb/lib/sdam/srv_polling.js +3 -3
- package/.output/server/node_modules/mongodb/lib/sdam/topology.js +37 -77
- package/.output/server/node_modules/mongodb/lib/sdam/topology_description.js +1 -1
- package/.output/server/node_modules/mongodb/lib/sessions.js +150 -40
- package/.output/server/node_modules/mongodb/lib/transactions.js +2 -13
- package/.output/server/node_modules/mongodb/lib/utils.js +42 -90
- package/.output/server/node_modules/mongodb/package.json +49 -45
- package/.output/server/node_modules/mongodb-connection-string-url/lib/index.js +45 -19
- package/.output/server/node_modules/mongodb-connection-string-url/lib/redact.js +30 -19
- package/.output/server/node_modules/mongodb-connection-string-url/package.json +25 -16
- package/.output/server/node_modules/mongoose/lib/aggregate.js +108 -127
- package/.output/server/node_modules/mongoose/lib/cast/bigint.js +3 -3
- package/.output/server/node_modules/mongoose/lib/cast/boolean.js +3 -3
- package/.output/server/node_modules/mongoose/lib/cast/double.js +4 -4
- package/.output/server/node_modules/mongoose/lib/cast/int32.js +2 -2
- package/.output/server/node_modules/mongoose/lib/cast/number.js +6 -6
- package/.output/server/node_modules/mongoose/lib/cast/string.js +3 -3
- package/.output/server/node_modules/mongoose/lib/cast/uuid.js +5 -48
- package/.output/server/node_modules/mongoose/lib/cast.js +16 -24
- package/.output/server/node_modules/mongoose/lib/collection.js +6 -6
- package/.output/server/node_modules/mongoose/lib/connection.js +108 -105
- package/.output/server/node_modules/mongoose/lib/cursor/aggregationCursor.js +23 -33
- package/.output/server/node_modules/mongoose/lib/cursor/changeStream.js +60 -40
- package/.output/server/node_modules/mongoose/lib/cursor/queryCursor.js +21 -25
- package/.output/server/node_modules/mongoose/lib/document.js +712 -531
- package/.output/server/node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js +85 -130
- package/.output/server/node_modules/mongoose/lib/drivers/node-mongodb-native/connection.js +32 -41
- package/.output/server/node_modules/mongoose/lib/error/cast.js +21 -12
- package/.output/server/node_modules/mongoose/lib/error/createCollectionsError.js +2 -2
- package/.output/server/node_modules/mongoose/lib/error/divergentArray.js +1 -1
- package/.output/server/node_modules/mongoose/lib/error/eachAsyncMultiError.js +1 -1
- package/.output/server/node_modules/mongoose/lib/error/index.js +3 -3
- package/.output/server/node_modules/mongoose/lib/error/invalidSchemaOption.js +1 -1
- package/.output/server/node_modules/mongoose/lib/error/messages.js +1 -0
- package/.output/server/node_modules/mongoose/lib/error/missingSchema.js +1 -1
- package/.output/server/node_modules/mongoose/lib/error/objectParameter.js +4 -5
- package/.output/server/node_modules/mongoose/lib/error/overwriteModel.js +1 -1
- package/.output/server/node_modules/mongoose/lib/error/setOptionError.js +3 -3
- package/.output/server/node_modules/mongoose/lib/error/strict.js +3 -3
- package/.output/server/node_modules/mongoose/lib/error/strictPopulate.js +2 -2
- package/.output/server/node_modules/mongoose/lib/error/syncIndexes.js +2 -2
- package/.output/server/node_modules/mongoose/lib/error/validation.js +2 -10
- package/.output/server/node_modules/mongoose/lib/error/validator.js +1 -1
- package/.output/server/node_modules/mongoose/lib/error/version.js +2 -2
- package/.output/server/node_modules/mongoose/lib/helpers/aggregate/prepareDiscriminatorPipeline.js +4 -4
- package/.output/server/node_modules/mongoose/lib/helpers/buildMiddlewareFilter.js +24 -0
- package/.output/server/node_modules/mongoose/lib/helpers/clone.js +35 -18
- package/.output/server/node_modules/mongoose/lib/helpers/common.js +5 -5
- package/.output/server/node_modules/mongoose/lib/helpers/cursor/eachAsync.js +4 -4
- package/.output/server/node_modules/mongoose/lib/helpers/discriminator/getConstructor.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/discriminator/getDiscriminatorByValue.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/discriminator/getSchemaDiscriminatorByValue.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/discriminator/mergeDiscriminatorSchema.js +10 -5
- package/.output/server/node_modules/mongoose/lib/helpers/document/applyDefaults.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/document/applyTimestamps.js +11 -10
- package/.output/server/node_modules/mongoose/lib/helpers/document/applyVirtuals.js +10 -9
- package/.output/server/node_modules/mongoose/lib/helpers/document/cleanModifiedSubpaths.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/document/compile.js +17 -14
- package/.output/server/node_modules/mongoose/lib/helpers/document/getDeepestSubdocumentForPath.js +3 -3
- package/.output/server/node_modules/mongoose/lib/helpers/document/getEmbeddedDiscriminatorPath.js +2 -2
- package/.output/server/node_modules/mongoose/lib/helpers/document/isInPathsToSave.js +24 -0
- package/.output/server/node_modules/mongoose/lib/helpers/get.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/indexes/decorateDiscriminatorIndexOptions.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/indexes/getRelatedIndexes.js +3 -3
- package/.output/server/node_modules/mongoose/lib/helpers/indexes/isIndexEqual.js +3 -4
- package/.output/server/node_modules/mongoose/lib/helpers/indexes/isIndexSpecEqual.js +3 -3
- package/.output/server/node_modules/mongoose/lib/helpers/isBsonType.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/isMongooseObject.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/isObject.js +2 -2
- package/.output/server/node_modules/mongoose/lib/helpers/isSimpleValidator.js +2 -2
- package/.output/server/node_modules/mongoose/lib/helpers/minimize.js +2 -2
- package/.output/server/node_modules/mongoose/lib/helpers/model/applyDefaultsToPOJO.js +2 -2
- package/.output/server/node_modules/mongoose/lib/helpers/model/applyHooks.js +55 -54
- package/.output/server/node_modules/mongoose/lib/helpers/model/applyMethods.js +2 -2
- package/.output/server/node_modules/mongoose/lib/helpers/model/applyStaticHooks.js +1 -48
- package/.output/server/node_modules/mongoose/lib/helpers/model/castBulkWrite.js +8 -12
- package/.output/server/node_modules/mongoose/lib/helpers/model/discriminator.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/parallelLimit.js +18 -36
- package/.output/server/node_modules/mongoose/lib/helpers/pluralize.js +4 -4
- package/.output/server/node_modules/mongoose/lib/helpers/populate/assignRawDocsToIdStructure.js +4 -11
- package/.output/server/node_modules/mongoose/lib/helpers/populate/assignVals.js +10 -10
- package/.output/server/node_modules/mongoose/lib/helpers/populate/createPopulateQueryFilter.js +3 -3
- package/.output/server/node_modules/mongoose/lib/helpers/populate/getModelsMapForPopulate.js +197 -69
- package/.output/server/node_modules/mongoose/lib/helpers/populate/getSchemaTypes.js +15 -15
- package/.output/server/node_modules/mongoose/lib/helpers/populate/markArraySubdocsPopulated.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/populate/modelNamesFromRefPath.js +10 -2
- package/.output/server/node_modules/mongoose/lib/helpers/populate/setPopulatedVirtualValue.js +5 -5
- package/.output/server/node_modules/mongoose/lib/helpers/printJestWarning.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/processConnectionOptions.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/projection/hasIncludedChildren.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/projection/isPathExcluded.js +3 -3
- package/.output/server/node_modules/mongoose/lib/helpers/projection/isSubpath.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/projection/parseProjection.js +9 -4
- package/.output/server/node_modules/mongoose/lib/helpers/query/cast$expr.js +8 -10
- package/.output/server/node_modules/mongoose/lib/helpers/query/castFilterPath.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/query/castUpdate.js +44 -38
- package/.output/server/node_modules/mongoose/lib/helpers/query/getEmbeddedDiscriminatorPath.js +8 -8
- package/.output/server/node_modules/mongoose/lib/helpers/query/handleImmutable.js +8 -8
- package/.output/server/node_modules/mongoose/lib/helpers/schema/applyPlugins.js +2 -2
- package/.output/server/node_modules/mongoose/lib/helpers/schema/applyReadConcern.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/schema/applyWriteConcern.js +4 -2
- package/.output/server/node_modules/mongoose/lib/helpers/schema/getIndexes.js +5 -11
- package/.output/server/node_modules/mongoose/lib/helpers/schema/getSubdocumentStrictValue.js +2 -2
- package/.output/server/node_modules/mongoose/lib/helpers/schema/handleIdOption.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/schema/idGetter.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/schematype/handleImmutable.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/setDefaultsOnInsert.js +26 -13
- package/.output/server/node_modules/mongoose/lib/helpers/timestamps/setDocumentTimestamps.js +2 -2
- package/.output/server/node_modules/mongoose/lib/helpers/timestamps/setupTimestamps.js +60 -38
- package/.output/server/node_modules/mongoose/lib/helpers/update/applyTimestampsToUpdate.js +13 -10
- package/.output/server/node_modules/mongoose/lib/helpers/update/castArrayFilters.js +4 -4
- package/.output/server/node_modules/mongoose/lib/helpers/update/decorateUpdateWithVersionKey.js +1 -1
- package/.output/server/node_modules/mongoose/lib/helpers/update/modifiedPaths.js +2 -2
- package/.output/server/node_modules/mongoose/lib/helpers/update/removeUnusedArrayFilters.js +7 -2
- package/.output/server/node_modules/mongoose/lib/helpers/updateValidators.js +58 -119
- package/.output/server/node_modules/mongoose/lib/model.js +940 -946
- package/.output/server/node_modules/mongoose/lib/mongoose.js +131 -79
- package/.output/server/node_modules/mongoose/lib/options/schemaArrayOptions.js +2 -2
- package/.output/server/node_modules/mongoose/lib/options/schemaBufferOptions.js +1 -1
- package/.output/server/node_modules/mongoose/lib/options/schemaDocumentArrayOptions.js +23 -0
- package/.output/server/node_modules/mongoose/lib/options/schemaNumberOptions.js +3 -3
- package/.output/server/node_modules/mongoose/lib/options/schemaObjectIdOptions.js +2 -2
- package/.output/server/node_modules/mongoose/lib/options/schemaStringOptions.js +6 -6
- package/.output/server/node_modules/mongoose/lib/options/schemaSubdocumentOptions.js +23 -0
- package/.output/server/node_modules/mongoose/lib/options/schemaTypeOptions.js +27 -13
- package/.output/server/node_modules/mongoose/lib/options/virtualOptions.js +12 -12
- package/.output/server/node_modules/mongoose/lib/plugins/index.js +0 -1
- package/.output/server/node_modules/mongoose/lib/plugins/saveSubdocs.js +84 -92
- package/.output/server/node_modules/mongoose/lib/plugins/sharding.js +33 -15
- package/.output/server/node_modules/mongoose/lib/plugins/trackTransaction.js +29 -25
- package/.output/server/node_modules/mongoose/lib/query.js +700 -548
- package/.output/server/node_modules/mongoose/lib/queryHelpers.js +34 -32
- package/.output/server/node_modules/mongoose/lib/schema/array.js +69 -113
- package/.output/server/node_modules/mongoose/lib/schema/bigint.js +18 -20
- package/.output/server/node_modules/mongoose/lib/schema/boolean.js +20 -22
- package/.output/server/node_modules/mongoose/lib/schema/buffer.js +23 -25
- package/.output/server/node_modules/mongoose/lib/schema/date.js +19 -21
- package/.output/server/node_modules/mongoose/lib/schema/decimal128.js +16 -18
- package/.output/server/node_modules/mongoose/lib/schema/documentArray.js +94 -131
- package/.output/server/node_modules/mongoose/lib/schema/documentArrayElement.js +50 -16
- package/.output/server/node_modules/mongoose/lib/schema/double.js +16 -18
- package/.output/server/node_modules/mongoose/lib/schema/index.js +1 -0
- package/.output/server/node_modules/mongoose/lib/schema/int32.js +17 -19
- package/.output/server/node_modules/mongoose/lib/schema/map.js +17 -24
- package/.output/server/node_modules/mongoose/lib/schema/mixed.js +14 -14
- package/.output/server/node_modules/mongoose/lib/schema/number.js +38 -28
- package/.output/server/node_modules/mongoose/lib/schema/objectId.js +18 -20
- package/.output/server/node_modules/mongoose/lib/schema/operators/exists.js +1 -1
- package/.output/server/node_modules/mongoose/lib/schema/operators/geospatial.js +1 -1
- package/.output/server/node_modules/mongoose/lib/schema/operators/text.js +4 -4
- package/.output/server/node_modules/mongoose/lib/schema/string.js +42 -27
- package/.output/server/node_modules/mongoose/lib/schema/subdocument.js +47 -58
- package/.output/server/node_modules/mongoose/lib/schema/union.js +54 -4
- package/.output/server/node_modules/mongoose/lib/schema/uuid.js +17 -40
- package/.output/server/node_modules/mongoose/lib/schema.js +235 -176
- package/.output/server/node_modules/mongoose/lib/schemaType.js +227 -158
- package/.output/server/node_modules/mongoose/lib/stateMachine.js +5 -8
- package/.output/server/node_modules/mongoose/lib/types/array/index.js +5 -5
- package/.output/server/node_modules/mongoose/lib/types/array/methods/index.js +27 -28
- package/.output/server/node_modules/mongoose/lib/types/arraySubdocument.js +11 -11
- package/.output/server/node_modules/mongoose/lib/types/buffer.js +15 -15
- package/.output/server/node_modules/mongoose/lib/types/decimal128.js +1 -1
- package/.output/server/node_modules/mongoose/lib/types/documentArray/index.js +4 -4
- package/.output/server/node_modules/mongoose/lib/types/documentArray/methods/index.js +15 -13
- package/.output/server/node_modules/mongoose/lib/types/double.js +1 -1
- package/.output/server/node_modules/mongoose/lib/types/map.js +20 -71
- package/.output/server/node_modules/mongoose/lib/types/objectid.js +1 -1
- package/.output/server/node_modules/mongoose/lib/types/subdocument.js +32 -81
- package/.output/server/node_modules/mongoose/lib/types/uuid.js +1 -1
- package/.output/server/node_modules/mongoose/lib/utils.js +91 -70
- package/.output/server/node_modules/mongoose/lib/validOptions.js +4 -3
- package/.output/server/node_modules/mongoose/lib/virtualType.js +18 -18
- package/.output/server/node_modules/mongoose/package.json +46 -63
- package/.output/server/node_modules/mquery/lib/collection/collection.js +3 -1
- package/.output/server/node_modules/mquery/lib/collection/node.js +17 -3
- package/.output/server/node_modules/mquery/lib/mquery.js +136 -93
- package/.output/server/node_modules/mquery/lib/permissions.js +21 -6
- package/.output/server/node_modules/mquery/package.json +4 -7
- package/.output/server/package.json +7 -9
- package/package.json +3 -3
- package/.output/public/_nuxt/builds/meta/0d6006db-fbb0-4297-85cf-bf92ceafcb79.json +0 -1
- package/.output/public/_nuxt/error-404.CTWLHxjC.css +0 -1
- package/.output/public/_nuxt/error-500.UBfk8-QP.css +0 -1
- package/.output/server/chunks/build/error-404-8tbBXju4.mjs.map +0 -1
- package/.output/server/chunks/build/error-404-styles.BeWfK6Py.mjs +0 -8
- package/.output/server/chunks/build/error-404-styles.BeWfK6Py.mjs.map +0 -1
- package/.output/server/chunks/build/error-500-DxFsom1i.mjs.map +0 -1
- package/.output/server/chunks/build/error-500-styles.CPUUvoY-.mjs +0 -8
- package/.output/server/chunks/build/error-500-styles.CPUUvoY-.mjs.map +0 -1
- package/.output/server/chunks/build/index-BB-Clavm.mjs.map +0 -1
- package/.output/server/node_modules/debug/package.json +0 -64
- package/.output/server/node_modules/debug/src/browser.js +0 -272
- package/.output/server/node_modules/debug/src/common.js +0 -292
- package/.output/server/node_modules/debug/src/index.js +0 -10
- package/.output/server/node_modules/debug/src/node.js +0 -263
- package/.output/server/node_modules/mongodb/lib/client-side-encryption/crypto_callbacks.js +0 -81
- package/.output/server/node_modules/mongodb/lib/resource_management.js +0 -58
- package/.output/server/node_modules/mongoose/lib/browserDocument.js +0 -101
- package/.output/server/node_modules/mongoose/lib/documentProvider.js +0 -30
- package/.output/server/node_modules/mongoose/lib/helpers/createJSONSchemaTypeDefinition.js +0 -24
- package/.output/server/node_modules/mongoose/lib/helpers/promiseOrCallback.js +0 -54
- package/.output/server/node_modules/mongoose/lib/plugins/validateBeforeSave.js +0 -51
- package/.output/server/node_modules/supports-color/index.js +0 -202
- package/.output/server/node_modules/supports-color/package.json +0 -64
|
@@ -24,127 +24,65 @@ Kareem.overwriteResult = function overwriteResult() {
|
|
|
24
24
|
this.args = [...arguments];
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
+
Kareem.overwriteArguments = function overwriteArguments() {
|
|
28
|
+
if (!(this instanceof Kareem.overwriteArguments)) {
|
|
29
|
+
return new Kareem.overwriteArguments(...arguments);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
this.args = [...arguments];
|
|
33
|
+
};
|
|
34
|
+
|
|
27
35
|
/**
|
|
28
36
|
* Execute all "pre" hooks for "name"
|
|
29
37
|
* @param {String} name The hook name to execute
|
|
30
38
|
* @param {*} context Overwrite the "this" for the hook
|
|
31
|
-
* @param {Array
|
|
32
|
-
* @param {
|
|
33
|
-
* @
|
|
39
|
+
* @param {Array} args arguments passed to the pre hooks
|
|
40
|
+
* @param {Object} [options] Optional options
|
|
41
|
+
* @param {Function} [options.filter] Filter function to select which hooks to run
|
|
42
|
+
* @returns {Array} The potentially modified arguments
|
|
34
43
|
*/
|
|
35
|
-
Kareem.prototype.execPre = function(name, context, args,
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
44
|
+
Kareem.prototype.execPre = async function execPre(name, context, args, options) {
|
|
45
|
+
let pres = this._pres.get(name) || [];
|
|
46
|
+
if (options?.filter) {
|
|
47
|
+
pres = pres.filter(options.filter);
|
|
39
48
|
}
|
|
40
|
-
const pres = this._pres.get(name) || [];
|
|
41
49
|
const numPres = pres.length;
|
|
42
|
-
|
|
43
|
-
let
|
|
44
|
-
let asyncPresLeft = numAsyncPres;
|
|
45
|
-
let done = false;
|
|
46
|
-
const $args = args;
|
|
47
|
-
let shouldSkipWrappedFunction = null;
|
|
50
|
+
let $args = args;
|
|
51
|
+
let skipWrappedFunction = null;
|
|
48
52
|
|
|
49
53
|
if (!numPres) {
|
|
50
|
-
return
|
|
51
|
-
callback(null);
|
|
52
|
-
});
|
|
54
|
+
return $args;
|
|
53
55
|
}
|
|
54
56
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
const pre = pres[currentPre];
|
|
60
|
-
|
|
61
|
-
if (pre.isAsync) {
|
|
62
|
-
const args = [
|
|
63
|
-
decorateNextFn(_next),
|
|
64
|
-
decorateNextFn(function(error) {
|
|
65
|
-
if (error) {
|
|
66
|
-
if (done) {
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
if (error instanceof Kareem.skipWrappedFunction) {
|
|
70
|
-
shouldSkipWrappedFunction = error;
|
|
71
|
-
} else {
|
|
72
|
-
done = true;
|
|
73
|
-
return callback(error);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
if (--asyncPresLeft === 0 && currentPre >= numPres) {
|
|
77
|
-
return callback(shouldSkipWrappedFunction);
|
|
78
|
-
}
|
|
79
|
-
})
|
|
80
|
-
];
|
|
81
|
-
|
|
82
|
-
callMiddlewareFunction(pre.fn, context, args, args[0]);
|
|
83
|
-
} else if (pre.fn.length > 0) {
|
|
84
|
-
const args = [decorateNextFn(_next)];
|
|
85
|
-
const _args = arguments.length >= 2 ? arguments : [null].concat($args);
|
|
86
|
-
for (let i = 1; i < _args.length; ++i) {
|
|
87
|
-
if (i === _args.length - 1 && typeof _args[i] === 'function') {
|
|
88
|
-
continue; // skip callbacks to avoid accidentally calling the callback from a hook
|
|
89
|
-
}
|
|
90
|
-
args.push(_args[i]);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
callMiddlewareFunction(pre.fn, context, args, args[0]);
|
|
94
|
-
} else {
|
|
95
|
-
let maybePromiseLike = null;
|
|
96
|
-
try {
|
|
97
|
-
maybePromiseLike = pre.fn.call(context);
|
|
98
|
-
} catch (err) {
|
|
99
|
-
if (err != null) {
|
|
100
|
-
return callback(err);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
57
|
+
for (const pre of pres) {
|
|
58
|
+
try {
|
|
59
|
+
const maybePromiseLike = pre.fn.apply(context, $args);
|
|
104
60
|
if (isPromiseLike(maybePromiseLike)) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
if (asyncPresLeft > 0) {
|
|
109
|
-
// Leave parallel hooks to run
|
|
110
|
-
return;
|
|
111
|
-
} else {
|
|
112
|
-
return nextTick(function() {
|
|
113
|
-
callback(shouldSkipWrappedFunction);
|
|
114
|
-
});
|
|
115
|
-
}
|
|
61
|
+
const result = await maybePromiseLike;
|
|
62
|
+
if (result instanceof Kareem.overwriteArguments) {
|
|
63
|
+
$args = result.args;
|
|
116
64
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
next.apply(null, [null].concat(args));
|
|
123
|
-
|
|
124
|
-
function _next(error) {
|
|
125
|
-
if (error) {
|
|
126
|
-
if (done) {
|
|
127
|
-
return;
|
|
65
|
+
} else if (maybePromiseLike instanceof Kareem.overwriteArguments) {
|
|
66
|
+
$args = maybePromiseLike.args;
|
|
128
67
|
}
|
|
68
|
+
} catch (error) {
|
|
129
69
|
if (error instanceof Kareem.skipWrappedFunction) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
done = true;
|
|
133
|
-
return callback(error);
|
|
70
|
+
skipWrappedFunction = error;
|
|
71
|
+
continue;
|
|
134
72
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
if (asyncPresLeft > 0) {
|
|
139
|
-
// Leave parallel hooks to run
|
|
140
|
-
return;
|
|
141
|
-
} else {
|
|
142
|
-
return callback(shouldSkipWrappedFunction);
|
|
73
|
+
if (error instanceof Kareem.overwriteArguments) {
|
|
74
|
+
$args = error.args;
|
|
75
|
+
continue;
|
|
143
76
|
}
|
|
77
|
+
throw error;
|
|
144
78
|
}
|
|
79
|
+
}
|
|
145
80
|
|
|
146
|
-
|
|
81
|
+
if (skipWrappedFunction) {
|
|
82
|
+
throw skipWrappedFunction;
|
|
147
83
|
}
|
|
84
|
+
|
|
85
|
+
return $args;
|
|
148
86
|
};
|
|
149
87
|
|
|
150
88
|
/**
|
|
@@ -152,34 +90,44 @@ Kareem.prototype.execPre = function(name, context, args, callback) {
|
|
|
152
90
|
* @param {String} name The hook name to execute
|
|
153
91
|
* @param {*} context Overwrite the "this" for the hook
|
|
154
92
|
* @param {Array} [args] Apply custom arguments to the hook
|
|
155
|
-
* @
|
|
93
|
+
* @param {Object} [options] Optional options
|
|
94
|
+
* @param {Function} [options.filter] Filter function to select which hooks to run
|
|
95
|
+
* @returns {Array} The potentially modified arguments
|
|
156
96
|
*/
|
|
157
|
-
Kareem.prototype.execPreSync = function(name, context, args) {
|
|
158
|
-
|
|
97
|
+
Kareem.prototype.execPreSync = function(name, context, args, options) {
|
|
98
|
+
let pres = this._pres.get(name) || [];
|
|
99
|
+
if (options?.filter) {
|
|
100
|
+
pres = pres.filter(options.filter);
|
|
101
|
+
}
|
|
159
102
|
const numPres = pres.length;
|
|
103
|
+
let $args = args || [];
|
|
160
104
|
|
|
161
105
|
for (let i = 0; i < numPres; ++i) {
|
|
162
|
-
pres[i].fn.apply(context, args
|
|
106
|
+
const result = pres[i].fn.apply(context, $args);
|
|
107
|
+
if (result instanceof Kareem.overwriteArguments) {
|
|
108
|
+
$args = result.args;
|
|
109
|
+
}
|
|
163
110
|
}
|
|
111
|
+
|
|
112
|
+
return $args;
|
|
164
113
|
};
|
|
165
114
|
|
|
166
115
|
/**
|
|
167
116
|
* Execute all "post" hooks for "name"
|
|
168
117
|
* @param {String} name The hook name to execute
|
|
169
118
|
* @param {*} context Overwrite the "this" for the hook
|
|
170
|
-
* @param {Array
|
|
171
|
-
* @param {
|
|
172
|
-
* @param {
|
|
119
|
+
* @param {Array} args Apply custom arguments to the hook
|
|
120
|
+
* @param {Object} [options] Optional options
|
|
121
|
+
* @param {Error} [options.error] Error to pass to error-handling middleware
|
|
122
|
+
* @param {Function} [options.filter] Filter function to select which hooks to run
|
|
173
123
|
* @returns {void}
|
|
174
124
|
*/
|
|
175
|
-
Kareem.prototype.execPost = function(name, context, args, options
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
125
|
+
Kareem.prototype.execPost = async function execPost(name, context, args, options) {
|
|
126
|
+
let posts = this._posts.get(name) || [];
|
|
127
|
+
if (options?.filter) {
|
|
128
|
+
posts = posts.filter(options.filter);
|
|
179
129
|
}
|
|
180
|
-
const posts = this._posts.get(name) || [];
|
|
181
130
|
const numPosts = posts.length;
|
|
182
|
-
let currentPost = 0;
|
|
183
131
|
|
|
184
132
|
let firstError = null;
|
|
185
133
|
if (options && options.error) {
|
|
@@ -187,124 +135,140 @@ Kareem.prototype.execPost = function(name, context, args, options, callback) {
|
|
|
187
135
|
}
|
|
188
136
|
|
|
189
137
|
if (!numPosts) {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
}
|
|
138
|
+
if (firstError != null) {
|
|
139
|
+
throw firstError;
|
|
140
|
+
}
|
|
141
|
+
return args;
|
|
193
142
|
}
|
|
194
143
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
newArgs.push(args[i]);
|
|
204
|
-
}
|
|
144
|
+
let cbPromise = null;
|
|
145
|
+
let resolve;
|
|
146
|
+
let reject;
|
|
147
|
+
const nextCallback = function nextCallback(err) {
|
|
148
|
+
if (err) {
|
|
149
|
+
reject(err);
|
|
150
|
+
} else {
|
|
151
|
+
resolve();
|
|
205
152
|
}
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
let newArgs = args.slice();
|
|
156
|
+
_handleNumCallbackParams(newArgs, options?.numCallbackParams);
|
|
157
|
+
let numArgs = newArgs.length;
|
|
158
|
+
newArgs.push(nextCallback);
|
|
159
|
+
let errorArgs = options?.error ? [firstError, ...newArgs] : null;
|
|
160
|
+
|
|
161
|
+
for (const currentPost of posts) {
|
|
162
|
+
const post = currentPost.fn;
|
|
163
|
+
|
|
164
|
+
cbPromise = new Promise((_resolve, _reject) => {
|
|
165
|
+
resolve = _resolve;
|
|
166
|
+
reject = _reject;
|
|
167
|
+
});
|
|
206
168
|
|
|
207
169
|
if (firstError) {
|
|
208
|
-
if (isErrorHandlingMiddleware(
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
return next();
|
|
217
|
-
}
|
|
218
|
-
firstError = error;
|
|
170
|
+
if (isErrorHandlingMiddleware(currentPost, numArgs)) {
|
|
171
|
+
try {
|
|
172
|
+
const res = post.apply(context, errorArgs);
|
|
173
|
+
if (isPromiseLike(res)) {
|
|
174
|
+
await res;
|
|
175
|
+
} else if (post.length === numArgs + 2) {
|
|
176
|
+
// `numArgs + 2` because we added the error and the callback
|
|
177
|
+
await cbPromise;
|
|
219
178
|
}
|
|
220
|
-
|
|
221
|
-
|
|
179
|
+
} catch (error) {
|
|
180
|
+
if (error instanceof Kareem.overwriteResult) {
|
|
181
|
+
args = error.args;
|
|
182
|
+
newArgs = args.slice();
|
|
183
|
+
_handleNumCallbackParams(newArgs, options?.numCallbackParams);
|
|
184
|
+
numArgs = newArgs.length;
|
|
185
|
+
newArgs.push(nextCallback);
|
|
186
|
+
continue;
|
|
222
187
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
callMiddlewareFunction(post, context,
|
|
227
|
-
[firstError].concat(newArgs).concat([_cb]), _cb);
|
|
228
|
-
} else {
|
|
229
|
-
if (++currentPost >= numPosts) {
|
|
230
|
-
return callback.call(null, firstError);
|
|
188
|
+
firstError = error;
|
|
189
|
+
errorArgs = [firstError, ...newArgs];
|
|
231
190
|
}
|
|
232
|
-
|
|
191
|
+
} else {
|
|
192
|
+
continue;
|
|
233
193
|
}
|
|
234
194
|
} else {
|
|
235
|
-
|
|
236
|
-
if
|
|
195
|
+
if (isErrorHandlingMiddleware(currentPost, numArgs)) {
|
|
196
|
+
// Skip error handlers if no error
|
|
197
|
+
continue;
|
|
198
|
+
} else {
|
|
199
|
+
let res = null;
|
|
200
|
+
try {
|
|
201
|
+
res = post.apply(context, newArgs);
|
|
202
|
+
if (isPromiseLike(res)) {
|
|
203
|
+
res = await res;
|
|
204
|
+
} else if (post.length === numArgs + 1) {
|
|
205
|
+
// If post function takes a callback, wait for the post function to call the callback
|
|
206
|
+
res = await cbPromise;
|
|
207
|
+
}
|
|
208
|
+
} catch (error) {
|
|
237
209
|
if (error instanceof Kareem.overwriteResult) {
|
|
238
210
|
args = error.args;
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
211
|
+
newArgs = args.slice();
|
|
212
|
+
_handleNumCallbackParams(newArgs, options?.numCallbackParams);
|
|
213
|
+
numArgs = newArgs.length;
|
|
214
|
+
newArgs.push(nextCallback);
|
|
215
|
+
errorArgs = [firstError, ...newArgs];
|
|
216
|
+
continue;
|
|
243
217
|
}
|
|
244
218
|
firstError = error;
|
|
245
|
-
|
|
219
|
+
errorArgs = [firstError, ...newArgs];
|
|
220
|
+
continue;
|
|
246
221
|
}
|
|
247
222
|
|
|
248
|
-
if (
|
|
249
|
-
|
|
223
|
+
if (res instanceof Kareem.overwriteResult) {
|
|
224
|
+
args = res.args;
|
|
225
|
+
newArgs = args.slice();
|
|
226
|
+
_handleNumCallbackParams(newArgs, options?.numCallbackParams);
|
|
227
|
+
numArgs = newArgs.length;
|
|
228
|
+
newArgs.push(nextCallback);
|
|
229
|
+
continue;
|
|
250
230
|
}
|
|
251
|
-
|
|
252
|
-
next();
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
if (isErrorHandlingMiddleware(posts[currentPost], numArgs)) {
|
|
256
|
-
// Skip error handlers if no error
|
|
257
|
-
if (++currentPost >= numPosts) {
|
|
258
|
-
return callback.apply(null, [null].concat(args));
|
|
259
|
-
}
|
|
260
|
-
return next();
|
|
261
231
|
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
} else {
|
|
265
|
-
let error;
|
|
266
|
-
let maybePromiseLike;
|
|
267
|
-
try {
|
|
268
|
-
maybePromiseLike = post.apply(context, newArgs);
|
|
269
|
-
} catch (err) {
|
|
270
|
-
error = err;
|
|
271
|
-
firstError = err;
|
|
272
|
-
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
273
234
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
_cb(res instanceof Kareem.overwriteResult ? res : null);
|
|
278
|
-
},
|
|
279
|
-
err => _cb(err)
|
|
280
|
-
);
|
|
281
|
-
}
|
|
235
|
+
if (firstError != null) {
|
|
236
|
+
throw firstError;
|
|
237
|
+
}
|
|
282
238
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
}
|
|
239
|
+
return args;
|
|
240
|
+
};
|
|
286
241
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
242
|
+
/*!
|
|
243
|
+
* Handle the `numCallbackParams` option for `execPostSync`: fill `newArgs` with `null` until
|
|
244
|
+
* length is `numCallbackParams` if `numCallbackParams` is a number.
|
|
245
|
+
*
|
|
246
|
+
* @param {Array} newArgs The arguments to fill
|
|
247
|
+
* @param {number|null|undefined} numCallbackParams The number of callback parameters
|
|
248
|
+
*/
|
|
290
249
|
|
|
291
|
-
|
|
292
|
-
|
|
250
|
+
function _handleNumCallbackParams(newArgs, numCallbackParams) {
|
|
251
|
+
if (typeof numCallbackParams === 'number' && numCallbackParams > newArgs.length) {
|
|
252
|
+
for (let i = newArgs.length; i < numCallbackParams; ++i) {
|
|
253
|
+
newArgs.push(null);
|
|
293
254
|
}
|
|
294
255
|
}
|
|
295
|
-
|
|
296
|
-
next();
|
|
297
|
-
};
|
|
256
|
+
}
|
|
298
257
|
|
|
299
258
|
/**
|
|
300
259
|
* Execute all "post" hooks for "name" synchronously
|
|
301
260
|
* @param {String} name The hook name to execute
|
|
302
261
|
* @param {*} context Overwrite the "this" for the hook
|
|
303
|
-
* @param {Array
|
|
262
|
+
* @param {Array} args Apply custom arguments to the hook
|
|
263
|
+
* @param {Object} [options] Optional options
|
|
264
|
+
* @param {Function} [options.filter] Filter function to select which hooks to run
|
|
304
265
|
* @returns {Array} The used arguments
|
|
305
266
|
*/
|
|
306
|
-
Kareem.prototype.execPostSync = function(name, context, args) {
|
|
307
|
-
|
|
267
|
+
Kareem.prototype.execPostSync = function(name, context, args, options) {
|
|
268
|
+
let posts = this._posts.get(name) || [];
|
|
269
|
+
if (options?.filter) {
|
|
270
|
+
posts = posts.filter(options.filter);
|
|
271
|
+
}
|
|
308
272
|
const numPosts = posts.length;
|
|
309
273
|
|
|
310
274
|
for (let i = 0; i < numPosts; ++i) {
|
|
@@ -321,113 +285,62 @@ Kareem.prototype.execPostSync = function(name, context, args) {
|
|
|
321
285
|
* Create a synchronous wrapper for "fn"
|
|
322
286
|
* @param {String} name The name of the hook
|
|
323
287
|
* @param {Function} fn The function to wrap
|
|
288
|
+
* @param {*} context Overwrite the "this" for the hook. If null/undefined, uses the calling context.
|
|
289
|
+
* @param {Object} [options] Options for the wrapper
|
|
290
|
+
* @param {Function} [options.getOptions] Function that receives the wrapper arguments and returns options for execPreSync/execPostSync. Can return `{ filter }` for both, or `{ pre: { filter }, post: { filter } }` for separate options.
|
|
324
291
|
* @returns {Function} The wrapped function
|
|
325
292
|
*/
|
|
326
|
-
Kareem.prototype.createWrapperSync = function(name, fn) {
|
|
293
|
+
Kareem.prototype.createWrapperSync = function(name, fn, context, options) {
|
|
327
294
|
const _this = this;
|
|
295
|
+
const getOptions = options?.getOptions;
|
|
328
296
|
return function syncWrapper() {
|
|
329
|
-
|
|
297
|
+
const _context = context ?? this;
|
|
298
|
+
const args = Array.from(arguments);
|
|
299
|
+
const execOptions = typeof getOptions === 'function' ? getOptions(args) : {};
|
|
300
|
+
const preOptions = execOptions.pre ?? execOptions;
|
|
301
|
+
const postOptions = execOptions.post ?? execOptions;
|
|
302
|
+
|
|
303
|
+
const modifiedArgs = _this.execPreSync(name, _context, args, preOptions);
|
|
330
304
|
|
|
331
|
-
const toReturn = fn.apply(
|
|
305
|
+
const toReturn = fn.apply(_context, modifiedArgs);
|
|
332
306
|
|
|
333
|
-
const result = _this.execPostSync(name,
|
|
307
|
+
const result = _this.execPostSync(name, _context, [toReturn], postOptions);
|
|
334
308
|
|
|
335
309
|
return result[0];
|
|
336
310
|
};
|
|
337
311
|
};
|
|
338
312
|
|
|
339
|
-
function _handleWrapError(instance, error, name, context, args, options, callback) {
|
|
340
|
-
if (options.useErrorHandlers) {
|
|
341
|
-
return instance.execPost(name, context, args, { error: error }, function(error) {
|
|
342
|
-
return typeof callback === 'function' && callback(error);
|
|
343
|
-
});
|
|
344
|
-
} else {
|
|
345
|
-
return typeof callback === 'function' && callback(error);
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
|
|
349
313
|
/**
|
|
350
314
|
* Executes pre hooks, followed by the wrapped function, followed by post hooks.
|
|
351
315
|
* @param {String} name The name of the hook
|
|
352
316
|
* @param {Function} fn The function for the hook
|
|
353
317
|
* @param {*} context Overwrite the "this" for the hook
|
|
354
318
|
* @param {Array} args Apply custom arguments to the hook
|
|
355
|
-
* @param {Object}
|
|
356
|
-
* @param {Boolean} [options.checkForPromise]
|
|
319
|
+
* @param {Object} options Additional options for the hook
|
|
357
320
|
* @returns {void}
|
|
358
321
|
*/
|
|
359
|
-
Kareem.prototype.wrap = function(name, fn, context, args, options) {
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
const checkForPromise = options.checkForPromise;
|
|
367
|
-
|
|
368
|
-
this.execPre(name, context, args, function(error) {
|
|
369
|
-
if (error && !(error instanceof Kareem.skipWrappedFunction)) {
|
|
370
|
-
const numCallbackParams = options.numCallbackParams || 0;
|
|
371
|
-
const errorArgs = options.contextParameter ? [context] : [];
|
|
372
|
-
for (let i = errorArgs.length; i < numCallbackParams; ++i) {
|
|
373
|
-
errorArgs.push(null);
|
|
374
|
-
}
|
|
375
|
-
return _handleWrapError(_this, error, name, context, errorArgs,
|
|
376
|
-
options, lastArg);
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
const numParameters = fn.length;
|
|
380
|
-
let ret;
|
|
381
|
-
|
|
322
|
+
Kareem.prototype.wrap = async function wrap(name, fn, context, args, options) {
|
|
323
|
+
let ret;
|
|
324
|
+
let skipWrappedFunction = false;
|
|
325
|
+
let modifiedArgs = args;
|
|
326
|
+
try {
|
|
327
|
+
modifiedArgs = await this.execPre(name, context, args);
|
|
328
|
+
} catch (error) {
|
|
382
329
|
if (error instanceof Kareem.skipWrappedFunction) {
|
|
383
|
-
ret = error.args
|
|
384
|
-
|
|
330
|
+
ret = error.args;
|
|
331
|
+
skipWrappedFunction = true;
|
|
385
332
|
} else {
|
|
386
|
-
|
|
387
|
-
ret = fn.apply(context, argsWithoutCb.concat(_cb));
|
|
388
|
-
} catch (err) {
|
|
389
|
-
return _cb(err);
|
|
390
|
-
}
|
|
333
|
+
await this.execPost(name, context, args, { ...options, error });
|
|
391
334
|
}
|
|
335
|
+
}
|
|
392
336
|
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
return ret.then(
|
|
397
|
-
res => _cb(null, res),
|
|
398
|
-
err => _cb(err)
|
|
399
|
-
);
|
|
400
|
-
}
|
|
337
|
+
if (!skipWrappedFunction) {
|
|
338
|
+
ret = await fn.apply(context, modifiedArgs);
|
|
339
|
+
}
|
|
401
340
|
|
|
402
|
-
|
|
403
|
-
// promise, assume it is sync
|
|
404
|
-
if (numParameters < argsWithoutCb.length + 1) {
|
|
405
|
-
return _cb(null, ret);
|
|
406
|
-
}
|
|
407
|
-
}
|
|
341
|
+
ret = await this.execPost(name, context, [ret], options);
|
|
408
342
|
|
|
409
|
-
|
|
410
|
-
const argsWithoutError = Array.from(arguments);
|
|
411
|
-
argsWithoutError.shift();
|
|
412
|
-
if (options.nullResultByDefault && argsWithoutError.length === 0) {
|
|
413
|
-
argsWithoutError.push(null);
|
|
414
|
-
}
|
|
415
|
-
if (arguments[0]) {
|
|
416
|
-
// Assume error
|
|
417
|
-
return _handleWrapError(_this, arguments[0], name, context,
|
|
418
|
-
argsWithoutError, options, lastArg);
|
|
419
|
-
} else {
|
|
420
|
-
_this.execPost(name, context, argsWithoutError, function() {
|
|
421
|
-
if (lastArg === null) {
|
|
422
|
-
return;
|
|
423
|
-
}
|
|
424
|
-
arguments[0]
|
|
425
|
-
? lastArg(arguments[0])
|
|
426
|
-
: lastArg.apply(context, arguments);
|
|
427
|
-
});
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
});
|
|
343
|
+
return ret[0];
|
|
431
344
|
};
|
|
432
345
|
|
|
433
346
|
/**
|
|
@@ -449,8 +362,6 @@ Kareem.prototype.filter = function(fn) {
|
|
|
449
362
|
continue;
|
|
450
363
|
}
|
|
451
364
|
|
|
452
|
-
hooks.numAsync = hooks.filter(h => h.isAsync).length;
|
|
453
|
-
|
|
454
365
|
clone._pres.set(name, hooks);
|
|
455
366
|
}
|
|
456
367
|
|
|
@@ -491,53 +402,43 @@ Kareem.prototype.hasHooks = function(name) {
|
|
|
491
402
|
Kareem.prototype.createWrapper = function(name, fn, context, options) {
|
|
492
403
|
const _this = this;
|
|
493
404
|
if (!this.hasHooks(name)) {
|
|
494
|
-
// Fast path: if there's no hooks for this function, just return the
|
|
495
|
-
|
|
496
|
-
return function() {
|
|
497
|
-
nextTick(() => fn.apply(this, arguments));
|
|
498
|
-
};
|
|
405
|
+
// Fast path: if there's no hooks for this function, just return the function
|
|
406
|
+
return fn;
|
|
499
407
|
}
|
|
500
|
-
return function() {
|
|
408
|
+
return function kareemWrappedFunction() {
|
|
501
409
|
const _context = context || this;
|
|
502
|
-
_this.wrap(name, fn, _context, Array.from(arguments), options);
|
|
410
|
+
return _this.wrap(name, fn, _context, Array.from(arguments), options);
|
|
503
411
|
};
|
|
504
412
|
};
|
|
505
413
|
|
|
506
414
|
/**
|
|
507
415
|
* Register a new hook for "pre"
|
|
508
416
|
* @param {String} name The name of the hook
|
|
509
|
-
* @param {
|
|
417
|
+
* @param {Object} [options]
|
|
510
418
|
* @param {Function} fn The function to register for "name"
|
|
511
419
|
* @param {never} error Unused
|
|
512
420
|
* @param {Boolean} [unshift] Wheter to "push" or to "unshift" the new hook
|
|
513
421
|
* @returns {Kareem}
|
|
514
422
|
*/
|
|
515
|
-
Kareem.prototype.pre = function(name,
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
options =
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
fn = isAsync;
|
|
522
|
-
isAsync = false;
|
|
423
|
+
Kareem.prototype.pre = function(name, options, fn, error, unshift) {
|
|
424
|
+
if (typeof options === 'function') {
|
|
425
|
+
fn = options;
|
|
426
|
+
options = {};
|
|
427
|
+
} else if (options == null) {
|
|
428
|
+
options = {};
|
|
523
429
|
}
|
|
524
430
|
|
|
525
431
|
const pres = this._pres.get(name) || [];
|
|
526
432
|
this._pres.set(name, pres);
|
|
527
433
|
|
|
528
|
-
if (isAsync) {
|
|
529
|
-
pres.numAsync = pres.numAsync || 0;
|
|
530
|
-
++pres.numAsync;
|
|
531
|
-
}
|
|
532
|
-
|
|
533
434
|
if (typeof fn !== 'function') {
|
|
534
435
|
throw new Error('pre() requires a function, got "' + typeof fn + '"');
|
|
535
436
|
}
|
|
536
437
|
|
|
537
438
|
if (unshift) {
|
|
538
|
-
pres.unshift(Object.assign({}, options, { fn: fn
|
|
439
|
+
pres.unshift(Object.assign({}, options, { fn: fn }));
|
|
539
440
|
} else {
|
|
540
|
-
pres.push(Object.assign({}, options, { fn: fn
|
|
441
|
+
pres.push(Object.assign({}, options, { fn: fn }));
|
|
541
442
|
}
|
|
542
443
|
|
|
543
444
|
return this;
|
|
@@ -547,6 +448,7 @@ Kareem.prototype.pre = function(name, isAsync, fn, error, unshift) {
|
|
|
547
448
|
* Register a new hook for "post"
|
|
548
449
|
* @param {String} name The name of the hook
|
|
549
450
|
* @param {Object} [options]
|
|
451
|
+
* @param {Boolean} [options.errorHandler] Whether this is an error handler
|
|
550
452
|
* @param {Function} fn The function to register for "name"
|
|
551
453
|
* @param {Boolean} [unshift] Wheter to "push" or to "unshift" the new hook
|
|
552
454
|
* @returns {Kareem}
|
|
@@ -573,6 +475,24 @@ Kareem.prototype.post = function(name, options, fn, unshift) {
|
|
|
573
475
|
return this;
|
|
574
476
|
};
|
|
575
477
|
|
|
478
|
+
/**
|
|
479
|
+
* Register a new error handler for "name"
|
|
480
|
+
* @param {String} name The name of the hook
|
|
481
|
+
* @param {Object} [options]
|
|
482
|
+
* @param {Function} fn The function to register for "name"
|
|
483
|
+
* @param {Boolean} [unshift] Wheter to "push" or to "unshift" the new hook
|
|
484
|
+
* @returns {Kareem}
|
|
485
|
+
*/
|
|
486
|
+
|
|
487
|
+
Kareem.prototype.postError = function postError(name, options, fn, unshift) {
|
|
488
|
+
if (typeof options === 'function') {
|
|
489
|
+
unshift = !!fn;
|
|
490
|
+
fn = options;
|
|
491
|
+
options = {};
|
|
492
|
+
}
|
|
493
|
+
return this.post(name, { ...options, errorHandler: true }, fn, unshift);
|
|
494
|
+
};
|
|
495
|
+
|
|
576
496
|
/**
|
|
577
497
|
* Clone the current instance
|
|
578
498
|
* @returns {Kareem} The cloned instance
|
|
@@ -582,7 +502,6 @@ Kareem.prototype.clone = function() {
|
|
|
582
502
|
|
|
583
503
|
for (const key of this._pres.keys()) {
|
|
584
504
|
const clone = this._pres.get(key).slice();
|
|
585
|
-
clone.numAsync = this._pres.get(key).numAsync;
|
|
586
505
|
n._pres.set(key, clone);
|
|
587
506
|
}
|
|
588
507
|
for (const key of this._posts.keys()) {
|
|
@@ -608,8 +527,6 @@ Kareem.prototype.merge = function(other, clone) {
|
|
|
608
527
|
// Deduplicate based on `fn`
|
|
609
528
|
filter(p => sourcePres.map(_p => _p.fn).indexOf(p.fn) === -1);
|
|
610
529
|
const combined = sourcePres.concat(deduplicated);
|
|
611
|
-
combined.numAsync = sourcePres.numAsync || 0;
|
|
612
|
-
combined.numAsync += deduplicated.filter(p => p.isAsync).length;
|
|
613
530
|
ret._pres.set(key, combined);
|
|
614
531
|
}
|
|
615
532
|
for (const key of other._posts.keys()) {
|
|
@@ -622,42 +539,10 @@ Kareem.prototype.merge = function(other, clone) {
|
|
|
622
539
|
return ret;
|
|
623
540
|
};
|
|
624
541
|
|
|
625
|
-
function callMiddlewareFunction(fn, context, args, next) {
|
|
626
|
-
let maybePromiseLike;
|
|
627
|
-
try {
|
|
628
|
-
maybePromiseLike = fn.apply(context, args);
|
|
629
|
-
} catch (error) {
|
|
630
|
-
return next(error);
|
|
631
|
-
}
|
|
632
|
-
|
|
633
|
-
if (isPromiseLike(maybePromiseLike)) {
|
|
634
|
-
maybePromiseLike.then(() => next(), err => next(err));
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
|
|
638
542
|
function isPromiseLike(v) {
|
|
639
543
|
return (typeof v === 'object' && v !== null && typeof v.then === 'function');
|
|
640
544
|
}
|
|
641
545
|
|
|
642
|
-
function decorateNextFn(fn) {
|
|
643
|
-
let called = false;
|
|
644
|
-
const _this = this;
|
|
645
|
-
return function() {
|
|
646
|
-
// Ensure this function can only be called once
|
|
647
|
-
if (called) {
|
|
648
|
-
return;
|
|
649
|
-
}
|
|
650
|
-
called = true;
|
|
651
|
-
// Make sure to clear the stack so try/catch doesn't catch errors
|
|
652
|
-
// in subsequent middleware
|
|
653
|
-
return nextTick(() => fn.apply(_this, arguments));
|
|
654
|
-
};
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
const nextTick = typeof process === 'object' && process !== null && process.nextTick || function nextTick(cb) {
|
|
658
|
-
setTimeout(cb, 0);
|
|
659
|
-
};
|
|
660
|
-
|
|
661
546
|
function isErrorHandlingMiddleware(post, numArgs) {
|
|
662
547
|
if (post.errorHandler) {
|
|
663
548
|
return true;
|