@autofleet/sadot 1.6.18-beta.5 → 1.6.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/decorate.cjs +1 -11
- package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/decorate.js +1 -10
- package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/decorateMetadata.cjs +1 -8
- package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/decorateMetadata.js +1 -7
- package/dist/_virtual/rolldown_runtime.cjs +1 -45
- package/dist/_virtual/rolldown_runtime.js +1 -22
- package/dist/api/index.cjs +2 -0
- package/dist/api/index.cjs.map +1 -0
- package/dist/api/index.js +2 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/v1/definition/index.cjs +2 -0
- package/dist/api/v1/definition/index.cjs.map +1 -0
- package/dist/api/v1/definition/index.js +2 -0
- package/dist/api/v1/definition/index.js.map +1 -0
- package/dist/api/v1/definition/validations.cjs +2 -0
- package/dist/api/v1/definition/validations.cjs.map +1 -0
- package/dist/api/v1/definition/validations.js +2 -0
- package/dist/api/v1/definition/validations.js.map +1 -0
- package/dist/api/v1/errors.cjs +2 -0
- package/dist/api/v1/errors.cjs.map +1 -0
- package/dist/api/v1/errors.js +2 -0
- package/dist/api/v1/errors.js.map +1 -0
- package/dist/api/v1/index.cjs +2 -0
- package/dist/api/v1/index.cjs.map +1 -0
- package/dist/api/v1/index.js +2 -0
- package/dist/api/v1/index.js.map +1 -0
- package/dist/api/v1/validator/index.cjs +2 -0
- package/dist/api/v1/validator/index.cjs.map +1 -0
- package/dist/api/v1/validator/index.js +2 -0
- package/dist/api/v1/validator/index.js.map +1 -0
- package/dist/api/v1/validator/validations.cjs +2 -0
- package/dist/api/v1/validator/validations.cjs.map +1 -0
- package/dist/api/v1/validator/validations.d.cts +2 -1
- package/dist/{packages/sadot/src/api → api}/v1/validator/validations.d.ts +2 -1
- package/dist/api/v1/validator/validations.js +2 -0
- package/dist/api/v1/validator/validations.js.map +1 -0
- package/dist/errors/index.cjs +3 -0
- package/dist/errors/index.cjs.map +1 -0
- package/dist/errors/index.js +3 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/events/index.cjs +2 -0
- package/dist/events/index.cjs.map +1 -0
- package/dist/events/index.js +2 -0
- package/dist/events/index.js.map +1 -0
- package/dist/hooks/enrich.cjs +2 -0
- package/dist/hooks/enrich.cjs.map +1 -0
- package/dist/hooks/enrich.js +2 -0
- package/dist/hooks/enrich.js.map +1 -0
- package/dist/hooks/find.cjs +2 -0
- package/dist/hooks/find.cjs.map +1 -0
- package/dist/hooks/find.js +2 -0
- package/dist/hooks/find.js.map +1 -0
- package/dist/hooks/hooks.cjs +2 -0
- package/dist/hooks/hooks.cjs.map +1 -0
- package/dist/hooks/hooks.js +2 -0
- package/dist/hooks/hooks.js.map +1 -0
- package/dist/hooks/index.cjs +1 -0
- package/dist/hooks/index.js +1 -0
- package/dist/hooks/utils/updateInstanceValues.cjs +2 -0
- package/dist/hooks/utils/updateInstanceValues.cjs.map +1 -0
- package/dist/hooks/utils/updateInstanceValues.js +2 -0
- package/dist/hooks/utils/updateInstanceValues.js.map +1 -0
- package/dist/index.cjs +2 -87
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +13 -14
- package/dist/index.js +2 -66
- package/dist/index.js.map +1 -0
- package/dist/init-state.cjs +2 -0
- package/dist/init-state.cjs.map +1 -0
- package/dist/init-state.d.cts +2 -1
- package/dist/{packages/sadot/src/init-state.d.ts → init-state.d.ts} +2 -1
- package/dist/init-state.js +2 -0
- package/dist/init-state.js.map +1 -0
- package/dist/mat-path-state.cjs +2 -0
- package/dist/mat-path-state.cjs.map +1 -0
- package/dist/mat-path-state.js +2 -0
- package/dist/mat-path-state.js.map +1 -0
- package/dist/{packages/sadot/src/migrations → migrations}/001-create-core-tables.cjs +7 -25
- package/dist/migrations/001-create-core-tables.cjs.map +1 -0
- package/dist/{packages/sadot/src/migrations → migrations}/001-create-core-tables.js +7 -23
- package/dist/migrations/001-create-core-tables.js.map +1 -0
- package/dist/{packages/sadot/src/migrations → migrations}/002-create-custom-field-entries.cjs +4 -16
- package/dist/migrations/002-create-custom-field-entries.cjs.map +1 -0
- package/dist/{packages/sadot/src/migrations → migrations}/002-create-custom-field-entries.js +4 -14
- package/dist/migrations/002-create-custom-field-entries.js.map +1 -0
- package/dist/{packages/sadot/src/migrations → migrations}/003-create-custom-field-model-type-map.cjs +6 -20
- package/dist/migrations/003-create-custom-field-model-type-map.cjs.map +1 -0
- package/dist/{packages/sadot/src/migrations → migrations}/003-create-custom-field-model-type-map.js +6 -18
- package/dist/migrations/003-create-custom-field-model-type-map.js.map +1 -0
- package/dist/migrations/index.cjs +2 -0
- package/dist/migrations/index.cjs.map +1 -0
- package/dist/migrations/index.js +2 -0
- package/dist/migrations/index.js.map +1 -0
- package/dist/models/CustomFieldDefinition.cjs +2 -0
- package/dist/models/CustomFieldDefinition.cjs.map +1 -0
- package/dist/models/CustomFieldDefinition.d.cts +2 -1
- package/dist/{packages/sadot/src/models → models}/CustomFieldDefinition.d.ts +2 -1
- package/dist/models/CustomFieldDefinition.js +2 -0
- package/dist/models/CustomFieldDefinition.js.map +1 -0
- package/dist/models/CustomFieldEntries.cjs +2 -0
- package/dist/models/CustomFieldEntries.cjs.map +1 -0
- package/dist/models/CustomFieldEntries.d.cts +2 -1
- package/dist/{packages/sadot/src/models → models}/CustomFieldEntries.d.ts +2 -1
- package/dist/models/CustomFieldEntries.js +2 -0
- package/dist/models/CustomFieldEntries.js.map +1 -0
- package/dist/models/CustomFieldModelTypeMap.cjs +2 -0
- package/dist/models/CustomFieldModelTypeMap.cjs.map +1 -0
- package/dist/models/CustomFieldModelTypeMap.d.cts +2 -1
- package/dist/{packages/sadot/src/models → models}/CustomFieldModelTypeMap.d.ts +2 -1
- package/dist/models/CustomFieldModelTypeMap.js +2 -0
- package/dist/models/CustomFieldModelTypeMap.js.map +1 -0
- package/dist/models/CustomFieldValue.cjs +2 -0
- package/dist/models/CustomFieldValue.cjs.map +1 -0
- package/dist/models/CustomFieldValue.d.cts +2 -1
- package/dist/{packages/sadot/src/models → models}/CustomFieldValue.d.ts +2 -1
- package/dist/models/CustomFieldValue.js +2 -0
- package/dist/models/CustomFieldValue.js.map +1 -0
- package/dist/models/CustomValidator.cjs +2 -0
- package/dist/models/CustomValidator.cjs.map +1 -0
- package/dist/models/CustomValidator.d.cts +2 -1
- package/dist/{packages/sadot/src/models → models}/CustomValidator.d.ts +2 -1
- package/dist/models/CustomValidator.js +2 -0
- package/dist/models/CustomValidator.js.map +1 -0
- package/dist/models/index.cjs +2 -0
- package/dist/models/index.cjs.map +1 -0
- package/dist/models/index.d.cts +7 -0
- package/dist/models/index.js +2 -0
- package/dist/models/index.js.map +1 -0
- package/dist/models/tests/AssociatedTestModel.cjs +2 -0
- package/dist/models/tests/AssociatedTestModel.cjs.map +1 -0
- package/dist/models/tests/AssociatedTestModel.js +2 -0
- package/dist/models/tests/AssociatedTestModel.js.map +1 -0
- package/dist/models/tests/TestModel.cjs +2 -0
- package/dist/models/tests/TestModel.cjs.map +1 -0
- package/dist/models/tests/TestModel.js +2 -0
- package/dist/models/tests/TestModel.js.map +1 -0
- package/dist/models/tests/contextAwareModels/ContextAwareTestModel.cjs +2 -0
- package/dist/models/tests/contextAwareModels/ContextAwareTestModel.cjs.map +1 -0
- package/dist/models/tests/contextAwareModels/ContextAwareTestModel.js +2 -0
- package/dist/models/tests/contextAwareModels/ContextAwareTestModel.js.map +1 -0
- package/dist/models/tests/contextAwareModels/ContextTestModel.cjs +2 -0
- package/dist/models/tests/contextAwareModels/ContextTestModel.cjs.map +1 -0
- package/dist/models/tests/contextAwareModels/ContextTestModel.js +2 -0
- package/dist/models/tests/contextAwareModels/ContextTestModel.js.map +1 -0
- package/dist/repository/definition.cjs +2 -0
- package/dist/repository/definition.cjs.map +1 -0
- package/dist/repository/definition.js +2 -0
- package/dist/repository/definition.js.map +1 -0
- package/dist/repository/entries.cjs +2 -0
- package/dist/repository/entries.cjs.map +1 -0
- package/dist/repository/entries.js +2 -0
- package/dist/repository/entries.js.map +1 -0
- package/dist/repository/utils/formatValues.cjs +2 -0
- package/dist/repository/utils/formatValues.cjs.map +1 -0
- package/dist/repository/utils/formatValues.js +2 -0
- package/dist/repository/utils/formatValues.js.map +1 -0
- package/dist/repository/validator.cjs +2 -0
- package/dist/repository/validator.cjs.map +1 -0
- package/dist/repository/validator.js +2 -0
- package/dist/repository/validator.js.map +1 -0
- package/dist/repository/value.cjs +2 -0
- package/dist/repository/value.cjs.map +1 -0
- package/dist/repository/value.js +2 -0
- package/dist/repository/value.js.map +1 -0
- package/dist/scopes/filter.cjs +2 -0
- package/dist/scopes/filter.cjs.map +1 -0
- package/dist/scopes/filter.d.cts +2 -1
- package/dist/{packages/sadot/src/scopes → scopes}/filter.d.ts +2 -1
- package/dist/scopes/filter.js +2 -0
- package/dist/scopes/filter.js.map +1 -0
- package/dist/scopes/helpers/filter.helpers.cjs +46 -0
- package/dist/scopes/helpers/filter.helpers.cjs.map +1 -0
- package/dist/scopes/helpers/filter.helpers.d.cts +2 -1
- package/dist/{packages/sadot/src/scopes → scopes}/helpers/filter.helpers.d.ts +2 -1
- package/dist/scopes/helpers/filter.helpers.js +46 -0
- package/dist/scopes/helpers/filter.helpers.js.map +1 -0
- package/dist/scopes/index.cjs +1 -0
- package/dist/scopes/index.js +1 -0
- package/dist/types/index.d.cts +4 -2
- package/dist/{packages/sadot/src/types → types}/index.d.ts +4 -2
- package/dist/utils/constants/index.cjs +2 -0
- package/dist/utils/constants/index.cjs.map +1 -0
- package/dist/utils/constants/index.d.cts +2 -1
- package/dist/{packages/sadot/src/utils → utils}/constants/index.d.ts +2 -1
- package/dist/utils/constants/index.js +2 -0
- package/dist/utils/constants/index.js.map +1 -0
- package/dist/utils/db/index.cjs +2 -0
- package/dist/utils/db/index.cjs.map +1 -0
- package/dist/utils/db/index.js +2 -0
- package/dist/utils/db/index.js.map +1 -0
- package/dist/utils/helpers/index.cjs +2 -0
- package/dist/utils/helpers/index.cjs.map +1 -0
- package/dist/utils/helpers/index.d.cts +2 -1
- package/dist/{packages/sadot/src/utils → utils}/helpers/index.d.ts +2 -1
- package/dist/utils/helpers/index.js +2 -0
- package/dist/utils/helpers/index.js.map +1 -0
- package/dist/utils/init.cjs +2 -0
- package/dist/utils/init.cjs.map +1 -0
- package/dist/utils/init.js +2 -0
- package/dist/utils/init.js.map +1 -0
- package/dist/utils/logger/index.cjs +2 -0
- package/dist/utils/logger/index.cjs.map +1 -0
- package/dist/utils/logger/index.js +2 -0
- package/dist/utils/logger/index.js.map +1 -0
- package/dist/utils/scopeAttributes.cjs +2 -0
- package/dist/utils/scopeAttributes.cjs.map +1 -0
- package/dist/utils/scopeAttributes.js +2 -0
- package/dist/utils/scopeAttributes.js.map +1 -0
- package/dist/utils/validations/index.cjs +2 -0
- package/dist/utils/validations/index.cjs.map +1 -0
- package/dist/utils/validations/index.js +2 -0
- package/dist/utils/validations/index.js.map +1 -0
- package/dist/utils/validations/schema/custom-fields.cjs +2 -0
- package/dist/utils/validations/schema/custom-fields.cjs.map +1 -0
- package/dist/utils/validations/schema/custom-fields.d.cts +2 -1
- package/dist/{packages/sadot/src/utils → utils}/validations/schema/custom-fields.d.ts +2 -1
- package/dist/utils/validations/schema/custom-fields.js +2 -0
- package/dist/utils/validations/schema/custom-fields.js.map +1 -0
- package/dist/utils/validations/schema/validator-schema.cjs +2 -0
- package/dist/utils/validations/schema/validator-schema.cjs.map +1 -0
- package/dist/utils/validations/schema/validator-schema.js +2 -0
- package/dist/utils/validations/schema/validator-schema.js.map +1 -0
- package/dist/utils/validations/validators/index.cjs +2 -0
- package/dist/utils/validations/validators/index.cjs.map +1 -0
- package/dist/utils/validations/validators/index.js +2 -0
- package/dist/utils/validations/validators/index.js.map +1 -0
- package/dist/utils/validations/validators/multi-select-dropdown.validator.cjs +2 -0
- package/dist/utils/validations/validators/multi-select-dropdown.validator.cjs.map +1 -0
- package/dist/utils/validations/validators/multi-select-dropdown.validator.js +2 -0
- package/dist/utils/validations/validators/multi-select-dropdown.validator.js.map +1 -0
- package/dist/utils/validations/validators/multi-select-status.validator.cjs +2 -0
- package/dist/utils/validations/validators/multi-select-status.validator.cjs.map +1 -0
- package/dist/utils/validations/validators/multi-select-status.validator.js +2 -0
- package/dist/utils/validations/validators/multi-select-status.validator.js.map +1 -0
- package/dist/utils/validations/validators/multi-select.helpers.cjs +2 -0
- package/dist/utils/validations/validators/multi-select.helpers.cjs.map +1 -0
- package/dist/utils/validations/validators/multi-select.helpers.js +2 -0
- package/dist/utils/validations/validators/multi-select.helpers.js.map +1 -0
- package/dist/utils/validations/validators/select.validator.cjs +2 -0
- package/dist/utils/validations/validators/select.validator.cjs.map +1 -0
- package/dist/utils/validations/validators/select.validator.js +2 -0
- package/dist/utils/validations/validators/select.validator.js.map +1 -0
- package/dist/utils/validations/validators/status.validator.cjs +2 -0
- package/dist/utils/validations/validators/status.validator.cjs.map +1 -0
- package/dist/utils/validations/validators/status.validator.js +2 -0
- package/dist/utils/validations/validators/status.validator.js.map +1 -0
- package/package.json +4 -4
- package/dist/models/FieldPolicy.d.cts +0 -23
- package/dist/node_modules/accepts/index.cjs +0 -180
- package/dist/node_modules/accepts/index.js +0 -175
- package/dist/node_modules/array-flatten/array-flatten.cjs +0 -61
- package/dist/node_modules/array-flatten/array-flatten.js +0 -56
- package/dist/node_modules/body-parser/index.cjs +0 -140
- package/dist/node_modules/body-parser/index.js +0 -135
- package/dist/node_modules/body-parser/lib/read.cjs +0 -169
- package/dist/node_modules/body-parser/lib/read.js +0 -164
- package/dist/node_modules/body-parser/lib/types/json.cjs +0 -205
- package/dist/node_modules/body-parser/lib/types/json.js +0 -200
- package/dist/node_modules/body-parser/lib/types/raw.cjs +0 -90
- package/dist/node_modules/body-parser/lib/types/raw.js +0 -85
- package/dist/node_modules/body-parser/lib/types/text.cjs +0 -106
- package/dist/node_modules/body-parser/lib/types/text.js +0 -101
- package/dist/node_modules/body-parser/lib/types/urlencoded.cjs +0 -222
- package/dist/node_modules/body-parser/lib/types/urlencoded.js +0 -217
- package/dist/node_modules/body-parser/node_modules/qs/lib/formats.cjs +0 -34
- package/dist/node_modules/body-parser/node_modules/qs/lib/formats.js +0 -29
- package/dist/node_modules/body-parser/node_modules/qs/lib/index.cjs +0 -26
- package/dist/node_modules/body-parser/node_modules/qs/lib/index.js +0 -21
- package/dist/node_modules/body-parser/node_modules/qs/lib/parse.cjs +0 -187
- package/dist/node_modules/body-parser/node_modules/qs/lib/parse.js +0 -182
- package/dist/node_modules/body-parser/node_modules/qs/lib/stringify.cjs +0 -192
- package/dist/node_modules/body-parser/node_modules/qs/lib/stringify.js +0 -187
- package/dist/node_modules/body-parser/node_modules/qs/lib/utils.cjs +0 -178
- package/dist/node_modules/body-parser/node_modules/qs/lib/utils.js +0 -173
- package/dist/node_modules/bytes/index.cjs +0 -126
- package/dist/node_modules/bytes/index.js +0 -121
- package/dist/node_modules/call-bind-apply-helpers/actualApply.cjs +0 -25
- package/dist/node_modules/call-bind-apply-helpers/actualApply.js +0 -20
- package/dist/node_modules/call-bind-apply-helpers/functionApply.cjs +0 -17
- package/dist/node_modules/call-bind-apply-helpers/functionApply.js +0 -12
- package/dist/node_modules/call-bind-apply-helpers/functionCall.cjs +0 -17
- package/dist/node_modules/call-bind-apply-helpers/functionCall.js +0 -12
- package/dist/node_modules/call-bind-apply-helpers/index.cjs +0 -28
- package/dist/node_modules/call-bind-apply-helpers/index.js +0 -23
- package/dist/node_modules/call-bind-apply-helpers/reflectApply.cjs +0 -17
- package/dist/node_modules/call-bind-apply-helpers/reflectApply.js +0 -12
- package/dist/node_modules/call-bound/index.cjs +0 -27
- package/dist/node_modules/call-bound/index.js +0 -22
- package/dist/node_modules/content-disposition/index.cjs +0 -314
- package/dist/node_modules/content-disposition/index.js +0 -309
- package/dist/node_modules/content-type/index.cjs +0 -156
- package/dist/node_modules/content-type/index.js +0 -151
- package/dist/node_modules/cookie/index.cjs +0 -250
- package/dist/node_modules/cookie/index.js +0 -245
- package/dist/node_modules/cookie-signature/index.cjs +0 -51
- package/dist/node_modules/cookie-signature/index.js +0 -48
- package/dist/node_modules/debug/node_modules/has-flag/index.cjs +0 -22
- package/dist/node_modules/debug/node_modules/has-flag/index.js +0 -17
- package/dist/node_modules/debug/node_modules/supports-color/index.cjs +0 -75
- package/dist/node_modules/debug/node_modules/supports-color/index.js +0 -70
- package/dist/node_modules/debug/src/browser.cjs +0 -206
- package/dist/node_modules/debug/src/browser.js +0 -203
- package/dist/node_modules/debug/src/common.cjs +0 -212
- package/dist/node_modules/debug/src/common.js +0 -209
- package/dist/node_modules/debug/src/index.cjs +0 -21
- package/dist/node_modules/debug/src/index.js +0 -18
- package/dist/node_modules/debug/src/node.cjs +0 -218
- package/dist/node_modules/debug/src/node.js +0 -215
- package/dist/node_modules/depd/index.cjs +0 -319
- package/dist/node_modules/depd/index.js +0 -316
- package/dist/node_modules/destroy/index.cjs +0 -160
- package/dist/node_modules/destroy/index.js +0 -155
- package/dist/node_modules/dunder-proto/get.cjs +0 -32
- package/dist/node_modules/dunder-proto/get.js +0 -27
- package/dist/node_modules/ee-first/index.cjs +0 -80
- package/dist/node_modules/ee-first/index.js +0 -75
- package/dist/node_modules/encodeurl/index.cjs +0 -61
- package/dist/node_modules/encodeurl/index.js +0 -56
- package/dist/node_modules/es-define-property/index.cjs +0 -23
- package/dist/node_modules/es-define-property/index.js +0 -18
- package/dist/node_modules/es-errors/eval.cjs +0 -17
- package/dist/node_modules/es-errors/eval.js +0 -12
- package/dist/node_modules/es-errors/index.cjs +0 -17
- package/dist/node_modules/es-errors/index.js +0 -12
- package/dist/node_modules/es-errors/range.cjs +0 -17
- package/dist/node_modules/es-errors/range.js +0 -12
- package/dist/node_modules/es-errors/ref.cjs +0 -17
- package/dist/node_modules/es-errors/ref.js +0 -12
- package/dist/node_modules/es-errors/syntax.cjs +0 -17
- package/dist/node_modules/es-errors/syntax.js +0 -12
- package/dist/node_modules/es-errors/type.cjs +0 -17
- package/dist/node_modules/es-errors/type.js +0 -12
- package/dist/node_modules/es-errors/uri.cjs +0 -17
- package/dist/node_modules/es-errors/uri.js +0 -12
- package/dist/node_modules/es-object-atoms/index.cjs +0 -17
- package/dist/node_modules/es-object-atoms/index.js +0 -12
- package/dist/node_modules/escape-html/index.cjs +0 -72
- package/dist/node_modules/escape-html/index.js +0 -67
- package/dist/node_modules/etag/index.cjs +0 -87
- package/dist/node_modules/etag/index.js +0 -82
- package/dist/node_modules/express/index.cjs +0 -24
- package/dist/node_modules/express/index.js +0 -19
- package/dist/node_modules/express/lib/application.cjs +0 -508
- package/dist/node_modules/express/lib/application.js +0 -503
- package/dist/node_modules/express/lib/express.cjs +0 -119
- package/dist/node_modules/express/lib/express.js +0 -114
- package/dist/node_modules/express/lib/middleware/init.cjs +0 -49
- package/dist/node_modules/express/lib/middleware/init.js +0 -44
- package/dist/node_modules/express/lib/middleware/query.cjs +0 -52
- package/dist/node_modules/express/lib/middleware/query.js +0 -47
- package/dist/node_modules/express/lib/request.cjs +0 -427
- package/dist/node_modules/express/lib/request.js +0 -422
- package/dist/node_modules/express/lib/response.cjs +0 -872
- package/dist/node_modules/express/lib/response.js +0 -867
- package/dist/node_modules/express/lib/router/index.cjs +0 -429
- package/dist/node_modules/express/lib/router/index.js +0 -424
- package/dist/node_modules/express/lib/router/layer.cjs +0 -145
- package/dist/node_modules/express/lib/router/layer.js +0 -140
- package/dist/node_modules/express/lib/router/route.cjs +0 -163
- package/dist/node_modules/express/lib/router/route.js +0 -158
- package/dist/node_modules/express/lib/utils.cjs +0 -252
- package/dist/node_modules/express/lib/utils.js +0 -247
- package/dist/node_modules/express/lib/view.cjs +0 -140
- package/dist/node_modules/express/lib/view.js +0 -135
- package/dist/node_modules/express/node_modules/qs/lib/formats.cjs +0 -34
- package/dist/node_modules/express/node_modules/qs/lib/formats.js +0 -29
- package/dist/node_modules/express/node_modules/qs/lib/index.cjs +0 -26
- package/dist/node_modules/express/node_modules/qs/lib/index.js +0 -21
- package/dist/node_modules/express/node_modules/qs/lib/parse.cjs +0 -187
- package/dist/node_modules/express/node_modules/qs/lib/parse.js +0 -182
- package/dist/node_modules/express/node_modules/qs/lib/stringify.cjs +0 -192
- package/dist/node_modules/express/node_modules/qs/lib/stringify.js +0 -187
- package/dist/node_modules/express/node_modules/qs/lib/utils.cjs +0 -178
- package/dist/node_modules/express/node_modules/qs/lib/utils.js +0 -173
- package/dist/node_modules/finalhandler/index.cjs +0 -239
- package/dist/node_modules/finalhandler/index.js +0 -234
- package/dist/node_modules/forwarded/index.cjs +0 -72
- package/dist/node_modules/forwarded/index.js +0 -67
- package/dist/node_modules/fresh/index.cjs +0 -101
- package/dist/node_modules/fresh/index.js +0 -96
- package/dist/node_modules/function-bind/implementation.cjs +0 -63
- package/dist/node_modules/function-bind/implementation.js +0 -58
- package/dist/node_modules/function-bind/index.cjs +0 -18
- package/dist/node_modules/function-bind/index.js +0 -13
- package/dist/node_modules/get-intrinsic/index.cjs +0 -362
- package/dist/node_modules/get-intrinsic/index.js +0 -357
- package/dist/node_modules/get-proto/Object.getPrototypeOf.cjs +0 -19
- package/dist/node_modules/get-proto/Object.getPrototypeOf.js +0 -14
- package/dist/node_modules/get-proto/Reflect.getPrototypeOf.cjs +0 -17
- package/dist/node_modules/get-proto/Reflect.getPrototypeOf.js +0 -12
- package/dist/node_modules/get-proto/index.cjs +0 -30
- package/dist/node_modules/get-proto/index.js +0 -25
- package/dist/node_modules/gopd/gOPD.cjs +0 -17
- package/dist/node_modules/gopd/gOPD.js +0 -12
- package/dist/node_modules/gopd/index.cjs +0 -24
- package/dist/node_modules/gopd/index.js +0 -19
- package/dist/node_modules/has-symbols/index.cjs +0 -26
- package/dist/node_modules/has-symbols/index.js +0 -21
- package/dist/node_modules/has-symbols/shams.cjs +0 -40
- package/dist/node_modules/has-symbols/shams.js +0 -35
- package/dist/node_modules/hasown/index.cjs +0 -21
- package/dist/node_modules/hasown/index.js +0 -16
- package/dist/node_modules/http-errors/index.cjs +0 -212
- package/dist/node_modules/http-errors/index.js +0 -207
- package/dist/node_modules/iconv-lite/encodings/dbcs-codec.cjs +0 -326
- package/dist/node_modules/iconv-lite/encodings/dbcs-codec.js +0 -321
- package/dist/node_modules/iconv-lite/encodings/dbcs-data.cjs +0 -131
- package/dist/node_modules/iconv-lite/encodings/dbcs-data.js +0 -126
- package/dist/node_modules/iconv-lite/encodings/index.cjs +0 -37
- package/dist/node_modules/iconv-lite/encodings/index.js +0 -32
- package/dist/node_modules/iconv-lite/encodings/internal.cjs +0 -140
- package/dist/node_modules/iconv-lite/encodings/internal.js +0 -135
- package/dist/node_modules/iconv-lite/encodings/sbcs-codec.cjs +0 -58
- package/dist/node_modules/iconv-lite/encodings/sbcs-codec.js +0 -53
- package/dist/node_modules/iconv-lite/encodings/sbcs-data-generated.cjs +0 -463
- package/dist/node_modules/iconv-lite/encodings/sbcs-data-generated.js +0 -458
- package/dist/node_modules/iconv-lite/encodings/sbcs-data.cjs +0 -155
- package/dist/node_modules/iconv-lite/encodings/sbcs-data.js +0 -150
- package/dist/node_modules/iconv-lite/encodings/tables/big5-added.cjs +0 -175
- package/dist/node_modules/iconv-lite/encodings/tables/big5-added.js +0 -172
- package/dist/node_modules/iconv-lite/encodings/tables/cp936.cjs +0 -2590
- package/dist/node_modules/iconv-lite/encodings/tables/cp936.js +0 -2587
- package/dist/node_modules/iconv-lite/encodings/tables/cp949.cjs +0 -2226
- package/dist/node_modules/iconv-lite/encodings/tables/cp949.js +0 -2223
- package/dist/node_modules/iconv-lite/encodings/tables/cp950.cjs +0 -233
- package/dist/node_modules/iconv-lite/encodings/tables/cp950.js +0 -230
- package/dist/node_modules/iconv-lite/encodings/tables/eucjp.cjs +0 -431
- package/dist/node_modules/iconv-lite/encodings/tables/eucjp.js +0 -428
- package/dist/node_modules/iconv-lite/encodings/tables/gb18030-ranges.cjs +0 -433
- package/dist/node_modules/iconv-lite/encodings/tables/gb18030-ranges.js +0 -430
- package/dist/node_modules/iconv-lite/encodings/tables/gbk-added.cjs +0 -235
- package/dist/node_modules/iconv-lite/encodings/tables/gbk-added.js +0 -232
- package/dist/node_modules/iconv-lite/encodings/tables/shiftjis.cjs +0 -298
- package/dist/node_modules/iconv-lite/encodings/tables/shiftjis.js +0 -295
- package/dist/node_modules/iconv-lite/encodings/utf16.cjs +0 -112
- package/dist/node_modules/iconv-lite/encodings/utf16.js +0 -107
- package/dist/node_modules/iconv-lite/encodings/utf7.cjs +0 -188
- package/dist/node_modules/iconv-lite/encodings/utf7.js +0 -183
- package/dist/node_modules/iconv-lite/lib/bom-handling.cjs +0 -50
- package/dist/node_modules/iconv-lite/lib/bom-handling.js +0 -45
- package/dist/node_modules/iconv-lite/lib/extend-node.cjs +0 -155
- package/dist/node_modules/iconv-lite/lib/extend-node.js +0 -150
- package/dist/node_modules/iconv-lite/lib/index.cjs +0 -101
- package/dist/node_modules/iconv-lite/lib/index.js +0 -96
- package/dist/node_modules/iconv-lite/lib/streams.cjs +0 -102
- package/dist/node_modules/iconv-lite/lib/streams.js +0 -97
- package/dist/node_modules/inherits/inherits.cjs +0 -23
- package/dist/node_modules/inherits/inherits.js +0 -20
- package/dist/node_modules/inherits/inherits_browser.cjs +0 -33
- package/dist/node_modules/inherits/inherits_browser.js +0 -30
- package/dist/node_modules/ipaddr.js/lib/ipaddr.cjs +0 -680
- package/dist/node_modules/ipaddr.js/lib/ipaddr.js +0 -677
- package/dist/node_modules/math-intrinsics/abs.cjs +0 -17
- package/dist/node_modules/math-intrinsics/abs.js +0 -12
- package/dist/node_modules/math-intrinsics/floor.cjs +0 -17
- package/dist/node_modules/math-intrinsics/floor.js +0 -12
- package/dist/node_modules/math-intrinsics/isNaN.cjs +0 -19
- package/dist/node_modules/math-intrinsics/isNaN.js +0 -14
- package/dist/node_modules/math-intrinsics/max.cjs +0 -17
- package/dist/node_modules/math-intrinsics/max.js +0 -12
- package/dist/node_modules/math-intrinsics/min.cjs +0 -17
- package/dist/node_modules/math-intrinsics/min.js +0 -12
- package/dist/node_modules/math-intrinsics/pow.cjs +0 -17
- package/dist/node_modules/math-intrinsics/pow.js +0 -12
- package/dist/node_modules/math-intrinsics/round.cjs +0 -17
- package/dist/node_modules/math-intrinsics/round.js +0 -12
- package/dist/node_modules/math-intrinsics/sign.cjs +0 -22
- package/dist/node_modules/math-intrinsics/sign.js +0 -17
- package/dist/node_modules/merge-descriptors/index.cjs +0 -51
- package/dist/node_modules/merge-descriptors/index.js +0 -46
- package/dist/node_modules/methods/index.cjs +0 -74
- package/dist/node_modules/methods/index.js +0 -69
- package/dist/node_modules/mime/mime.cjs +0 -82
- package/dist/node_modules/mime/mime.js +0 -79
- package/dist/node_modules/mime/types.cjs +0 -1107
- package/dist/node_modules/mime/types.js +0 -1104
- package/dist/node_modules/mime-types/index.cjs +0 -128
- package/dist/node_modules/mime-types/index.js +0 -123
- package/dist/node_modules/mime-types/node_modules/mime-db/db.cjs +0 -7054
- package/dist/node_modules/mime-types/node_modules/mime-db/db.js +0 -7051
- package/dist/node_modules/mime-types/node_modules/mime-db/index.cjs +0 -24
- package/dist/node_modules/mime-types/node_modules/mime-db/index.js +0 -21
- package/dist/node_modules/ms/index.cjs +0 -127
- package/dist/node_modules/ms/index.js +0 -124
- package/dist/node_modules/negotiator/index.cjs +0 -81
- package/dist/node_modules/negotiator/index.js +0 -76
- package/dist/node_modules/negotiator/lib/charset.cjs +0 -137
- package/dist/node_modules/negotiator/lib/charset.js +0 -132
- package/dist/node_modules/negotiator/lib/encoding.cjs +0 -148
- package/dist/node_modules/negotiator/lib/encoding.js +0 -143
- package/dist/node_modules/negotiator/lib/language.cjs +0 -143
- package/dist/node_modules/negotiator/lib/language.js +0 -138
- package/dist/node_modules/negotiator/lib/mediaType.cjs +0 -205
- package/dist/node_modules/negotiator/lib/mediaType.js +0 -200
- package/dist/node_modules/object-inspect/index.cjs +0 -392
- package/dist/node_modules/object-inspect/index.js +0 -389
- package/dist/node_modules/object-inspect/util.inspect.cjs +0 -14
- package/dist/node_modules/object-inspect/util.inspect.js +0 -11
- package/dist/node_modules/on-finished/index.cjs +0 -183
- package/dist/node_modules/on-finished/index.js +0 -178
- package/dist/node_modules/parseurl/index.cjs +0 -116
- package/dist/node_modules/parseurl/index.js +0 -111
- package/dist/node_modules/path-to-regexp/index.cjs +0 -121
- package/dist/node_modules/path-to-regexp/index.js +0 -118
- package/dist/node_modules/proxy-addr/index.cjs +0 -217
- package/dist/node_modules/proxy-addr/index.js +0 -212
- package/dist/node_modules/range-parser/index.cjs +0 -115
- package/dist/node_modules/range-parser/index.js +0 -110
- package/dist/node_modules/raw-body/index.cjs +0 -214
- package/dist/node_modules/raw-body/index.js +0 -209
- package/dist/node_modules/safe-buffer/index.cjs +0 -49
- package/dist/node_modules/safe-buffer/index.js +0 -46
- package/dist/node_modules/safer-buffer/safer.cjs +0 -53
- package/dist/node_modules/safer-buffer/safer.js +0 -48
- package/dist/node_modules/send/index.cjs +0 -806
- package/dist/node_modules/send/index.js +0 -801
- package/dist/node_modules/send/node_modules/encodeurl/index.cjs +0 -61
- package/dist/node_modules/send/node_modules/encodeurl/index.js +0 -56
- package/dist/node_modules/serve-static/index.cjs +0 -139
- package/dist/node_modules/serve-static/index.js +0 -134
- package/dist/node_modules/setprototypeof/index.cjs +0 -24
- package/dist/node_modules/setprototypeof/index.js +0 -19
- package/dist/node_modules/side-channel/index.cjs +0 -50
- package/dist/node_modules/side-channel/index.js +0 -45
- package/dist/node_modules/side-channel-list/index.cjs +0 -89
- package/dist/node_modules/side-channel-list/index.js +0 -84
- package/dist/node_modules/side-channel-map/index.cjs +0 -67
- package/dist/node_modules/side-channel-map/index.js +0 -62
- package/dist/node_modules/side-channel-weakmap/index.cjs +0 -78
- package/dist/node_modules/side-channel-weakmap/index.js +0 -73
- package/dist/node_modules/statuses/codes.cjs +0 -78
- package/dist/node_modules/statuses/codes.js +0 -75
- package/dist/node_modules/statuses/index.cjs +0 -113
- package/dist/node_modules/statuses/index.js +0 -108
- package/dist/node_modules/toidentifier/index.cjs +0 -37
- package/dist/node_modules/toidentifier/index.js +0 -32
- package/dist/node_modules/type-is/index.cjs +0 -184
- package/dist/node_modules/type-is/index.js +0 -179
- package/dist/node_modules/type-is/node_modules/media-typer/index.cjs +0 -189
- package/dist/node_modules/type-is/node_modules/media-typer/index.js +0 -186
- package/dist/node_modules/unpipe/index.cjs +0 -55
- package/dist/node_modules/unpipe/index.js +0 -50
- package/dist/node_modules/utils-merge/index.cjs +0 -31
- package/dist/node_modules/utils-merge/index.js +0 -28
- package/dist/node_modules/vary/index.cjs +0 -100
- package/dist/node_modules/vary/index.js +0 -95
- package/dist/packages/sadot/src/api/index.cjs +0 -12
- package/dist/packages/sadot/src/api/index.js +0 -11
- package/dist/packages/sadot/src/api/v1/definition/index.cjs +0 -113
- package/dist/packages/sadot/src/api/v1/definition/index.js +0 -112
- package/dist/packages/sadot/src/api/v1/definition/validations.cjs +0 -128
- package/dist/packages/sadot/src/api/v1/definition/validations.js +0 -125
- package/dist/packages/sadot/src/api/v1/errors.cjs +0 -14
- package/dist/packages/sadot/src/api/v1/errors.js +0 -13
- package/dist/packages/sadot/src/api/v1/index.cjs +0 -16
- package/dist/packages/sadot/src/api/v1/index.js +0 -15
- package/dist/packages/sadot/src/api/v1/templates/index.cjs +0 -77
- package/dist/packages/sadot/src/api/v1/templates/index.js +0 -76
- package/dist/packages/sadot/src/api/v1/validator/index.cjs +0 -115
- package/dist/packages/sadot/src/api/v1/validator/index.js +0 -114
- package/dist/packages/sadot/src/api/v1/validator/validations.cjs +0 -40
- package/dist/packages/sadot/src/api/v1/validator/validations.js +0 -38
- package/dist/packages/sadot/src/errors/index.cjs +0 -62
- package/dist/packages/sadot/src/errors/index.js +0 -55
- package/dist/packages/sadot/src/events/index.cjs +0 -52
- package/dist/packages/sadot/src/events/index.js +0 -50
- package/dist/packages/sadot/src/hooks/enrich.cjs +0 -175
- package/dist/packages/sadot/src/hooks/enrich.js +0 -175
- package/dist/packages/sadot/src/hooks/find.cjs +0 -22
- package/dist/packages/sadot/src/hooks/find.js +0 -22
- package/dist/packages/sadot/src/hooks/hooks.cjs +0 -310
- package/dist/packages/sadot/src/hooks/hooks.js +0 -302
- package/dist/packages/sadot/src/hooks/index.cjs +0 -3
- package/dist/packages/sadot/src/hooks/index.js +0 -5
- package/dist/packages/sadot/src/hooks/utils/updateInstanceValues.cjs +0 -27
- package/dist/packages/sadot/src/hooks/utils/updateInstanceValues.js +0 -27
- package/dist/packages/sadot/src/init-state.cjs +0 -56
- package/dist/packages/sadot/src/init-state.js +0 -55
- package/dist/packages/sadot/src/mat-path-state.cjs +0 -10
- package/dist/packages/sadot/src/mat-path-state.js +0 -9
- package/dist/packages/sadot/src/migrations/004-create-field-policy-tables.cjs +0 -29
- package/dist/packages/sadot/src/migrations/004-create-field-policy-tables.js +0 -27
- package/dist/packages/sadot/src/migrations/index.cjs +0 -88
- package/dist/packages/sadot/src/migrations/index.js +0 -89
- package/dist/packages/sadot/src/models/CustomFieldDefinition.cjs +0 -147
- package/dist/packages/sadot/src/models/CustomFieldDefinition.js +0 -146
- package/dist/packages/sadot/src/models/CustomFieldEntries.cjs +0 -71
- package/dist/packages/sadot/src/models/CustomFieldEntries.js +0 -70
- package/dist/packages/sadot/src/models/CustomFieldModelTypeMap.cjs +0 -62
- package/dist/packages/sadot/src/models/CustomFieldModelTypeMap.js +0 -61
- package/dist/packages/sadot/src/models/CustomFieldValue.cjs +0 -109
- package/dist/packages/sadot/src/models/CustomFieldValue.js +0 -108
- package/dist/packages/sadot/src/models/CustomValidator.cjs +0 -68
- package/dist/packages/sadot/src/models/CustomValidator.js +0 -67
- package/dist/packages/sadot/src/models/FieldPolicy.cjs +0 -50
- package/dist/packages/sadot/src/models/FieldPolicy.d.ts +0 -23
- package/dist/packages/sadot/src/models/FieldPolicy.js +0 -49
- package/dist/packages/sadot/src/models/index.cjs +0 -163
- package/dist/packages/sadot/src/models/index.js +0 -161
- package/dist/packages/sadot/src/models/tests/AssociatedTestModel.cjs +0 -51
- package/dist/packages/sadot/src/models/tests/AssociatedTestModel.js +0 -50
- package/dist/packages/sadot/src/models/tests/TestModel.cjs +0 -43
- package/dist/packages/sadot/src/models/tests/TestModel.js +0 -42
- package/dist/packages/sadot/src/models/tests/contextAwareModels/ContextAwareTestModel.cjs +0 -35
- package/dist/packages/sadot/src/models/tests/contextAwareModels/ContextAwareTestModel.js +0 -34
- package/dist/packages/sadot/src/models/tests/contextAwareModels/ContextTestModel.cjs +0 -33
- package/dist/packages/sadot/src/models/tests/contextAwareModels/ContextTestModel.js +0 -32
- package/dist/packages/sadot/src/repository/definition.cjs +0 -221
- package/dist/packages/sadot/src/repository/definition.js +0 -212
- package/dist/packages/sadot/src/repository/entries.cjs +0 -69
- package/dist/packages/sadot/src/repository/entries.js +0 -67
- package/dist/packages/sadot/src/repository/field-policy.cjs +0 -42
- package/dist/packages/sadot/src/repository/field-policy.d.ts +0 -29
- package/dist/packages/sadot/src/repository/field-policy.js +0 -33
- package/dist/packages/sadot/src/repository/utils/formatValues.cjs +0 -14
- package/dist/packages/sadot/src/repository/utils/formatValues.js +0 -14
- package/dist/packages/sadot/src/repository/validator.cjs +0 -58
- package/dist/packages/sadot/src/repository/validator.js +0 -54
- package/dist/packages/sadot/src/repository/value.cjs +0 -77
- package/dist/packages/sadot/src/repository/value.js +0 -76
- package/dist/packages/sadot/src/scopes/filter.cjs +0 -56
- package/dist/packages/sadot/src/scopes/filter.js +0 -54
- package/dist/packages/sadot/src/scopes/helpers/filter.helpers.cjs +0 -152
- package/dist/packages/sadot/src/scopes/helpers/filter.helpers.js +0 -147
- package/dist/packages/sadot/src/scopes/index.cjs +0 -1
- package/dist/packages/sadot/src/scopes/index.js +0 -3
- package/dist/packages/sadot/src/utils/constants/index.cjs +0 -32
- package/dist/packages/sadot/src/utils/constants/index.js +0 -29
- package/dist/packages/sadot/src/utils/db/index.cjs +0 -15
- package/dist/packages/sadot/src/utils/db/index.js +0 -14
- package/dist/packages/sadot/src/utils/helpers/index.cjs +0 -23
- package/dist/packages/sadot/src/utils/helpers/index.js +0 -21
- package/dist/packages/sadot/src/utils/init.cjs +0 -115
- package/dist/packages/sadot/src/utils/init.js +0 -111
- package/dist/packages/sadot/src/utils/logger/index.cjs +0 -15
- package/dist/packages/sadot/src/utils/logger/index.js +0 -12
- package/dist/packages/sadot/src/utils/scopeAttributes.cjs +0 -12
- package/dist/packages/sadot/src/utils/scopeAttributes.js +0 -11
- package/dist/packages/sadot/src/utils/validations/index.cjs +0 -34
- package/dist/packages/sadot/src/utils/validations/index.js +0 -32
- package/dist/packages/sadot/src/utils/validations/schema/custom-fields.cjs +0 -9
- package/dist/packages/sadot/src/utils/validations/schema/custom-fields.js +0 -7
- package/dist/packages/sadot/src/utils/validations/schema/validator-schema.cjs +0 -102
- package/dist/packages/sadot/src/utils/validations/schema/validator-schema.js +0 -99
- package/dist/packages/sadot/src/utils/validations/validators/index.cjs +0 -45
- package/dist/packages/sadot/src/utils/validations/validators/index.js +0 -42
- package/dist/packages/sadot/src/utils/validations/validators/multi-select-dropdown.validator.cjs +0 -7
- package/dist/packages/sadot/src/utils/validations/validators/multi-select-dropdown.validator.js +0 -7
- package/dist/packages/sadot/src/utils/validations/validators/multi-select-status.validator.cjs +0 -10
- package/dist/packages/sadot/src/utils/validations/validators/multi-select-status.validator.js +0 -10
- package/dist/packages/sadot/src/utils/validations/validators/multi-select.helpers.cjs +0 -12
- package/dist/packages/sadot/src/utils/validations/validators/multi-select.helpers.js +0 -10
- package/dist/packages/sadot/src/utils/validations/validators/select.validator.cjs +0 -12
- package/dist/packages/sadot/src/utils/validations/validators/select.validator.js +0 -10
- package/dist/packages/sadot/src/utils/validations/validators/status.validator.cjs +0 -12
- package/dist/packages/sadot/src/utils/validations/validators/status.validator.js +0 -10
- package/dist/repository/field-policy.d.cts +0 -29
- /package/dist/{packages/sadot/src/models → models}/index.d.ts +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"find.cjs","names":[],"sources":["../../src/hooks/find.ts"],"sourcesContent":["import type { FindOptions } from 'sequelize';\nimport logger from '../utils/logger';\n\nconst doScopeAttributesMissing = (\n scopeAttributes: string[],\n queryAttributes: (string | string[])[],\n): string[] => {\n const attributes = scopeAttributes\n .filter(attribute => !queryAttributes.includes(attribute));\n if (!queryAttributes.includes?.('id')) {\n attributes.push('id');\n }\n return attributes;\n};\n\nexport const beforeFind = (scopeAttributes: string[]) => (options: FindOptions): void => {\n const { attributes: queryAttributes } = options;\n if ((queryAttributes as string[])?.includes?.('customFields')) {\n const missingScopeAttributes = doScopeAttributesMissing(scopeAttributes, queryAttributes as string[]);\n logger.debug('sadot - before find hook');\n if (missingScopeAttributes?.length > 0) {\n (queryAttributes as string[]).push(...missingScopeAttributes);\n (options as any).attributesToRemove = missingScopeAttributes;\n }\n }\n};\n"],"mappings":"6CAGM,GACJ,EACA,IACa,CACb,IAAM,EAAa,EAChB,OAAO,GAAa,CAAC,EAAgB,SAAS,EAAU,CAAC,CAI5D,OAHK,EAAgB,WAAW,KAAK,EACnC,EAAW,KAAK,KAAK,CAEhB,GAGI,EAAc,GAA+B,GAA+B,CACvF,GAAM,CAAE,WAAY,GAAoB,EACxC,GAAK,GAA8B,WAAW,eAAe,CAAE,CAC7D,IAAM,EAAyB,EAAyB,EAAiB,EAA4B,CACrG,EAAA,QAAO,MAAM,2BAA2B,CACpC,GAAwB,OAAS,IAClC,EAA6B,KAAK,GAAG,EAAuB,CAC5D,EAAgB,mBAAqB"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import e from"../utils/logger/index.js";const t=(e,t)=>{let n=e.filter(e=>!t.includes(e));return t.includes?.(`id`)||n.push(`id`),n},n=n=>r=>{let{attributes:i}=r;if(i?.includes?.(`customFields`)){let a=t(n,i);e.debug(`sadot - before find hook`),a?.length>0&&(i.push(...a),r.attributesToRemove=a)}};export{n as beforeFind};
|
|
2
|
+
//# sourceMappingURL=find.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"find.js","names":[],"sources":["../../src/hooks/find.ts"],"sourcesContent":["import type { FindOptions } from 'sequelize';\nimport logger from '../utils/logger';\n\nconst doScopeAttributesMissing = (\n scopeAttributes: string[],\n queryAttributes: (string | string[])[],\n): string[] => {\n const attributes = scopeAttributes\n .filter(attribute => !queryAttributes.includes(attribute));\n if (!queryAttributes.includes?.('id')) {\n attributes.push('id');\n }\n return attributes;\n};\n\nexport const beforeFind = (scopeAttributes: string[]) => (options: FindOptions): void => {\n const { attributes: queryAttributes } = options;\n if ((queryAttributes as string[])?.includes?.('customFields')) {\n const missingScopeAttributes = doScopeAttributesMissing(scopeAttributes, queryAttributes as string[]);\n logger.debug('sadot - before find hook');\n if (missingScopeAttributes?.length > 0) {\n (queryAttributes as string[]).push(...missingScopeAttributes);\n (options as any).attributesToRemove = missingScopeAttributes;\n }\n }\n};\n"],"mappings":"wCAGA,MAAM,GACJ,EACA,IACa,CACb,IAAM,EAAa,EAChB,OAAO,GAAa,CAAC,EAAgB,SAAS,EAAU,CAAC,CAI5D,OAHK,EAAgB,WAAW,KAAK,EACnC,EAAW,KAAK,KAAK,CAEhB,GAGI,EAAc,GAA+B,GAA+B,CACvF,GAAM,CAAE,WAAY,GAAoB,EACxC,GAAK,GAA8B,WAAW,eAAe,CAAE,CAC7D,IAAM,EAAyB,EAAyB,EAAiB,EAA4B,CACrG,EAAO,MAAM,2BAA2B,CACpC,GAAwB,OAAS,IAClC,EAA6B,KAAK,GAAG,EAAuB,CAC5D,EAAgB,mBAAqB"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require(`../_virtual/rolldown_runtime.cjs`),t=require(`../utils/logger/index.cjs`),n=require(`../utils/constants/index.cjs`),r=require(`../errors/index.cjs`),i=require(`../repository/definition.cjs`),a=require(`../repository/validator.cjs`),o=require(`../utils/scopeAttributes.cjs`),s=require(`./utils/updateInstanceValues.cjs`);let c=require(`joi`);c=e.__toESM(c);let l=require(`@autofleet/errors`),u=require(`ajv`);u=e.__toESM(u);let d=require(`ajv-formats`);d=e.__toESM(d);let f=require(`ajv-errors`);f=e.__toESM(f);const p=[`id`,`schema`,`modelType`,`entityId`,`disabled`],m=new u.default({allErrors:!0,strict:!1,strictTypes:!1,$data:!0});(0,d.default)(m),(0,f.default)(m);const h=(e,t)=>({__proto__:null,...e,...t}),g=async(e,n)=>{if(!e.id||!e.customFields||Object.keys(e.customFields).length===0)return e.customFields||{};try{let r=await e.constructor.findOne({where:{id:e.id},attributes:[`customFields`],transaction:n.transaction,raw:!0});if(r?.customFields){let n=h(r.customFields,e.customFields);return t.default.debug(`sadot - fetched complete custom fields for validation`,{fieldsCount:Object.keys(n).length,updateFieldsCount:Object.keys(e.customFields).length}),n}}catch(e){t.default.error(`sadot - error fetching complete model for validation`,{error:e})}return e.customFields||{}},_=e=>{let t={...e.dataValues};(e.changed?.()||[]).forEach(n=>{let r=e.previous?.(n);r!==void 0&&(t[n]=r)});let n=e.previous?.(`customFields`);return n!==void 0&&(t.customFields=n),t},v=e=>e.reduce((e,t)=>{let n=((t.instancePath||``).split(`/`).filter(Boolean).join(`.`).replace(/^after\./,``)+(t.keyword===`required`?`.${t.params?.missingProperty}`:``)).replace(/^\./,``)||`root`;return e[n]=t.message||`Invalid value`,e},{}),y=async(e,n,r,i={},s=!1)=>{let c=e.constructor.name;t.default.debug(`sadot - validating model`,{isCreate:s,modelType:c});let u=o.default(e,r);if(t.default.debug(`sadot - identifiers`,{identifiers:u}),!u||Object.keys(u).length===0){t.default.debug(`sadot - skipping validation: no identifiers`);return}let d=Object.values(u)[0];if(t.default.debug(`sadot - entityId`,{entityId:d}),!d){t.default.debug(`sadot - skipping validation: no entityId`);return}let f,y;n.transaction&&(n.transaction.validationsCache??=new Map,y=`${c}-${d}`,f=n.transaction.validationsCache.get(y)),f||(f=a.findAllByModelType(c,d,{transaction:n.transaction,attributes:p,modelOptions:i}),n.transaction&&n?.transaction?.validationsCache.set(y,f));let b=await f;if(t.default.debug(`sadot - validators found`,{count:b.length}),!b.length){t.default.debug(`sadot - skipping validation: no validators found`);return}let x=null;s||(x=_(e));let S=s?e.customFields||{}:await g(e,n);for(let n of b){let{schema:r}=n,i=r;if(t.default.debug(`sadot - validating with schema`,{schema:r,hasAfterProps:!!i.properties?.after,hasBeforeProps:!!i.properties?.before}),s){if(i.properties?.after){let t=m.compile({...r,properties:{after:i.properties.after}});if(!t(JSON.parse(JSON.stringify({after:{...e.dataValues,customFields:S}})))){let e=t.errors?.map(e=>`${e.instancePath||``} ${e.message||`Invalid value`}`).join(`, `),n=v(t.errors);throw new l.BadRequest([Error(`Validation failed for ${c}: ${e}`)],void 0,{customError:n})}}}else{let n=m.compile(i),r=h(e.dataValues);r.customFields=S;let a={before:x,after:r},o=n(JSON.parse(JSON.stringify(a)));if(t.default.debug(`sadot - validation result`,{isValid:o,test:{before:x,after:r}}),!o){let e=n.errors?.map(e=>`${e.instancePath||``} ${e.message||`Invalid value`}`).join(`, `),t=v(n.errors);throw new l.BadRequest([Error(`Validation failed for ${c}: ${e}`)],void 0,{customError:t})}}}},b=async({modelType:e,modelOptions:t,identifiers:n,options:r,instance:a,sadotOptions:o})=>{let{include:s,useEntityIdFromInclude:c}=t;if(o.hasTypeId&&a?.typeId)return i.findByModelTypeId(a.typeId,{withDisabled:!1,transaction:r.transaction,entityIds:n,modelType:e,modelOptions:t});let l={modelType:e,disabled:!1,...!c&&{entityId:n}};return i.findAll(l,{withDisabled:!1,transaction:r.transaction,include:s?.(n)})},x=(e,t)=>{(e||[]).forEach(e=>{let{fieldType:i,name:a}=e;if([n.CustomFieldDefinitionType.DATE,n.CustomFieldDefinitionType.DATETIME].includes(i)){let e=t.customFields?.[a];if(e){let{value:n,error:i}=c.default.date().validate(e);if(i)throw new r.InvalidValueError(e,a,i);t.customFields[a]=n.toISOString()}}})},S=(e,n={},i={useCustomFieldsEntries:!1})=>async(a,c)=>{t.default.debug(`sadot - before create hook`);let{fields:l}=c,u=a.constructor.name,d=o.default(a,e),f=await b({modelType:u,modelOptions:n,identifiers:d,options:c,instance:a,sadotOptions:i}),p=f.filter(e=>![null,void 0].includes(e.defaultValue));p.length&&(a.customFields||={},p.filter(e=>a.customFields?.[e.name]===void 0).forEach(({name:e,defaultValue:t})=>{a.customFields[e]=t}));let m;m=i.getRequiredCustomFields?await Promise.resolve(i.getRequiredCustomFields(a,f,c)):Array.from(new Set(f.filter(({required:e})=>e).map(({name:e})=>e)));let{customFields:h}=a,g=Object.keys(h??{}),_=m.filter(e=>!g.includes(e));if(_?.length)throw new r.MissingRequiredCustomFieldError(_);await y(a,c,e,n,!0),x(f,a);let v=l.indexOf(`customFields`);v===-1||!h||!Object.keys(h).length||(await s.default({modelId:a.id,modelType:u,identifiers:d,customFields:h,options:{useCustomFieldsEntries:i.useCustomFieldsEntries,transaction:c.transaction,modelOptions:n}}),l.splice(v,1))},C=(e,n={},r={useCustomFieldsEntries:!1})=>async(i,a)=>{t.default.debug(`sadot - before update hook`);let{fields:c}=a,l=i.constructor.name,u=o.default(i,e),d=await b({modelType:l,modelOptions:n,identifiers:u,options:a,instance:i,sadotOptions:r});await y(i,a,e,n,!1),x(d,i);let f=c.indexOf(`customFields`);if(f>-1){let{customFields:e}=i;if(!Object.keys(e).length)return;await s.default({modelId:i.id,modelType:l,identifiers:u,customFields:e,options:{useCustomFieldsEntries:r.useCustomFieldsEntries,transaction:a.transaction,modelOptions:n}}),c.splice(f,1)}},w=e=>{e.individualHooks=!0},T=e=>{e.individualHooks=!0};exports.beforeBulkCreate=w,exports.beforeBulkUpdate=T,exports.beforeCreate=S,exports.beforeUpdate=C;
|
|
2
|
+
//# sourceMappingURL=hooks.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.cjs","names":["ajv","Ajv","beforeFull: any","applyScopeToInstance","cacheKey: string | undefined","BadRequest","where: WhereOptions","CustomFieldDefinitionType","Joi","InvalidValueError","requiredFieldsNames: string[]","MissingRequiredCustomFieldError","updateInstanceValues"],"sources":["../../src/hooks/hooks.ts"],"sourcesContent":["import type {\n BulkCreateOptions, CreateOptions, Transactionable, UpdateOptions, WhereOptions,\n} from 'sequelize';\nimport Ajv from 'ajv';\nimport Joi from 'joi';\nimport addFormats from 'ajv-formats';\nimport { BadRequest } from '@autofleet/errors';\nimport ajvErrors from 'ajv-errors';\nimport logger from '../utils/logger';\nimport * as ValidatorRepo from '../repository/validator';\nimport * as DefinitionRepo from '../repository/definition';\nimport { InvalidValueError, MissingRequiredCustomFieldError } from '../errors';\nimport type { CustomFieldOptions, ModelOptions, TransactionOptions } from '../types';\nimport applyScopeToInstance from '../utils/scopeAttributes';\nimport updateInstanceValues from './utils/updateInstanceValues';\nimport { CustomFieldDefinitionType } from '../utils/constants';\nimport type { CustomFieldDefinition } from '../models';\n\ntype HookSadotOptions = Pick<\n CustomFieldOptions,\n 'useCustomFieldsEntries' | 'getRequiredCustomFields' | 'hasTypeId'\n>;\n\n// Include all required fields for proper validation\nconst CUSTOM_VALIDATOR_ATTRIBUTES_TO_PULL = ['id', 'schema', 'modelType', 'entityId', 'disabled'];\n\n// Initialize Ajv with relaxed settings to avoid warnings\nconst ajv = new Ajv({\n allErrors: true,\n strict: false, // Disable strict mode to avoid warnings\n strictTypes: false, // Disable strict type checking\n $data: true, // Enable $data references\n});\n\naddFormats(ajv);\najvErrors(ajv);\n\n/**\n * Helper function to manually copy object properties\n * This is more efficient for large objects and avoids excessive object creation\n */\nconst manualObjectCopy = (sourceObj: Record<string, any>, additionalProps?: Record<string, any>): Record<string, any> =>\n ({ __proto__: null, ...sourceObj, ...additionalProps });\n\n/**\n * Fetches complete custom fields for an instance by merging DB values with update values\n * This is needed for partial updates to ensure all related fields are available for validation\n */\nconst getCompleteCustomFields = async (instance: any, options: Transactionable): Promise<Record<string, any>> => {\n // If we don't have an instance id or no custom fields being updated, return original fields\n if (!instance.id || !instance.customFields || Object.keys(instance.customFields).length === 0) {\n return instance.customFields || {};\n }\n\n try {\n const ModelClass = instance.constructor;\n // Only select the customFields column to minimize data transfer\n const currentCustomFields = await ModelClass.findOne({\n where: { id: instance.id },\n attributes: ['customFields'],\n transaction: options.transaction,\n raw: true, // Get plain object instead of model instance for better performance\n });\n\n if (currentCustomFields?.customFields) {\n // Merge existing fields with update fields using our helper function\n const completeFields = manualObjectCopy(\n currentCustomFields.customFields,\n instance.customFields,\n );\n\n logger.debug('sadot - fetched complete custom fields for validation', {\n fieldsCount: Object.keys(completeFields).length,\n updateFieldsCount: Object.keys(instance.customFields).length,\n });\n\n return completeFields;\n }\n } catch (error) {\n logger.error('sadot - error fetching complete model for validation', { error });\n // Continue with partial data if we can't fetch the complete model\n }\n\n return instance.customFields || {};\n};\n\nconst buildPreChangeState = (instance: any) => {\n const beforeFull: any = { ...instance.dataValues };\n\n const changedKeys: string[] = instance.changed?.() || [];\n changedKeys.forEach((key) => {\n const prevVal = instance.previous?.(key);\n if (prevVal !== undefined) {\n beforeFull[key] = prevVal;\n }\n });\n\n const prevCF = instance.previous?.('customFields');\n if (prevCF !== undefined) {\n beforeFull.customFields = prevCF;\n }\n\n return beforeFull;\n};\n\nconst formatAjvErrors = (\n errors: {\n instancePath?: string;\n keyword: string;\n message?: string;\n params?: Record<string, any>;\n }[],\n): Record<string, string> => errors.reduce((acc, err) => {\n const basePath = (err.instancePath || '')\n .split('/')\n .filter(Boolean)\n .join('.')\n .replace(/^after\\./, '');\n\n const missingProp = err.keyword === 'required' ? `.${err.params?.missingProperty}` : '';\n const key = (basePath + missingProp).replace(/^\\./, '') || 'root';\n\n const message = err.message || 'Invalid value';\n acc[key] = message;\n\n return acc;\n}, {} as Record<string, string>);\n\n/**\n * Validates the model using custom validators\n */\nconst validateModel = async (\n instance: any,\n options: TransactionOptions,\n scopeAttributes: string[],\n modelOptions: ModelOptions = {},\n isCreate = false,\n): Promise<void> => {\n const modelType = instance.constructor.name;\n\n logger.debug('sadot - validating model', { isCreate, modelType });\n const identifiers = applyScopeToInstance(instance, scopeAttributes);\n\n logger.debug('sadot - identifiers', { identifiers });\n\n // Skip if no identifiers\n if (!identifiers || Object.keys(identifiers).length === 0) {\n logger.debug('sadot - skipping validation: no identifiers');\n return;\n }\n\n // Find the entityId from identifiers (fleetId, businessModelId, etc.)\n const entityId = Object.values(identifiers)[0]; // Get the first value as entityId\n\n logger.debug('sadot - entityId', { entityId });\n\n if (!entityId) {\n logger.debug('sadot - skipping validation: no entityId');\n return;\n }\n\n let validatorsPromise;\n let cacheKey: string | undefined;\n if (options.transaction) {\n options.transaction.validationsCache ??= new Map();\n cacheKey = `${modelType}-${entityId}`;\n validatorsPromise = options.transaction.validationsCache.get(cacheKey);\n }\n\n if (!validatorsPromise) {\n validatorsPromise = ValidatorRepo.findAllByModelType(\n modelType,\n entityId,\n {\n transaction: options.transaction,\n attributes: CUSTOM_VALIDATOR_ATTRIBUTES_TO_PULL,\n modelOptions,\n },\n );\n if (options.transaction) {\n options?.transaction?.validationsCache!.set(cacheKey!, validatorsPromise);\n }\n }\n const validators = await validatorsPromise;\n\n logger.debug('sadot - validators found', { count: validators.length });\n\n if (!validators.length) {\n logger.debug('sadot - skipping validation: no validators found');\n return;\n }\n\n // For updates, get the previous values\n let originalValues = null;\n if (!isCreate) {\n originalValues = buildPreChangeState(instance);\n }\n\n // Get complete custom fields by merging DB values with update values\n // This is especially important for partial updates to ensure all related fields are available\n const completeCustomFields = !isCreate\n ? await getCompleteCustomFields(instance, options)\n : instance.customFields || {};\n\n for (const validator of validators) {\n const { schema } = validator;\n const typedSchema = schema as Record<string, any>;\n\n logger.debug('sadot - validating with schema', {\n schema,\n hasAfterProps: !!typedSchema.properties?.after,\n hasBeforeProps: !!typedSchema.properties?.before,\n });\n\n if (isCreate) {\n // For create operations, we only need the 'after' state\n if (typedSchema.properties?.after) {\n const validateSchema = ajv.compile({\n ...schema,\n // Focus only on the 'after' validation part for create\n properties: {\n after: typedSchema.properties.after,\n },\n });\n\n const isValid = validateSchema(JSON.parse(JSON.stringify({\n after: {\n ...instance.dataValues,\n customFields: completeCustomFields,\n },\n })));\n\n if (!isValid) {\n const errorDetails = validateSchema.errors?.map(err =>\n `${(err as any).instancePath || ''} ${(err as any).message || 'Invalid value'}`).join(', ');\n\n const formattedErrors = formatAjvErrors(validateSchema.errors!);\n throw new BadRequest(\n [new Error(`Validation failed for ${modelType}: ${errorDetails}`)],\n undefined,\n {\n customError: formattedErrors,\n },\n );\n }\n }\n } else {\n // For update operations, we need both before and after\n const validateSchema = ajv.compile(typedSchema);\n\n // Create after object with our helper function\n const afterObj = manualObjectCopy(instance.dataValues);\n\n // Add complete custom fields\n afterObj.customFields = completeCustomFields;\n\n // Create validation payload\n const payload = {\n before: originalValues,\n after: afterObj,\n };\n\n // Validate\n const isValid = validateSchema(JSON.parse(JSON.stringify(payload)));\n\n logger.debug('sadot - validation result', {\n isValid,\n test: {\n before: originalValues,\n after: afterObj,\n },\n });\n\n if (!isValid) {\n const errorDetails = validateSchema\n .errors\n ?.map(err => `${(err as any).instancePath || ''} ${(err as any).message || 'Invalid value'}`).join(', ');\n\n const formattedErrors = formatAjvErrors(validateSchema.errors!);\n throw new BadRequest(\n [new Error(`Validation failed for ${modelType}: ${errorDetails}`)],\n undefined,\n {\n customError: formattedErrors,\n },\n );\n }\n }\n }\n};\n\nconst getFieldDefinitions = async ({\n modelType,\n modelOptions,\n identifiers,\n options,\n instance,\n sadotOptions,\n}: {\n modelType: any;\n modelOptions: ModelOptions;\n identifiers: any[];\n options: any;\n instance?: any;\n sadotOptions: HookSadotOptions;\n}) => {\n const { include, useEntityIdFromInclude } = modelOptions;\n\n if (sadotOptions.hasTypeId && instance?.typeId) {\n return DefinitionRepo.findByModelTypeId(instance.typeId, {\n withDisabled: false,\n transaction: options.transaction,\n entityIds: identifiers,\n modelType,\n modelOptions,\n });\n }\n const where: WhereOptions = {\n modelType,\n disabled: false,\n ...(!useEntityIdFromInclude && { entityId: identifiers }),\n };\n return DefinitionRepo.findAll(where, {\n withDisabled: false,\n transaction: options.transaction,\n include: include?.(identifiers),\n });\n};\n\nconst formatDates = (fieldDefinitions: CustomFieldDefinition[], instance: any) => {\n (fieldDefinitions || []).forEach((fieldDefinition) => {\n const { fieldType, name } = fieldDefinition;\n if ([CustomFieldDefinitionType.DATE, CustomFieldDefinitionType.DATETIME].includes(fieldType)) {\n const value = instance.customFields?.[name];\n if (value) {\n const { value: joiValue, error: validationError } = Joi.date().validate(value);\n if (validationError) {\n throw new InvalidValueError(value, name, validationError);\n }\n instance.customFields[name] = joiValue.toISOString();\n }\n }\n });\n};\n\n/**\n * Hook to handle validation and custom fields during creation\n */\nexport const beforeCreate = (\n scopeAttributes: string[],\n modelOptions: ModelOptions = {},\n sadotOptions: HookSadotOptions = { useCustomFieldsEntries: false },\n) => async (\n instance: any,\n options: CreateOptions,\n): Promise<void> => {\n logger.debug('sadot - before create hook');\n const { fields } = options;\n const modelType = instance.constructor.name;\n\n const identifiers = applyScopeToInstance(instance, scopeAttributes);\n\n // Step 1: Handle custom fields default values and required fields\n\n const fieldDefinitions = await getFieldDefinitions({\n modelType, modelOptions, identifiers, options, instance, sadotOptions,\n });\n\n // Apply default values\n const fieldsWithDefaultValue = fieldDefinitions.filter(def => ![null, undefined].includes(def.defaultValue));\n if (fieldsWithDefaultValue.length) {\n instance.customFields ||= {};\n fieldsWithDefaultValue\n .filter(def => (instance.customFields?.[def.name] === undefined))\n .forEach(({ name, defaultValue }) => {\n instance.customFields[name] = defaultValue;\n });\n }\n\n // Check for required fields\n let requiredFieldsNames: string[];\n\n if (sadotOptions.getRequiredCustomFields) {\n // Use consumer-provided logic to determine required fields\n requiredFieldsNames = await Promise.resolve(\n sadotOptions.getRequiredCustomFields(instance, fieldDefinitions, options),\n );\n } else {\n // Default behavior: use required flag from fieldDefinitions\n requiredFieldsNames = Array.from(\n new Set(fieldDefinitions.filter(({ required }) => required).map(({ name }) => name)),\n );\n }\n\n const { customFields } = instance;\n const fieldsNames = Object.keys(customFields ?? {});\n const missingFields = requiredFieldsNames.filter(name => !fieldsNames.includes(name));\n if (missingFields?.length) {\n throw new MissingRequiredCustomFieldError(missingFields);\n }\n\n // Step 2: Validate the model data (including custom fields)\n await validateModel(instance, options as TransactionOptions, scopeAttributes, modelOptions, true);\n\n // format date and datetime fields\n formatDates(fieldDefinitions, instance);\n\n // Step 3: Save custom field values if they exist\n const customFieldsIdx = fields!.indexOf('customFields');\n if (customFieldsIdx === -1 || !customFields || !Object.keys(customFields).length) {\n // No custom fields to update\n return;\n }\n\n // Save custom field values\n await updateInstanceValues({\n modelId: instance.id,\n modelType,\n identifiers,\n customFields,\n options: {\n useCustomFieldsEntries: sadotOptions.useCustomFieldsEntries,\n transaction: options.transaction,\n modelOptions,\n },\n });\n\n // Remove customFields from fields array after handling\n fields!.splice(customFieldsIdx, 1);\n};\n\n/**\n * Hook to handle validation and custom fields during update\n */\nexport const beforeUpdate = (\n scopeAttributes: string[],\n modelOptions: ModelOptions = {},\n sadotOptions: HookSadotOptions = { useCustomFieldsEntries: false },\n) => async (\n instance: any,\n options: UpdateOptions,\n): Promise<void> => {\n logger.debug('sadot - before update hook');\n const { fields } = options;\n const modelType = instance.constructor.name;\n const identifiers = applyScopeToInstance(instance, scopeAttributes);\n\n const fieldDefinitions = await getFieldDefinitions({\n modelType, modelOptions, identifiers, options, instance, sadotOptions,\n });\n\n // Step 1: Validate the model data (including custom fields)\n await validateModel(instance, options as TransactionOptions, scopeAttributes, modelOptions, false);\n\n // format date and datetime fields\n formatDates(fieldDefinitions, instance);\n\n // Step 2: Update custom field values if they exist\n const customFieldsIdx = fields!.indexOf('customFields');\n if (customFieldsIdx > -1) {\n const { customFields } = instance;\n\n if (!Object.keys(customFields).length) {\n return;\n }\n\n // Save custom field values\n await updateInstanceValues({\n modelId: instance.id,\n modelType,\n identifiers,\n customFields,\n options: {\n useCustomFieldsEntries: sadotOptions.useCustomFieldsEntries,\n transaction: options.transaction,\n modelOptions,\n },\n });\n\n // Remove customFields from fields array after handling\n fields!.splice(customFieldsIdx, 1);\n }\n};\n\n/**\n * Hook to enable individual hooks for bulk create operations\n */\nexport const beforeBulkCreate = (options: BulkCreateOptions): void => {\n // This will activate the beforeCreate hook on each instance\n options.individualHooks = true;\n};\n\n/**\n * Hook to enable individual hooks for bulk update operations\n */\nexport const beforeBulkUpdate = (options: UpdateOptions): void => {\n // This will activate the beforeUpdate hook on each instance\n options.individualHooks = true;\n};\n"],"mappings":"+gBAwBA,MAAM,EAAsC,CAAC,KAAM,SAAU,YAAa,WAAY,WAAW,CAG3FA,EAAM,IAAIC,EAAAA,QAAI,CAClB,UAAW,GACX,OAAQ,GACR,YAAa,GACb,MAAO,GACR,CAAC,eAESD,EAAI,eACLA,EAAI,CAMd,MAAM,GAAoB,EAAgC,KACvD,CAAE,UAAW,KAAM,GAAG,EAAW,GAAG,EAAiB,EAMlD,EAA0B,MAAO,EAAe,IAA2D,CAE/G,GAAI,CAAC,EAAS,IAAM,CAAC,EAAS,cAAgB,OAAO,KAAK,EAAS,aAAa,CAAC,SAAW,EAC1F,OAAO,EAAS,cAAgB,EAAE,CAGpC,GAAI,CAGF,IAAM,EAAsB,MAFT,EAAS,YAEiB,QAAQ,CACnD,MAAO,CAAE,GAAI,EAAS,GAAI,CAC1B,WAAY,CAAC,eAAe,CAC5B,YAAa,EAAQ,YACrB,IAAK,GACN,CAAC,CAEF,GAAI,GAAqB,aAAc,CAErC,IAAM,EAAiB,EACrB,EAAoB,aACpB,EAAS,aACV,CAOD,OALA,EAAA,QAAO,MAAM,wDAAyD,CACpE,YAAa,OAAO,KAAK,EAAe,CAAC,OACzC,kBAAmB,OAAO,KAAK,EAAS,aAAa,CAAC,OACvD,CAAC,CAEK,SAEF,EAAO,CACd,EAAA,QAAO,MAAM,uDAAwD,CAAE,QAAO,CAAC,CAIjF,OAAO,EAAS,cAAgB,EAAE,EAG9B,EAAuB,GAAkB,CAC7C,IAAME,EAAkB,CAAE,GAAG,EAAS,WAAY,EAEpB,EAAS,WAAW,EAAI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,uBACrC,YAAa,EAAQ,YACrB,eACD,CACF,CAAC,CAGF,EAAQ,OAAO,EAAiB,EAAE,GAMvB,GACX,EACA,EAA6B,EAAE,CAC/B,EAAiC,CAAE,uBAAwB,GAAO,GAC/D,MACH,EACA,IACkB,CAClB,EAAA,QAAO,MAAM,6BAA6B,CAC1C,GAAM,CAAE,UAAW,EACb,EAAY,EAAS,YAAY,KACjC,EAAcT,EAAAA,QAAqB,EAAU,EAAgB,CAE7D,EAAmB,MAAM,EAAoB,CACjD,YAAW,eAAc,cAAa,UAAS,WAAU,eAC1D,CAAC,CAGF,MAAM,EAAc,EAAU,EAA+B,EAAiB,EAAc,GAAM,CAGlG,EAAY,EAAkB,EAAS,CAGvC,IAAM,EAAkB,EAAQ,QAAQ,eAAe,CACvD,GAAI,EAAkB,GAAI,CACxB,GAAM,CAAE,gBAAiB,EAEzB,GAAI,CAAC,OAAO,KAAK,EAAa,CAAC,OAC7B,OAIF,MAAMS,EAAAA,QAAqB,CACzB,QAAS,EAAS,GAClB,YACA,cACA,eACA,QAAS,CACP,uBAAwB,EAAa,uBACrC,YAAa,EAAQ,YACrB,eACD,CACF,CAAC,CAGF,EAAQ,OAAO,EAAiB,EAAE,GAOzB,EAAoB,GAAqC,CAEpE,EAAQ,gBAAkB,IAMf,EAAoB,GAAiC,CAEhE,EAAQ,gBAAkB"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import e from"../utils/logger/index.js";import{CustomFieldDefinitionType as t}from"../utils/constants/index.js";import{InvalidValueError as n,MissingRequiredCustomFieldError as r}from"../errors/index.js";import{findAll as i,findByModelTypeId as a}from"../repository/definition.js";import{findAllByModelType as o}from"../repository/validator.js";import s from"../utils/scopeAttributes.js";import c from"./utils/updateInstanceValues.js";import l from"joi";import{BadRequest as u}from"@autofleet/errors";import d from"ajv";import f from"ajv-formats";import p from"ajv-errors";const m=[`id`,`schema`,`modelType`,`entityId`,`disabled`],h=new d({allErrors:!0,strict:!1,strictTypes:!1,$data:!0});f(h),p(h);const g=(e,t)=>({__proto__:null,...e,...t}),_=async(t,n)=>{if(!t.id||!t.customFields||Object.keys(t.customFields).length===0)return t.customFields||{};try{let r=await t.constructor.findOne({where:{id:t.id},attributes:[`customFields`],transaction:n.transaction,raw:!0});if(r?.customFields){let n=g(r.customFields,t.customFields);return e.debug(`sadot - fetched complete custom fields for validation`,{fieldsCount:Object.keys(n).length,updateFieldsCount:Object.keys(t.customFields).length}),n}}catch(t){e.error(`sadot - error fetching complete model for validation`,{error:t})}return t.customFields||{}},v=e=>{let t={...e.dataValues};(e.changed?.()||[]).forEach(n=>{let r=e.previous?.(n);r!==void 0&&(t[n]=r)});let n=e.previous?.(`customFields`);return n!==void 0&&(t.customFields=n),t},y=e=>e.reduce((e,t)=>{let n=((t.instancePath||``).split(`/`).filter(Boolean).join(`.`).replace(/^after\./,``)+(t.keyword===`required`?`.${t.params?.missingProperty}`:``)).replace(/^\./,``)||`root`;return e[n]=t.message||`Invalid value`,e},{}),b=async(t,n,r,i={},a=!1)=>{let c=t.constructor.name;e.debug(`sadot - validating model`,{isCreate:a,modelType:c});let l=s(t,r);if(e.debug(`sadot - identifiers`,{identifiers:l}),!l||Object.keys(l).length===0){e.debug(`sadot - skipping validation: no identifiers`);return}let d=Object.values(l)[0];if(e.debug(`sadot - entityId`,{entityId:d}),!d){e.debug(`sadot - skipping validation: no entityId`);return}let f,p;n.transaction&&(n.transaction.validationsCache??=new Map,p=`${c}-${d}`,f=n.transaction.validationsCache.get(p)),f||(f=o(c,d,{transaction:n.transaction,attributes:m,modelOptions:i}),n.transaction&&n?.transaction?.validationsCache.set(p,f));let b=await f;if(e.debug(`sadot - validators found`,{count:b.length}),!b.length){e.debug(`sadot - skipping validation: no validators found`);return}let x=null;a||(x=v(t));let S=a?t.customFields||{}:await _(t,n);for(let n of b){let{schema:r}=n,i=r;if(e.debug(`sadot - validating with schema`,{schema:r,hasAfterProps:!!i.properties?.after,hasBeforeProps:!!i.properties?.before}),a){if(i.properties?.after){let e=h.compile({...r,properties:{after:i.properties.after}});if(!e(JSON.parse(JSON.stringify({after:{...t.dataValues,customFields:S}})))){let t=e.errors?.map(e=>`${e.instancePath||``} ${e.message||`Invalid value`}`).join(`, `),n=y(e.errors);throw new u([Error(`Validation failed for ${c}: ${t}`)],void 0,{customError:n})}}}else{let n=h.compile(i),r=g(t.dataValues);r.customFields=S;let a={before:x,after:r},o=n(JSON.parse(JSON.stringify(a)));if(e.debug(`sadot - validation result`,{isValid:o,test:{before:x,after:r}}),!o){let e=n.errors?.map(e=>`${e.instancePath||``} ${e.message||`Invalid value`}`).join(`, `),t=y(n.errors);throw new u([Error(`Validation failed for ${c}: ${e}`)],void 0,{customError:t})}}}},x=async({modelType:e,modelOptions:t,identifiers:n,options:r,instance:o,sadotOptions:s})=>{let{include:c,useEntityIdFromInclude:l}=t;return s.hasTypeId&&o?.typeId?a(o.typeId,{withDisabled:!1,transaction:r.transaction,entityIds:n,modelType:e,modelOptions:t}):i({modelType:e,disabled:!1,...!l&&{entityId:n}},{withDisabled:!1,transaction:r.transaction,include:c?.(n)})},S=(e,r)=>{(e||[]).forEach(e=>{let{fieldType:i,name:a}=e;if([t.DATE,t.DATETIME].includes(i)){let e=r.customFields?.[a];if(e){let{value:t,error:i}=l.date().validate(e);if(i)throw new n(e,a,i);r.customFields[a]=t.toISOString()}}})},C=(t,n={},i={useCustomFieldsEntries:!1})=>async(a,o)=>{e.debug(`sadot - before create hook`);let{fields:l}=o,u=a.constructor.name,d=s(a,t),f=await x({modelType:u,modelOptions:n,identifiers:d,options:o,instance:a,sadotOptions:i}),p=f.filter(e=>![null,void 0].includes(e.defaultValue));p.length&&(a.customFields||={},p.filter(e=>a.customFields?.[e.name]===void 0).forEach(({name:e,defaultValue:t})=>{a.customFields[e]=t}));let m;m=i.getRequiredCustomFields?await Promise.resolve(i.getRequiredCustomFields(a,f,o)):Array.from(new Set(f.filter(({required:e})=>e).map(({name:e})=>e)));let{customFields:h}=a,g=Object.keys(h??{}),_=m.filter(e=>!g.includes(e));if(_?.length)throw new r(_);await b(a,o,t,n,!0),S(f,a);let v=l.indexOf(`customFields`);v===-1||!h||!Object.keys(h).length||(await c({modelId:a.id,modelType:u,identifiers:d,customFields:h,options:{useCustomFieldsEntries:i.useCustomFieldsEntries,transaction:o.transaction,modelOptions:n}}),l.splice(v,1))},w=(t,n={},r={useCustomFieldsEntries:!1})=>async(i,a)=>{e.debug(`sadot - before update hook`);let{fields:o}=a,l=i.constructor.name,u=s(i,t),d=await x({modelType:l,modelOptions:n,identifiers:u,options:a,instance:i,sadotOptions:r});await b(i,a,t,n,!1),S(d,i);let f=o.indexOf(`customFields`);if(f>-1){let{customFields:e}=i;if(!Object.keys(e).length)return;await c({modelId:i.id,modelType:l,identifiers:u,customFields:e,options:{useCustomFieldsEntries:r.useCustomFieldsEntries,transaction:a.transaction,modelOptions:n}}),o.splice(f,1)}},T=e=>{e.individualHooks=!0},E=e=>{e.individualHooks=!0};export{T as beforeBulkCreate,E as beforeBulkUpdate,C as beforeCreate,w as beforeUpdate};
|
|
2
|
+
//# sourceMappingURL=hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.js","names":["beforeFull: any","applyScopeToInstance","cacheKey: string | undefined","ValidatorRepo.findAllByModelType","DefinitionRepo.findByModelTypeId","where: WhereOptions","DefinitionRepo.findAll","requiredFieldsNames: string[]","updateInstanceValues"],"sources":["../../src/hooks/hooks.ts"],"sourcesContent":["import type {\n BulkCreateOptions, CreateOptions, Transactionable, UpdateOptions, WhereOptions,\n} from 'sequelize';\nimport Ajv from 'ajv';\nimport Joi from 'joi';\nimport addFormats from 'ajv-formats';\nimport { BadRequest } from '@autofleet/errors';\nimport ajvErrors from 'ajv-errors';\nimport logger from '../utils/logger';\nimport * as ValidatorRepo from '../repository/validator';\nimport * as DefinitionRepo from '../repository/definition';\nimport { InvalidValueError, MissingRequiredCustomFieldError } from '../errors';\nimport type { CustomFieldOptions, ModelOptions, TransactionOptions } from '../types';\nimport applyScopeToInstance from '../utils/scopeAttributes';\nimport updateInstanceValues from './utils/updateInstanceValues';\nimport { CustomFieldDefinitionType } from '../utils/constants';\nimport type { CustomFieldDefinition } from '../models';\n\ntype HookSadotOptions = Pick<\n CustomFieldOptions,\n 'useCustomFieldsEntries' | 'getRequiredCustomFields' | 'hasTypeId'\n>;\n\n// Include all required fields for proper validation\nconst CUSTOM_VALIDATOR_ATTRIBUTES_TO_PULL = ['id', 'schema', 'modelType', 'entityId', 'disabled'];\n\n// Initialize Ajv with relaxed settings to avoid warnings\nconst ajv = new Ajv({\n allErrors: true,\n strict: false, // Disable strict mode to avoid warnings\n strictTypes: false, // Disable strict type checking\n $data: true, // Enable $data references\n});\n\naddFormats(ajv);\najvErrors(ajv);\n\n/**\n * Helper function to manually copy object properties\n * This is more efficient for large objects and avoids excessive object creation\n */\nconst manualObjectCopy = (sourceObj: Record<string, any>, additionalProps?: Record<string, any>): Record<string, any> =>\n ({ __proto__: null, ...sourceObj, ...additionalProps });\n\n/**\n * Fetches complete custom fields for an instance by merging DB values with update values\n * This is needed for partial updates to ensure all related fields are available for validation\n */\nconst getCompleteCustomFields = async (instance: any, options: Transactionable): Promise<Record<string, any>> => {\n // If we don't have an instance id or no custom fields being updated, return original fields\n if (!instance.id || !instance.customFields || Object.keys(instance.customFields).length === 0) {\n return instance.customFields || {};\n }\n\n try {\n const ModelClass = instance.constructor;\n // Only select the customFields column to minimize data transfer\n const currentCustomFields = await ModelClass.findOne({\n where: { id: instance.id },\n attributes: ['customFields'],\n transaction: options.transaction,\n raw: true, // Get plain object instead of model instance for better performance\n });\n\n if (currentCustomFields?.customFields) {\n // Merge existing fields with update fields using our helper function\n const completeFields = manualObjectCopy(\n currentCustomFields.customFields,\n instance.customFields,\n );\n\n logger.debug('sadot - fetched complete custom fields for validation', {\n fieldsCount: Object.keys(completeFields).length,\n updateFieldsCount: Object.keys(instance.customFields).length,\n });\n\n return completeFields;\n }\n } catch (error) {\n logger.error('sadot - error fetching complete model for validation', { error });\n // Continue with partial data if we can't fetch the complete model\n }\n\n return instance.customFields || {};\n};\n\nconst buildPreChangeState = (instance: any) => {\n const beforeFull: any = { ...instance.dataValues };\n\n const changedKeys: string[] = instance.changed?.() || [];\n changedKeys.forEach((key) => {\n const prevVal = instance.previous?.(key);\n if (prevVal !== undefined) {\n beforeFull[key] = prevVal;\n }\n });\n\n const prevCF = instance.previous?.('customFields');\n if (prevCF !== undefined) {\n beforeFull.customFields = prevCF;\n }\n\n return beforeFull;\n};\n\nconst formatAjvErrors = (\n errors: {\n instancePath?: string;\n keyword: string;\n message?: string;\n params?: Record<string, any>;\n }[],\n): Record<string, string> => errors.reduce((acc, err) => {\n const basePath = (err.instancePath || '')\n .split('/')\n .filter(Boolean)\n .join('.')\n .replace(/^after\\./, '');\n\n const missingProp = err.keyword === 'required' ? `.${err.params?.missingProperty}` : '';\n const key = (basePath + missingProp).replace(/^\\./, '') || 'root';\n\n const message = err.message || 'Invalid value';\n acc[key] = message;\n\n return acc;\n}, {} as Record<string, string>);\n\n/**\n * Validates the model using custom validators\n */\nconst validateModel = async (\n instance: any,\n options: TransactionOptions,\n scopeAttributes: string[],\n modelOptions: ModelOptions = {},\n isCreate = false,\n): Promise<void> => {\n const modelType = instance.constructor.name;\n\n logger.debug('sadot - validating model', { isCreate, modelType });\n const identifiers = applyScopeToInstance(instance, scopeAttributes);\n\n logger.debug('sadot - identifiers', { identifiers });\n\n // Skip if no identifiers\n if (!identifiers || Object.keys(identifiers).length === 0) {\n logger.debug('sadot - skipping validation: no identifiers');\n return;\n }\n\n // Find the entityId from identifiers (fleetId, businessModelId, etc.)\n const entityId = Object.values(identifiers)[0]; // Get the first value as entityId\n\n logger.debug('sadot - entityId', { entityId });\n\n if (!entityId) {\n logger.debug('sadot - skipping validation: no entityId');\n return;\n }\n\n let validatorsPromise;\n let cacheKey: string | undefined;\n if (options.transaction) {\n options.transaction.validationsCache ??= new Map();\n cacheKey = `${modelType}-${entityId}`;\n validatorsPromise = options.transaction.validationsCache.get(cacheKey);\n }\n\n if (!validatorsPromise) {\n validatorsPromise = ValidatorRepo.findAllByModelType(\n modelType,\n entityId,\n {\n transaction: options.transaction,\n attributes: CUSTOM_VALIDATOR_ATTRIBUTES_TO_PULL,\n modelOptions,\n },\n );\n if (options.transaction) {\n options?.transaction?.validationsCache!.set(cacheKey!, validatorsPromise);\n }\n }\n const validators = await validatorsPromise;\n\n logger.debug('sadot - validators found', { count: validators.length });\n\n if (!validators.length) {\n logger.debug('sadot - skipping validation: no validators found');\n return;\n }\n\n // For updates, get the previous values\n let originalValues = null;\n if (!isCreate) {\n originalValues = buildPreChangeState(instance);\n }\n\n // Get complete custom fields by merging DB values with update values\n // This is especially important for partial updates to ensure all related fields are available\n const completeCustomFields = !isCreate\n ? await getCompleteCustomFields(instance, options)\n : instance.customFields || {};\n\n for (const validator of validators) {\n const { schema } = validator;\n const typedSchema = schema as Record<string, any>;\n\n logger.debug('sadot - validating with schema', {\n schema,\n hasAfterProps: !!typedSchema.properties?.after,\n hasBeforeProps: !!typedSchema.properties?.before,\n });\n\n if (isCreate) {\n // For create operations, we only need the 'after' state\n if (typedSchema.properties?.after) {\n const validateSchema = ajv.compile({\n ...schema,\n // Focus only on the 'after' validation part for create\n properties: {\n after: typedSchema.properties.after,\n },\n });\n\n const isValid = validateSchema(JSON.parse(JSON.stringify({\n after: {\n ...instance.dataValues,\n customFields: completeCustomFields,\n },\n })));\n\n if (!isValid) {\n const errorDetails = validateSchema.errors?.map(err =>\n `${(err as any).instancePath || ''} ${(err as any).message || 'Invalid value'}`).join(', ');\n\n const formattedErrors = formatAjvErrors(validateSchema.errors!);\n throw new BadRequest(\n [new Error(`Validation failed for ${modelType}: ${errorDetails}`)],\n undefined,\n {\n customError: formattedErrors,\n },\n );\n }\n }\n } else {\n // For update operations, we need both before and after\n const validateSchema = ajv.compile(typedSchema);\n\n // Create after object with our helper function\n const afterObj = manualObjectCopy(instance.dataValues);\n\n // Add complete custom fields\n afterObj.customFields = completeCustomFields;\n\n // Create validation payload\n const payload = {\n before: originalValues,\n after: afterObj,\n };\n\n // Validate\n const isValid = validateSchema(JSON.parse(JSON.stringify(payload)));\n\n logger.debug('sadot - validation result', {\n isValid,\n test: {\n before: originalValues,\n after: afterObj,\n },\n });\n\n if (!isValid) {\n const errorDetails = validateSchema\n .errors\n ?.map(err => `${(err as any).instancePath || ''} ${(err as any).message || 'Invalid value'}`).join(', ');\n\n const formattedErrors = formatAjvErrors(validateSchema.errors!);\n throw new BadRequest(\n [new Error(`Validation failed for ${modelType}: ${errorDetails}`)],\n undefined,\n {\n customError: formattedErrors,\n },\n );\n }\n }\n }\n};\n\nconst getFieldDefinitions = async ({\n modelType,\n modelOptions,\n identifiers,\n options,\n instance,\n sadotOptions,\n}: {\n modelType: any;\n modelOptions: ModelOptions;\n identifiers: any[];\n options: any;\n instance?: any;\n sadotOptions: HookSadotOptions;\n}) => {\n const { include, useEntityIdFromInclude } = modelOptions;\n\n if (sadotOptions.hasTypeId && instance?.typeId) {\n return DefinitionRepo.findByModelTypeId(instance.typeId, {\n withDisabled: false,\n transaction: options.transaction,\n entityIds: identifiers,\n modelType,\n modelOptions,\n });\n }\n const where: WhereOptions = {\n modelType,\n disabled: false,\n ...(!useEntityIdFromInclude && { entityId: identifiers }),\n };\n return DefinitionRepo.findAll(where, {\n withDisabled: false,\n transaction: options.transaction,\n include: include?.(identifiers),\n });\n};\n\nconst formatDates = (fieldDefinitions: CustomFieldDefinition[], instance: any) => {\n (fieldDefinitions || []).forEach((fieldDefinition) => {\n const { fieldType, name } = fieldDefinition;\n if ([CustomFieldDefinitionType.DATE, CustomFieldDefinitionType.DATETIME].includes(fieldType)) {\n const value = instance.customFields?.[name];\n if (value) {\n const { value: joiValue, error: validationError } = Joi.date().validate(value);\n if (validationError) {\n throw new InvalidValueError(value, name, validationError);\n }\n instance.customFields[name] = joiValue.toISOString();\n }\n }\n });\n};\n\n/**\n * Hook to handle validation and custom fields during creation\n */\nexport const beforeCreate = (\n scopeAttributes: string[],\n modelOptions: ModelOptions = {},\n sadotOptions: HookSadotOptions = { useCustomFieldsEntries: false },\n) => async (\n instance: any,\n options: CreateOptions,\n): Promise<void> => {\n logger.debug('sadot - before create hook');\n const { fields } = options;\n const modelType = instance.constructor.name;\n\n const identifiers = applyScopeToInstance(instance, scopeAttributes);\n\n // Step 1: Handle custom fields default values and required fields\n\n const fieldDefinitions = await getFieldDefinitions({\n modelType, modelOptions, identifiers, options, instance, sadotOptions,\n });\n\n // Apply default values\n const fieldsWithDefaultValue = fieldDefinitions.filter(def => ![null, undefined].includes(def.defaultValue));\n if (fieldsWithDefaultValue.length) {\n instance.customFields ||= {};\n fieldsWithDefaultValue\n .filter(def => (instance.customFields?.[def.name] === undefined))\n .forEach(({ name, defaultValue }) => {\n instance.customFields[name] = defaultValue;\n });\n }\n\n // Check for required fields\n let requiredFieldsNames: string[];\n\n if (sadotOptions.getRequiredCustomFields) {\n // Use consumer-provided logic to determine required fields\n requiredFieldsNames = await Promise.resolve(\n sadotOptions.getRequiredCustomFields(instance, fieldDefinitions, options),\n );\n } else {\n // Default behavior: use required flag from fieldDefinitions\n requiredFieldsNames = Array.from(\n new Set(fieldDefinitions.filter(({ required }) => required).map(({ name }) => name)),\n );\n }\n\n const { customFields } = instance;\n const fieldsNames = Object.keys(customFields ?? {});\n const missingFields = requiredFieldsNames.filter(name => !fieldsNames.includes(name));\n if (missingFields?.length) {\n throw new MissingRequiredCustomFieldError(missingFields);\n }\n\n // Step 2: Validate the model data (including custom fields)\n await validateModel(instance, options as TransactionOptions, scopeAttributes, modelOptions, true);\n\n // format date and datetime fields\n formatDates(fieldDefinitions, instance);\n\n // Step 3: Save custom field values if they exist\n const customFieldsIdx = fields!.indexOf('customFields');\n if (customFieldsIdx === -1 || !customFields || !Object.keys(customFields).length) {\n // No custom fields to update\n return;\n }\n\n // Save custom field values\n await updateInstanceValues({\n modelId: instance.id,\n modelType,\n identifiers,\n customFields,\n options: {\n useCustomFieldsEntries: sadotOptions.useCustomFieldsEntries,\n transaction: options.transaction,\n modelOptions,\n },\n });\n\n // Remove customFields from fields array after handling\n fields!.splice(customFieldsIdx, 1);\n};\n\n/**\n * Hook to handle validation and custom fields during update\n */\nexport const beforeUpdate = (\n scopeAttributes: string[],\n modelOptions: ModelOptions = {},\n sadotOptions: HookSadotOptions = { useCustomFieldsEntries: false },\n) => async (\n instance: any,\n options: UpdateOptions,\n): Promise<void> => {\n logger.debug('sadot - before update hook');\n const { fields } = options;\n const modelType = instance.constructor.name;\n const identifiers = applyScopeToInstance(instance, scopeAttributes);\n\n const fieldDefinitions = await getFieldDefinitions({\n modelType, modelOptions, identifiers, options, instance, sadotOptions,\n });\n\n // Step 1: Validate the model data (including custom fields)\n await validateModel(instance, options as TransactionOptions, scopeAttributes, modelOptions, false);\n\n // format date and datetime fields\n formatDates(fieldDefinitions, instance);\n\n // Step 2: Update custom field values if they exist\n const customFieldsIdx = fields!.indexOf('customFields');\n if (customFieldsIdx > -1) {\n const { customFields } = instance;\n\n if (!Object.keys(customFields).length) {\n return;\n }\n\n // Save custom field values\n await updateInstanceValues({\n modelId: instance.id,\n modelType,\n identifiers,\n customFields,\n options: {\n useCustomFieldsEntries: sadotOptions.useCustomFieldsEntries,\n transaction: options.transaction,\n modelOptions,\n },\n });\n\n // Remove customFields from fields array after handling\n fields!.splice(customFieldsIdx, 1);\n }\n};\n\n/**\n * Hook to enable individual hooks for bulk create operations\n */\nexport const beforeBulkCreate = (options: BulkCreateOptions): void => {\n // This will activate the beforeCreate hook on each instance\n options.individualHooks = true;\n};\n\n/**\n * Hook to enable individual hooks for bulk update operations\n */\nexport const beforeBulkUpdate = (options: UpdateOptions): void => {\n // This will activate the beforeUpdate hook on each instance\n options.individualHooks = true;\n};\n"],"mappings":"6jBAwBA,MAAM,EAAsC,CAAC,KAAM,SAAU,YAAa,WAAY,WAAW,CAG3F,EAAM,IAAI,EAAI,CAClB,UAAW,GACX,OAAQ,GACR,YAAa,GACb,MAA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EAAS,GAClB,YACA,cACA,eACA,QAAS,CACP,uBAAwB,EAAa,uBACrC,YAAa,EAAQ,YACrB,eACD,CACF,CAAC,CAGF,EAAQ,OAAO,EAAiB,EAAE,GAOzB,EAAoB,GAAqC,CAEpE,EAAQ,gBAAkB,IAMf,EAAoB,GAAiC,CAEhE,EAAQ,gBAAkB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require(`./enrich.cjs`),t=require(`./find.cjs`),n=require(`./hooks.cjs`);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"./enrich.js";import{beforeFind as t}from"./find.js";import{beforeBulkCreate as n,beforeBulkUpdate as r,beforeCreate as i,beforeUpdate as a}from"./hooks.js";export{};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require(`../../repository/value.cjs`),t=require(`../../repository/entries.cjs`),n=async({modelId:n,modelType:r,identifiers:i,customFields:a,options:o={modelOptions:{},useCustomFieldsEntries:!1}})=>{if(await e.updateValues(r,n,i,a,{...o,modelOptions:o.modelOptions??{}}),!o?.useCustomFieldsEntries)return;let{dataValues:{customFields:s}}=await t.findEntriesByModelId(n,o)??{dataValues:{}},c={...s,...a};await t.updateEntries(n,r,c,i,{...o,modelOptions:o.modelOptions??{}})};var r=n;exports.default=r;
|
|
2
|
+
//# sourceMappingURL=updateInstanceValues.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"updateInstanceValues.cjs","names":[],"sources":["../../../src/hooks/utils/updateInstanceValues.ts"],"sourcesContent":["import type { Transaction } from 'sequelize';\nimport * as ValueRepo from '../../repository/value';\nimport * as EntriesRepo from '../../repository/entries';\nimport type { ModelOptions } from '../../types';\n\ninterface UpdateInstanceValuesParams {\n modelId: string;\n modelType: string;\n identifiers: string[];\n customFields: Record<string, any>;\n options?: {\n transaction?: Transaction | null;\n modelOptions?: ModelOptions;\n useCustomFieldsEntries?: boolean;\n };\n}\n\nconst updateInstanceValues = async ({\n modelId,\n modelType,\n identifiers,\n customFields,\n options = {\n modelOptions: {},\n useCustomFieldsEntries: false,\n },\n}: UpdateInstanceValuesParams): Promise<void> => {\n await ValueRepo.updateValues(\n modelType,\n modelId,\n identifiers,\n customFields,\n {\n ...options,\n modelOptions: options.modelOptions ?? {},\n },\n );\n\n /*\n T.Y TODO - Once we're ready to switch from custom_field_values to custom_field_entries, we should remove the ValueRepo.updateValues call.\n Currently, We're updating both tables to keep the data in sync, but not all microservices are using the new table yet.\n */\n\n if (!options?.useCustomFieldsEntries) {\n return;\n }\n\n const { dataValues: { customFields: oldCustomFields } } = await EntriesRepo.findEntriesByModelId(modelId, options) ?? { dataValues: {} };\n const newCustomFields = { ...oldCustomFields, ...customFields };\n\n await EntriesRepo.updateEntries(\n modelId,\n modelType,\n newCustomFields,\n identifiers,\n {\n ...options,\n modelOptions: options.modelOptions ?? {},\n },\n );\n};\n\nexport default updateInstanceValues;\n"],"mappings":"wFAiBM,EAAuB,MAAO,CAClC,UACA,YACA,cACA,eACA,UAAU,CACR,aAAc,EAAE,CAChB,uBAAwB,GACzB,IAC8C,CAiB/C,GAhBA,MAAA,EAAA,aACE,EACA,EACA,EACA,EACA,CACE,GAAG,EACH,aAAc,EAAQ,cAAgB,EAAE,CACzC,CACF,CAOG,CAAC,GAAS,uBACZ,OAGF,GAAM,CAAE,WAAY,CAAE,aAAc,IAAsB,MAAA,EAAA,qBAAuC,EAAS,EAAQ,EAAI,CAAE,WAAY,EAAE,CAAE,CAClI,EAAkB,CAAE,GAAG,EAAiB,GAAG,EAAc,CAE/D,MAAA,EAAA,cACE,EACA,EACA,EACA,EACA,CACE,GAAG,EACH,aAAc,EAAQ,cAAgB,EAAE,CACzC,CACF,EAGH,IAAA,EAAe"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{updateValues as e}from"../../repository/value.js";import{findEntriesByModelId as t,updateEntries as n}from"../../repository/entries.js";var r=async({modelId:r,modelType:i,identifiers:a,customFields:o,options:s={modelOptions:{},useCustomFieldsEntries:!1}})=>{if(await e(i,r,a,o,{...s,modelOptions:s.modelOptions??{}}),!s?.useCustomFieldsEntries)return;let{dataValues:{customFields:c}}=await t(r,s)??{dataValues:{}};await n(r,i,{...c,...o},a,{...s,modelOptions:s.modelOptions??{}})};export{r as default};
|
|
2
|
+
//# sourceMappingURL=updateInstanceValues.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"updateInstanceValues.js","names":["ValueRepo.updateValues","EntriesRepo.findEntriesByModelId","EntriesRepo.updateEntries"],"sources":["../../../src/hooks/utils/updateInstanceValues.ts"],"sourcesContent":["import type { Transaction } from 'sequelize';\nimport * as ValueRepo from '../../repository/value';\nimport * as EntriesRepo from '../../repository/entries';\nimport type { ModelOptions } from '../../types';\n\ninterface UpdateInstanceValuesParams {\n modelId: string;\n modelType: string;\n identifiers: string[];\n customFields: Record<string, any>;\n options?: {\n transaction?: Transaction | null;\n modelOptions?: ModelOptions;\n useCustomFieldsEntries?: boolean;\n };\n}\n\nconst updateInstanceValues = async ({\n modelId,\n modelType,\n identifiers,\n customFields,\n options = {\n modelOptions: {},\n useCustomFieldsEntries: false,\n },\n}: UpdateInstanceValuesParams): Promise<void> => {\n await ValueRepo.updateValues(\n modelType,\n modelId,\n identifiers,\n customFields,\n {\n ...options,\n modelOptions: options.modelOptions ?? {},\n },\n );\n\n /*\n T.Y TODO - Once we're ready to switch from custom_field_values to custom_field_entries, we should remove the ValueRepo.updateValues call.\n Currently, We're updating both tables to keep the data in sync, but not all microservices are using the new table yet.\n */\n\n if (!options?.useCustomFieldsEntries) {\n return;\n }\n\n const { dataValues: { customFields: oldCustomFields } } = await EntriesRepo.findEntriesByModelId(modelId, options) ?? { dataValues: {} };\n const newCustomFields = { ...oldCustomFields, ...customFields };\n\n await EntriesRepo.updateEntries(\n modelId,\n modelType,\n newCustomFields,\n identifiers,\n {\n ...options,\n modelOptions: options.modelOptions ?? {},\n },\n );\n};\n\nexport default updateInstanceValues;\n"],"mappings":"+IA8DA,IAAA,EA7C6B,MAAO,CAClC,UACA,YACA,cACA,eACA,UAAU,CACR,aAAc,EAAE,CAChB,uBAAwB,GACzB,IAC8C,CAiB/C,GAhBA,MAAMA,EACJ,EACA,EACA,EACA,EACA,CACE,GAAG,EACH,aAAc,EAAQ,cAAgB,EAAE,CACzC,CACF,CAOG,CAAC,GAAS,uBACZ,OAGF,GAAM,CAAE,WAAY,CAAE,aAAc,IAAsB,MAAMC,EAAiC,EAAS,EAAQ,EAAI,CAAE,WAAY,EAAE,CAAE,CAGxI,MAAMC,EACJ,EACA,EAJsB,CAAE,GAAG,EAAiB,GAAG,EAAc,CAM7D,EACA,CACE,GAAG,EACH,aAAc,EAAQ,cAAgB,EAAE,CACzC,CACF"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,87 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,
|
|
2
|
-
|
|
3
|
-
const require_index$1 = require('./packages/sadot/src/utils/constants/index.cjs');
|
|
4
|
-
const require_CustomFieldValue = require('./packages/sadot/src/models/CustomFieldValue.cjs');
|
|
5
|
-
const require_CustomFieldDefinition = require('./packages/sadot/src/models/CustomFieldDefinition.cjs');
|
|
6
|
-
const require_CustomFieldEntries = require('./packages/sadot/src/models/CustomFieldEntries.cjs');
|
|
7
|
-
const require_CustomValidator = require('./packages/sadot/src/models/CustomValidator.cjs');
|
|
8
|
-
const require_index$2 = require('./packages/sadot/src/migrations/index.cjs');
|
|
9
|
-
const require_index$3 = require('./packages/sadot/src/models/index.cjs');
|
|
10
|
-
const require_mat_path_state = require('./packages/sadot/src/mat-path-state.cjs');
|
|
11
|
-
const require_FieldPolicy = require('./packages/sadot/src/models/FieldPolicy.cjs');
|
|
12
|
-
const require_field_policy = require('./packages/sadot/src/repository/field-policy.cjs');
|
|
13
|
-
const require_index$4 = require('./packages/sadot/src/api/v1/templates/index.cjs');
|
|
14
|
-
const require_index$5 = require('./packages/sadot/src/api/index.cjs');
|
|
15
|
-
const require_index$6 = require('./packages/sadot/src/utils/db/index.cjs');
|
|
16
|
-
const require_index$7 = require('./packages/sadot/src/utils/helpers/index.cjs');
|
|
17
|
-
const require_filter = require('./packages/sadot/src/scopes/filter.cjs');
|
|
18
|
-
const require_init = require('./packages/sadot/src/utils/init.cjs');
|
|
19
|
-
const require_init_state = require('./packages/sadot/src/init-state.cjs');
|
|
20
|
-
const require_custom_fields = require('./packages/sadot/src/utils/validations/schema/custom-fields.cjs');
|
|
21
|
-
|
|
22
|
-
//#region src/index.ts
|
|
23
|
-
const sadotInitState = new require_init_state.SadotInitializationState();
|
|
24
|
-
/**
|
|
25
|
-
* Internal implementation of custom fields initialization
|
|
26
|
-
* Contains all the business logic without state tracking
|
|
27
|
-
*/
|
|
28
|
-
const internalUseCustomFields = async (app, getModel, options) => {
|
|
29
|
-
require_index.tryAddingTraceIdMiddleware();
|
|
30
|
-
const { models, useCustomFieldsEntries, useModelTypeMapping, isMatPathEnabled, runLegacyMigrations } = options;
|
|
31
|
-
require_mat_path_state.matPathState.isMatPathEnabled = isMatPathEnabled;
|
|
32
|
-
if (app) {
|
|
33
|
-
app.use("/api", require_index$5.default);
|
|
34
|
-
app.use("/api/v1/templates", require_index$4.default);
|
|
35
|
-
}
|
|
36
|
-
const sequelize = options.sequelize ?? require_index$6.default(options.databaseConfig);
|
|
37
|
-
if (process.env.NODE_ENV === "test") await require_index$3.initTestModels(sequelize);
|
|
38
|
-
sequelize.addModels([require_FieldPolicy.default]);
|
|
39
|
-
require_init.addHooks(models, getModel, { useCustomFieldsEntries });
|
|
40
|
-
await require_index$3.initTables(sequelize, options.getUser, {
|
|
41
|
-
useCustomFieldsEntries,
|
|
42
|
-
useModelTypeMapping,
|
|
43
|
-
isMatPathEnabled,
|
|
44
|
-
runLegacyMigrations
|
|
45
|
-
});
|
|
46
|
-
await require_index$2.runSadotMigrations(sequelize);
|
|
47
|
-
require_init.addScopes(models, getModel, { useCustomFieldsEntries });
|
|
48
|
-
require_init.applyCustomAssociation(models);
|
|
49
|
-
require_index.default.debug("sadot - custom fields finished initializing with models", models);
|
|
50
|
-
return sequelize;
|
|
51
|
-
};
|
|
52
|
-
/**
|
|
53
|
-
* Adding custom fields enrichment to the models inside the MODELS_FILE_NAME json file
|
|
54
|
-
* @see {@link 'custom-fields/config'} for configurations
|
|
55
|
-
*/
|
|
56
|
-
const useCustomFields = async (app, getModel, options) => {
|
|
57
|
-
const initPromise = internalUseCustomFields(app, getModel, options);
|
|
58
|
-
sadotInitState.setInitPromise(initPromise, !options.sequelize);
|
|
59
|
-
return await initPromise;
|
|
60
|
-
};
|
|
61
|
-
var src_default = useCustomFields;
|
|
62
|
-
const disableCustomFields = (models, getModel) => {
|
|
63
|
-
require_init.removeHooks(models, getModel);
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
//#endregion
|
|
67
|
-
exports.CUSTOM_FIELDS_FILTER_SCOPE = require_index$1.CUSTOM_FIELDS_FILTER_SCOPE;
|
|
68
|
-
exports.CustomFieldDefinition = require_CustomFieldDefinition.default;
|
|
69
|
-
exports.CustomFieldDefinitionType = require_index$1.CustomFieldDefinitionType;
|
|
70
|
-
exports.CustomFieldEntries = require_CustomFieldEntries.default;
|
|
71
|
-
exports.CustomFieldValue = require_CustomFieldValue.default;
|
|
72
|
-
exports.CustomFieldsSchema = require_custom_fields.CustomFieldsSchema;
|
|
73
|
-
exports.CustomValidator = require_CustomValidator.default;
|
|
74
|
-
exports.FieldPolicy = require_FieldPolicy.default;
|
|
75
|
-
Object.defineProperty(exports, 'FieldPolicyRepo', {
|
|
76
|
-
enumerable: true,
|
|
77
|
-
get: function () {
|
|
78
|
-
return require_field_policy.field_policy_exports;
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
exports.customFieldsSortScope = require_filter.customFieldsSortScope;
|
|
82
|
-
exports.default = src_default;
|
|
83
|
-
exports.disableCustomFields = disableCustomFields;
|
|
84
|
-
exports.generateCustomFieldSearchQueryPayload = require_index$7.generateCustomFieldSearchQueryPayload;
|
|
85
|
-
exports.generateRandomString = require_index$7.generateRandomString;
|
|
86
|
-
exports.sadotInitState = sadotInitState;
|
|
87
|
-
exports.supportedEntities = require_index$1.supportedEntities;
|
|
1
|
+
Object.defineProperty(exports,`__esModule`,{value:!0});const e=require(`./utils/logger/index.cjs`),t=require(`./utils/constants/index.cjs`),n=require(`./models/CustomFieldValue.cjs`),r=require(`./models/CustomFieldDefinition.cjs`),i=require(`./models/CustomFieldEntries.cjs`),a=require(`./models/CustomValidator.cjs`),o=require(`./models/index.cjs`),s=require(`./mat-path-state.cjs`),c=require(`./api/index.cjs`),l=require(`./utils/db/index.cjs`),u=require(`./utils/helpers/index.cjs`),d=require(`./scopes/filter.cjs`),f=require(`./utils/init.cjs`),p=require(`./init-state.cjs`),m=require(`./utils/validations/schema/custom-fields.cjs`),h=new p.SadotInitializationState,g=async(t,n,r)=>{e.tryAddingTraceIdMiddleware();let{models:i,useCustomFieldsEntries:a,useModelTypeMapping:u,isMatPathEnabled:d,runLegacyMigrations:p}=r;s.matPathState.isMatPathEnabled=d,t&&t.use(`/api`,c.default);let m=r.sequelize??l.default(r.databaseConfig);return process.env.NODE_ENV===`test`&&await o.initTestModels(m),f.addHooks(i,n,{useCustomFieldsEntries:a}),await o.initTables(m,r.getUser,{useCustomFieldsEntries:a,useModelTypeMapping:u,isMatPathEnabled:d,runLegacyMigrations:p}),f.addScopes(i,n,{useCustomFieldsEntries:a}),f.applyCustomAssociation(i),e.default.debug(`sadot - custom fields finished initializing with models`,i),m},_=async(e,t,n)=>{let r=g(e,t,n);return h.setInitPromise(r,!n.sequelize),await r};var v=_;const y=(e,t)=>{f.removeHooks(e,t)};exports.CUSTOM_FIELDS_FILTER_SCOPE=t.CUSTOM_FIELDS_FILTER_SCOPE,exports.CustomFieldDefinition=r.default,exports.CustomFieldDefinitionType=t.CustomFieldDefinitionType,exports.CustomFieldEntries=i.default,exports.CustomFieldValue=n.default,exports.CustomFieldsSchema=m.CustomFieldsSchema,exports.CustomValidator=a.default,exports.customFieldsSortScope=d.customFieldsSortScope,exports.default=v,exports.disableCustomFields=y,exports.generateCustomFieldSearchQueryPayload=u.generateCustomFieldSearchQueryPayload,exports.generateRandomString=u.generateRandomString,exports.sadotInitState=h,exports.supportedEntities=t.supportedEntities;
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["sadotInitState: SadotInitializationState","SadotInitializationState","api","initDB","initTestModels","initTables"],"sources":["../src/index.ts"],"sourcesContent":["import type { Application } from 'express';\nimport type { Sequelize } from 'sequelize-typescript';\nimport {\n initTables, initTestModels,\n} from './models';\nimport api from './api';\nimport initDB from './utils/db';\nimport logger, { tryAddingTraceIdMiddleware } from './utils/logger';\nimport type { CustomFieldOptions, ModelFetcher, Models } from './types';\nimport {\n addHooks, addScopes, applyCustomAssociation, removeHooks,\n} from './utils/init';\nimport { SadotInitializationState } from './init-state';\nimport { matPathState } from './mat-path-state';\n\nexport * from './utils/validations/schema/custom-fields';\n\nexport * from './utils/constants';\n\nexport * from './utils/helpers';\n\nexport { customFieldsSortScope } from './scopes/filter';\nexport {\n CustomFieldDefinition,\n CustomFieldEntries,\n CustomFieldValue,\n CustomValidator,\n} from './models';\n\nexport const sadotInitState: SadotInitializationState = new SadotInitializationState();\n\n/**\n * Internal implementation of custom fields initialization\n * Contains all the business logic without state tracking\n */\nconst internalUseCustomFields = async (\n app: Pick<Application, 'use'> | null,\n getModel: ModelFetcher,\n options: CustomFieldOptions,\n): Promise<Sequelize> => {\n tryAddingTraceIdMiddleware();\n const { models, useCustomFieldsEntries, useModelTypeMapping, isMatPathEnabled, runLegacyMigrations } = options;\n matPathState.isMatPathEnabled = isMatPathEnabled;\n if (app) {\n app.use('/api', api);\n }\n const sequelize = options.sequelize ?? initDB(options.databaseConfig);\n if (process.env.NODE_ENV === 'test') {\n await initTestModels(sequelize);\n }\n // The order is important\n addHooks(models, getModel, { useCustomFieldsEntries });\n await initTables(sequelize, options.getUser, { useCustomFieldsEntries, useModelTypeMapping, isMatPathEnabled, runLegacyMigrations });\n addScopes(models, getModel, { useCustomFieldsEntries });\n applyCustomAssociation(models);\n\n logger.debug('sadot - custom fields finished initializing with models', models);\n return sequelize;\n};\n\n/**\n * Adding custom fields enrichment to the models inside the MODELS_FILE_NAME json file\n * @see {@link 'custom-fields/config'} for configurations\n */\nconst useCustomFields = async (\n app: Pick<Application, 'use'> | null,\n getModel: ModelFetcher,\n options: CustomFieldOptions,\n): Promise<Sequelize> => {\n const initPromise = internalUseCustomFields(app, getModel, options);\n\n sadotInitState.setInitPromise(initPromise, !options.sequelize);\n\n return await initPromise;\n};\n\nexport default useCustomFields;\n\nexport const disableCustomFields = (models: Models[], getModel: ModelFetcher): void => {\n removeHooks(models, getModel);\n};\n"],"mappings":"6nBA6BaA,EAA2C,IAAIC,EAAAA,yBAMtD,EAA0B,MAC9B,EACA,EACA,IACuB,CACvB,EAAA,4BAA4B,CAC5B,GAAM,CAAE,SAAQ,yBAAwB,sBAAqB,mBAAkB,uBAAwB,EACvG,EAAA,aAAa,iBAAmB,EAC5B,GACF,EAAI,IAAI,OAAQC,EAAAA,QAAI,CAEtB,IAAM,EAAY,EAAQ,WAAaC,EAAAA,QAAO,EAAQ,eAAe,CAWrE,OAVI,QAAQ,IAAI,WAAa,QAC3B,MAAMC,EAAAA,eAAe,EAAU,CAGjC,EAAA,SAAS,EAAQ,EAAU,CAAE,yBAAwB,CAAC,CACtD,MAAMC,EAAAA,WAAW,EAAW,EAAQ,QAAS,CAAE,yBAAwB,sBAAqB,mBAAkB,sBAAqB,CAAC,CACpI,EAAA,UAAU,EAAQ,EAAU,CAAE,yBAAwB,CAAC,CACvD,EAAA,uBAAuB,EAAO,CAE9B,EAAA,QAAO,MAAM,0DAA2D,EAAO,CACxE,GAOH,EAAkB,MACtB,EACA,EACA,IACuB,CACvB,IAAM,EAAc,EAAwB,EAAK,EAAU,EAAQ,CAInE,OAFA,EAAe,eAAe,EAAa,CAAC,EAAQ,UAAU,CAEvD,MAAM,GAGf,IAAA,EAAe,EAEf,MAAa,GAAuB,EAAkB,IAAiC,CACrF,EAAA,YAAY,EAAQ,EAAS"}
|
package/dist/index.d.cts
CHANGED
|
@@ -8,8 +8,7 @@ import { CustomFieldsSchema } from "./utils/validations/schema/custom-fields.cjs
|
|
|
8
8
|
import { generateCustomFieldSearchQueryPayload, generateRandomString } from "./utils/helpers/index.cjs";
|
|
9
9
|
import { customFieldsSortScope } from "./scopes/filter.cjs";
|
|
10
10
|
import { CustomFieldEntries } from "./models/CustomFieldEntries.cjs";
|
|
11
|
-
import
|
|
12
|
-
import { field_policy_d_exports } from "./repository/field-policy.cjs";
|
|
11
|
+
import "./models/index.cjs";
|
|
13
12
|
import { Application } from "express";
|
|
14
13
|
import { Sequelize } from "sequelize-typescript";
|
|
15
14
|
|
|
@@ -22,4 +21,5 @@ declare const sadotInitState: SadotInitializationState;
|
|
|
22
21
|
declare const useCustomFields: (app: Pick<Application, "use"> | null, getModel: ModelFetcher, options: CustomFieldOptions) => Promise<Sequelize>;
|
|
23
22
|
declare const disableCustomFields: (models: Models[], getModel: ModelFetcher) => void;
|
|
24
23
|
//#endregion
|
|
25
|
-
export { CUSTOM_FIELDS_FILTER_SCOPE, CustomFieldDefinition, CustomFieldDefinitionType, CustomFieldEntries, CustomFieldValue, CustomFieldsSchema, CustomValidator,
|
|
24
|
+
export { CUSTOM_FIELDS_FILTER_SCOPE, CustomFieldDefinition, CustomFieldDefinitionType, CustomFieldEntries, CustomFieldValue, CustomFieldsSchema, CustomValidator, customFieldsSortScope, useCustomFields as default, disableCustomFields, generateCustomFieldSearchQueryPayload, generateRandomString, sadotInitState, supportedEntities };
|
|
25
|
+
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import { CUSTOM_FIELDS_FILTER_SCOPE, CustomFieldDefinitionType, supportedEntities } from "./
|
|
2
|
-
import { CustomFieldValue } from "./
|
|
3
|
-
import { CustomFieldDefinition } from "./
|
|
4
|
-
import { CustomValidator } from "./
|
|
5
|
-
import { CustomFieldOptions, ModelFetcher, Models } from "./
|
|
6
|
-
import { SadotInitializationState } from "./
|
|
7
|
-
import { CustomFieldsSchema } from "./
|
|
8
|
-
import { generateCustomFieldSearchQueryPayload, generateRandomString } from "./
|
|
9
|
-
import { customFieldsSortScope } from "./
|
|
10
|
-
import { CustomFieldEntries } from "./
|
|
11
|
-
import "./
|
|
12
|
-
import { FieldPolicy, ModelInclusion, ModelMode } from "./packages/sadot/src/models/FieldPolicy.js";
|
|
13
|
-
import { field_policy_d_exports } from "./packages/sadot/src/repository/field-policy.js";
|
|
1
|
+
import { CUSTOM_FIELDS_FILTER_SCOPE, CustomFieldDefinitionType, supportedEntities } from "./utils/constants/index.js";
|
|
2
|
+
import { CustomFieldValue } from "./models/CustomFieldValue.js";
|
|
3
|
+
import { CustomFieldDefinition } from "./models/CustomFieldDefinition.js";
|
|
4
|
+
import { CustomValidator } from "./models/CustomValidator.js";
|
|
5
|
+
import { CustomFieldOptions, ModelFetcher, Models } from "./types/index.js";
|
|
6
|
+
import { SadotInitializationState } from "./init-state.js";
|
|
7
|
+
import { CustomFieldsSchema } from "./utils/validations/schema/custom-fields.js";
|
|
8
|
+
import { generateCustomFieldSearchQueryPayload, generateRandomString } from "./utils/helpers/index.js";
|
|
9
|
+
import { customFieldsSortScope } from "./scopes/filter.js";
|
|
10
|
+
import { CustomFieldEntries } from "./models/CustomFieldEntries.js";
|
|
11
|
+
import "./models/index.js";
|
|
14
12
|
import { Sequelize } from "sequelize-typescript";
|
|
15
13
|
import { Application } from "express";
|
|
16
14
|
|
|
@@ -23,4 +21,5 @@ declare const sadotInitState: SadotInitializationState;
|
|
|
23
21
|
declare const useCustomFields: (app: Pick<Application, "use"> | null, getModel: ModelFetcher, options: CustomFieldOptions) => Promise<Sequelize>;
|
|
24
22
|
declare const disableCustomFields: (models: Models[], getModel: ModelFetcher) => void;
|
|
25
23
|
//#endregion
|
|
26
|
-
export { CUSTOM_FIELDS_FILTER_SCOPE, CustomFieldDefinition, CustomFieldDefinitionType, CustomFieldEntries, CustomFieldValue, CustomFieldsSchema, CustomValidator,
|
|
24
|
+
export { CUSTOM_FIELDS_FILTER_SCOPE, CustomFieldDefinition, CustomFieldDefinitionType, CustomFieldEntries, CustomFieldValue, CustomFieldsSchema, CustomValidator, customFieldsSortScope, useCustomFields as default, disableCustomFields, generateCustomFieldSearchQueryPayload, generateRandomString, sadotInitState, supportedEntities };
|
|
25
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,66 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import CustomFieldValue_default from "./packages/sadot/src/models/CustomFieldValue.js";
|
|
4
|
-
import CustomFieldDefinition_default from "./packages/sadot/src/models/CustomFieldDefinition.js";
|
|
5
|
-
import CustomFieldEntries_default from "./packages/sadot/src/models/CustomFieldEntries.js";
|
|
6
|
-
import CustomValidator_default from "./packages/sadot/src/models/CustomValidator.js";
|
|
7
|
-
import { runSadotMigrations } from "./packages/sadot/src/migrations/index.js";
|
|
8
|
-
import { initTables, initTestModels } from "./packages/sadot/src/models/index.js";
|
|
9
|
-
import { matPathState } from "./packages/sadot/src/mat-path-state.js";
|
|
10
|
-
import FieldPolicy_default from "./packages/sadot/src/models/FieldPolicy.js";
|
|
11
|
-
import { field_policy_exports } from "./packages/sadot/src/repository/field-policy.js";
|
|
12
|
-
import templates_default from "./packages/sadot/src/api/v1/templates/index.js";
|
|
13
|
-
import api_default from "./packages/sadot/src/api/index.js";
|
|
14
|
-
import db_default from "./packages/sadot/src/utils/db/index.js";
|
|
15
|
-
import { generateCustomFieldSearchQueryPayload, generateRandomString } from "./packages/sadot/src/utils/helpers/index.js";
|
|
16
|
-
import { customFieldsSortScope } from "./packages/sadot/src/scopes/filter.js";
|
|
17
|
-
import { addHooks, addScopes, applyCustomAssociation, removeHooks } from "./packages/sadot/src/utils/init.js";
|
|
18
|
-
import { SadotInitializationState } from "./packages/sadot/src/init-state.js";
|
|
19
|
-
import { CustomFieldsSchema } from "./packages/sadot/src/utils/validations/schema/custom-fields.js";
|
|
20
|
-
|
|
21
|
-
//#region src/index.ts
|
|
22
|
-
const sadotInitState = new SadotInitializationState();
|
|
23
|
-
/**
|
|
24
|
-
* Internal implementation of custom fields initialization
|
|
25
|
-
* Contains all the business logic without state tracking
|
|
26
|
-
*/
|
|
27
|
-
const internalUseCustomFields = async (app, getModel, options) => {
|
|
28
|
-
tryAddingTraceIdMiddleware();
|
|
29
|
-
const { models, useCustomFieldsEntries, useModelTypeMapping, isMatPathEnabled, runLegacyMigrations } = options;
|
|
30
|
-
matPathState.isMatPathEnabled = isMatPathEnabled;
|
|
31
|
-
if (app) {
|
|
32
|
-
app.use("/api", api_default);
|
|
33
|
-
app.use("/api/v1/templates", templates_default);
|
|
34
|
-
}
|
|
35
|
-
const sequelize = options.sequelize ?? db_default(options.databaseConfig);
|
|
36
|
-
if (process.env.NODE_ENV === "test") await initTestModels(sequelize);
|
|
37
|
-
sequelize.addModels([FieldPolicy_default]);
|
|
38
|
-
addHooks(models, getModel, { useCustomFieldsEntries });
|
|
39
|
-
await initTables(sequelize, options.getUser, {
|
|
40
|
-
useCustomFieldsEntries,
|
|
41
|
-
useModelTypeMapping,
|
|
42
|
-
isMatPathEnabled,
|
|
43
|
-
runLegacyMigrations
|
|
44
|
-
});
|
|
45
|
-
await runSadotMigrations(sequelize);
|
|
46
|
-
addScopes(models, getModel, { useCustomFieldsEntries });
|
|
47
|
-
applyCustomAssociation(models);
|
|
48
|
-
logger_default.debug("sadot - custom fields finished initializing with models", models);
|
|
49
|
-
return sequelize;
|
|
50
|
-
};
|
|
51
|
-
/**
|
|
52
|
-
* Adding custom fields enrichment to the models inside the MODELS_FILE_NAME json file
|
|
53
|
-
* @see {@link 'custom-fields/config'} for configurations
|
|
54
|
-
*/
|
|
55
|
-
const useCustomFields = async (app, getModel, options) => {
|
|
56
|
-
const initPromise = internalUseCustomFields(app, getModel, options);
|
|
57
|
-
sadotInitState.setInitPromise(initPromise, !options.sequelize);
|
|
58
|
-
return await initPromise;
|
|
59
|
-
};
|
|
60
|
-
var src_default = useCustomFields;
|
|
61
|
-
const disableCustomFields = (models, getModel) => {
|
|
62
|
-
removeHooks(models, getModel);
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
//#endregion
|
|
66
|
-
export { CUSTOM_FIELDS_FILTER_SCOPE, CustomFieldDefinition_default as CustomFieldDefinition, CustomFieldDefinitionType, CustomFieldEntries_default as CustomFieldEntries, CustomFieldValue_default as CustomFieldValue, CustomFieldsSchema, CustomValidator_default as CustomValidator, FieldPolicy_default as FieldPolicy, field_policy_exports as FieldPolicyRepo, customFieldsSortScope, src_default as default, disableCustomFields, generateCustomFieldSearchQueryPayload, generateRandomString, sadotInitState, supportedEntities };
|
|
1
|
+
import e,{tryAddingTraceIdMiddleware as t}from"./utils/logger/index.js";import{CUSTOM_FIELDS_FILTER_SCOPE as n,CustomFieldDefinitionType as r,supportedEntities as i}from"./utils/constants/index.js";import a from"./models/CustomFieldValue.js";import o from"./models/CustomFieldDefinition.js";import s from"./models/CustomFieldEntries.js";import c from"./models/CustomValidator.js";import{initTables as l,initTestModels as u}from"./models/index.js";import{matPathState as d}from"./mat-path-state.js";import f from"./api/index.js";import p from"./utils/db/index.js";import{generateCustomFieldSearchQueryPayload as m,generateRandomString as h}from"./utils/helpers/index.js";import{customFieldsSortScope as g}from"./scopes/filter.js";import{addHooks as _,addScopes as v,applyCustomAssociation as y,removeHooks as b}from"./utils/init.js";import{SadotInitializationState as x}from"./init-state.js";import{CustomFieldsSchema as S}from"./utils/validations/schema/custom-fields.js";const C=new x,w=async(n,r,i)=>{t();let{models:a,useCustomFieldsEntries:o,useModelTypeMapping:s,isMatPathEnabled:c,runLegacyMigrations:m}=i;d.isMatPathEnabled=c,n&&n.use(`/api`,f);let h=i.sequelize??p(i.databaseConfig);return process.env.NODE_ENV===`test`&&await u(h),_(a,r,{useCustomFieldsEntries:o}),await l(h,i.getUser,{useCustomFieldsEntries:o,useModelTypeMapping:s,isMatPathEnabled:c,runLegacyMigrations:m}),v(a,r,{useCustomFieldsEntries:o}),y(a),e.debug(`sadot - custom fields finished initializing with models`,a),h};var T=async(e,t,n)=>{let r=w(e,t,n);return C.setInitPromise(r,!n.sequelize),await r};const E=(e,t)=>{b(e,t)};export{n as CUSTOM_FIELDS_FILTER_SCOPE,o as CustomFieldDefinition,r as CustomFieldDefinitionType,s as CustomFieldEntries,a as CustomFieldValue,S as CustomFieldsSchema,c as CustomValidator,g as customFieldsSortScope,T as default,E as disableCustomFields,m as generateCustomFieldSearchQueryPayload,h as generateRandomString,C as sadotInitState,i as supportedEntities};
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["sadotInitState: SadotInitializationState","api","initDB"],"sources":["../src/index.ts"],"sourcesContent":["import type { Application } from 'express';\nimport type { Sequelize } from 'sequelize-typescript';\nimport {\n initTables, initTestModels,\n} from './models';\nimport api from './api';\nimport initDB from './utils/db';\nimport logger, { tryAddingTraceIdMiddleware } from './utils/logger';\nimport type { CustomFieldOptions, ModelFetcher, Models } from './types';\nimport {\n addHooks, addScopes, applyCustomAssociation, removeHooks,\n} from './utils/init';\nimport { SadotInitializationState } from './init-state';\nimport { matPathState } from './mat-path-state';\n\nexport * from './utils/validations/schema/custom-fields';\n\nexport * from './utils/constants';\n\nexport * from './utils/helpers';\n\nexport { customFieldsSortScope } from './scopes/filter';\nexport {\n CustomFieldDefinition,\n CustomFieldEntries,\n CustomFieldValue,\n CustomValidator,\n} from './models';\n\nexport const sadotInitState: SadotInitializationState = new SadotInitializationState();\n\n/**\n * Internal implementation of custom fields initialization\n * Contains all the business logic without state tracking\n */\nconst internalUseCustomFields = async (\n app: Pick<Application, 'use'> | null,\n getModel: ModelFetcher,\n options: CustomFieldOptions,\n): Promise<Sequelize> => {\n tryAddingTraceIdMiddleware();\n const { models, useCustomFieldsEntries, useModelTypeMapping, isMatPathEnabled, runLegacyMigrations } = options;\n matPathState.isMatPathEnabled = isMatPathEnabled;\n if (app) {\n app.use('/api', api);\n }\n const sequelize = options.sequelize ?? initDB(options.databaseConfig);\n if (process.env.NODE_ENV === 'test') {\n await initTestModels(sequelize);\n }\n // The order is important\n addHooks(models, getModel, { useCustomFieldsEntries });\n await initTables(sequelize, options.getUser, { useCustomFieldsEntries, useModelTypeMapping, isMatPathEnabled, runLegacyMigrations });\n addScopes(models, getModel, { useCustomFieldsEntries });\n applyCustomAssociation(models);\n\n logger.debug('sadot - custom fields finished initializing with models', models);\n return sequelize;\n};\n\n/**\n * Adding custom fields enrichment to the models inside the MODELS_FILE_NAME json file\n * @see {@link 'custom-fields/config'} for configurations\n */\nconst useCustomFields = async (\n app: Pick<Application, 'use'> | null,\n getModel: ModelFetcher,\n options: CustomFieldOptions,\n): Promise<Sequelize> => {\n const initPromise = internalUseCustomFields(app, getModel, options);\n\n sadotInitState.setInitPromise(initPromise, !options.sequelize);\n\n return await initPromise;\n};\n\nexport default useCustomFields;\n\nexport const disableCustomFields = (models: Models[], getModel: ModelFetcher): void => {\n removeHooks(models, getModel);\n};\n"],"mappings":"48BA6BA,MAAaA,EAA2C,IAAI,EAMtD,EAA0B,MAC9B,EACA,EACA,IACuB,CACvB,GAA4B,CAC5B,GAAM,CAAE,SAAQ,yBAAwB,sBAAqB,mBAAkB,uBAAwB,EACvG,EAAa,iBAAmB,EAC5B,GACF,EAAI,IAAI,OAAQC,EAAI,CAEtB,IAAM,EAAY,EAAQ,WAAaC,EAAO,EAAQ,eAAe,CAWrE,OAVI,QAAQ,IAAI,WAAa,QAC3B,MAAM,EAAe,EAAU,CAGjC,EAAS,EAAQ,EAAU,CAAE,yBAAwB,CAAC,CACtD,MAAM,EAAW,EAAW,EAAQ,QAAS,CAAE,yBAAwB,sBAAqB,mBAAkB,sBAAqB,CAAC,CACpI,EAAU,EAAQ,EAAU,CAAE,yBAAwB,CAAC,CACvD,EAAuB,EAAO,CAE9B,EAAO,MAAM,0DAA2D,EAAO,CACxE,GAmBT,IAAA,EAZwB,MACtB,EACA,EACA,IACuB,CACvB,IAAM,EAAc,EAAwB,EAAK,EAAU,EAAQ,CAInE,OAFA,EAAe,eAAe,EAAa,CAAC,EAAQ,UAAU,CAEvD,MAAM,GAKf,MAAa,GAAuB,EAAkB,IAAiC,CACrF,EAAY,EAAQ,EAAS"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var e=class{constructor(){this.initPromise=null,this.initError=null,this.isInitialized=!1,this.sequelizeInstance=null,this.ownsSequelizeInstance=!1}setInitPromise(e,t){this.initPromise=e,this.ownsSequelizeInstance=t,e.then(e=>{this.sequelizeInstance=e,this.isInitialized=!0},e=>this.initError=e)}get sequelize(){return this.sequelizeInstance}async waitForInitialization(){if(this.isInitialized&&this.sequelizeInstance)return this.ownsSequelizeInstance?this.sequelizeInstance:void 0;if(this.initError)throw this.initError;if(!this.initPromise)throw Error(`Sadot initialization has not started`);let e=await this.initPromise;if(this.initError)throw this.initError;return this.ownsSequelizeInstance?e:void 0}get isReady(){return this.isInitialized&&!this.initError}get error(){return this.initError}};exports.SadotInitializationState=e;
|
|
2
|
+
//# sourceMappingURL=init-state.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init-state.cjs","names":[],"sources":["../src/init-state.ts"],"sourcesContent":["import type { Sequelize } from 'sequelize-typescript';\n\n/**\n * Tracks the initialization state of sadot's useCustomFields function\n * Allows HealthManager to wait for initialization before passing readiness checks\n */\nexport class SadotInitializationState {\n private initPromise: Promise<Sequelize> | null = null;\n private initError: Error | null = null;\n private isInitialized = false;\n private sequelizeInstance: Sequelize | null = null;\n private ownsSequelizeInstance = false;\n\n /** Set the initialization promise */\n setInitPromise(promise: Promise<Sequelize>, ownsSequelize: boolean): void {\n this.initPromise = promise;\n this.ownsSequelizeInstance = ownsSequelize;\n\n promise.then((sequelize) => {\n this.sequelizeInstance = sequelize;\n this.isInitialized = true;\n }, error => this.initError = error);\n }\n\n /**\n * Get the Sequelize instance\n * Returns null if initialization hasn't completed yet, or in cases where it failed.\n */\n get sequelize(): Sequelize | null {\n return this.sequelizeInstance;\n }\n\n /**\n * Wait for initialization to complete and return the Sequelize instance\n * Returns the Sequelize instance only if Sadot created it (owns it)\n * Returns undefined if the Sequelize instance was provided externally\n * Rejects when initialization fails\n */\n async waitForInitialization(): Promise<Sequelize | undefined> {\n if (this.isInitialized && this.sequelizeInstance) {\n return this.ownsSequelizeInstance ? this.sequelizeInstance : undefined;\n }\n\n if (this.initError) {\n throw this.initError;\n }\n\n if (!this.initPromise) {\n throw new Error('Sadot initialization has not started');\n }\n\n const sequelize = await this.initPromise;\n\n if (this.initError) {\n throw this.initError as Error; // Since line 47 checked the truthiness, TS thinks `initError` can't be true, as it doesn't account for the async nature of the function.\n }\n\n return this.ownsSequelizeInstance ? sequelize : undefined;\n }\n\n /** Check if initialization is complete and successful */\n get isReady(): boolean {\n return this.isInitialized && !this.initError;\n }\n\n /** Get the initialization error if one occurred */\n get error(): Error | null {\n return this.initError;\n }\n}\n"],"mappings":"AAMA,IAAa,EAAb,KAAsC,gCACa,oBACf,wBACV,0BACsB,gCACd,GAGhC,eAAe,EAA6B,EAA8B,CACxE,KAAK,YAAc,EACnB,KAAK,sBAAwB,EAE7B,EAAQ,KAAM,GAAc,CAC1B,KAAK,kBAAoB,EACzB,KAAK,cAAgB,IACpB,GAAS,KAAK,UAAY,EAAM,CAOrC,IAAI,WAA8B,CAChC,OAAO,KAAK,kBASd,MAAM,uBAAwD,CAC5D,GAAI,KAAK,eAAiB,KAAK,kBAC7B,OAAO,KAAK,sBAAwB,KAAK,kBAAoB,IAAA,GAG/D,GAAI,KAAK,UACP,MAAM,KAAK,UAGb,GAAI,CAAC,KAAK,YACR,MAAU,MAAM,uCAAuC,CAGzD,IAAM,EAAY,MAAM,KAAK,YAE7B,GAAI,KAAK,UACP,MAAM,KAAK,UAGb,OAAO,KAAK,sBAAwB,EAAY,IAAA,GAIlD,IAAI,SAAmB,CACrB,OAAO,KAAK,eAAiB,CAAC,KAAK,UAIrC,IAAI,OAAsB,CACxB,OAAO,KAAK"}
|
package/dist/init-state.d.cts
CHANGED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var e=class{constructor(){this.initPromise=null,this.initError=null,this.isInitialized=!1,this.sequelizeInstance=null,this.ownsSequelizeInstance=!1}setInitPromise(e,t){this.initPromise=e,this.ownsSequelizeInstance=t,e.then(e=>{this.sequelizeInstance=e,this.isInitialized=!0},e=>this.initError=e)}get sequelize(){return this.sequelizeInstance}async waitForInitialization(){if(this.isInitialized&&this.sequelizeInstance)return this.ownsSequelizeInstance?this.sequelizeInstance:void 0;if(this.initError)throw this.initError;if(!this.initPromise)throw Error(`Sadot initialization has not started`);let e=await this.initPromise;if(this.initError)throw this.initError;return this.ownsSequelizeInstance?e:void 0}get isReady(){return this.isInitialized&&!this.initError}get error(){return this.initError}};export{e as SadotInitializationState};
|
|
2
|
+
//# sourceMappingURL=init-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init-state.js","names":[],"sources":["../src/init-state.ts"],"sourcesContent":["import type { Sequelize } from 'sequelize-typescript';\n\n/**\n * Tracks the initialization state of sadot's useCustomFields function\n * Allows HealthManager to wait for initialization before passing readiness checks\n */\nexport class SadotInitializationState {\n private initPromise: Promise<Sequelize> | null = null;\n private initError: Error | null = null;\n private isInitialized = false;\n private sequelizeInstance: Sequelize | null = null;\n private ownsSequelizeInstance = false;\n\n /** Set the initialization promise */\n setInitPromise(promise: Promise<Sequelize>, ownsSequelize: boolean): void {\n this.initPromise = promise;\n this.ownsSequelizeInstance = ownsSequelize;\n\n promise.then((sequelize) => {\n this.sequelizeInstance = sequelize;\n this.isInitialized = true;\n }, error => this.initError = error);\n }\n\n /**\n * Get the Sequelize instance\n * Returns null if initialization hasn't completed yet, or in cases where it failed.\n */\n get sequelize(): Sequelize | null {\n return this.sequelizeInstance;\n }\n\n /**\n * Wait for initialization to complete and return the Sequelize instance\n * Returns the Sequelize instance only if Sadot created it (owns it)\n * Returns undefined if the Sequelize instance was provided externally\n * Rejects when initialization fails\n */\n async waitForInitialization(): Promise<Sequelize | undefined> {\n if (this.isInitialized && this.sequelizeInstance) {\n return this.ownsSequelizeInstance ? this.sequelizeInstance : undefined;\n }\n\n if (this.initError) {\n throw this.initError;\n }\n\n if (!this.initPromise) {\n throw new Error('Sadot initialization has not started');\n }\n\n const sequelize = await this.initPromise;\n\n if (this.initError) {\n throw this.initError as Error; // Since line 47 checked the truthiness, TS thinks `initError` can't be true, as it doesn't account for the async nature of the function.\n }\n\n return this.ownsSequelizeInstance ? sequelize : undefined;\n }\n\n /** Check if initialization is complete and successful */\n get isReady(): boolean {\n return this.isInitialized && !this.initError;\n }\n\n /** Get the initialization error if one occurred */\n get error(): Error | null {\n return this.initError;\n }\n}\n"],"mappings":"AAMA,IAAa,EAAb,KAAsC,gCACa,oBACf,wBACV,0BACsB,gCACd,GAGhC,eAAe,EAA6B,EAA8B,CACxE,KAAK,YAAc,EACnB,KAAK,sBAAwB,EAE7B,EAAQ,KAAM,GAAc,CAC1B,KAAK,kBAAoB,EACzB,KAAK,cAAgB,IACpB,GAAS,KAAK,UAAY,EAAM,CAOrC,IAAI,WAA8B,CAChC,OAAO,KAAK,kBASd,MAAM,uBAAwD,CAC5D,GAAI,KAAK,eAAiB,KAAK,kBAC7B,OAAO,KAAK,sBAAwB,KAAK,kBAAoB,IAAA,GAG/D,GAAI,KAAK,UACP,MAAM,KAAK,UAGb,GAAI,CAAC,KAAK,YACR,MAAU,MAAM,uCAAuC,CAGzD,IAAM,EAAY,MAAM,KAAK,YAE7B,GAAI,KAAK,UACP,MAAM,KAAK,UAGb,OAAO,KAAK,sBAAwB,EAAY,IAAA,GAIlD,IAAI,SAAmB,CACrB,OAAO,KAAK,eAAiB,CAAC,KAAK,UAIrC,IAAI,OAAsB,CACxB,OAAO,KAAK"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mat-path-state.cjs","names":["matPathState: { isMatPathEnabled?: CustomFieldOptions['isMatPathEnabled']; }"],"sources":["../src/mat-path-state.ts"],"sourcesContent":["import type { CustomFieldOptions } from './types';\n\n/**\n * Module-scoped holder for the optional `isMatPathEnabled` predicate so route handlers can\n * read it without threading the option through every layer. Set once during `useCustomFields()`.\n */\nexport const matPathState: { isMatPathEnabled?: CustomFieldOptions['isMatPathEnabled']; } = {};\n"],"mappings":"AAMA,MAAaA,EAA+E,EAAE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mat-path-state.js","names":["matPathState: { isMatPathEnabled?: CustomFieldOptions['isMatPathEnabled']; }"],"sources":["../src/mat-path-state.ts"],"sourcesContent":["import type { CustomFieldOptions } from './types';\n\n/**\n * Module-scoped holder for the optional `isMatPathEnabled` predicate so route handlers can\n * read it without threading the option through every layer. Set once during `useCustomFields()`.\n */\nexport const matPathState: { isMatPathEnabled?: CustomFieldOptions['isMatPathEnabled']; } = {};\n"],"mappings":"AAMA,MAAaA,EAA+E,EAAE"}
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
//#region src/migrations/001-create-core-tables.ts
|
|
3
|
-
const up = async ({ context: queryInterface }) => {
|
|
4
|
-
const { sequelize } = queryInterface;
|
|
5
|
-
await sequelize.query(`
|
|
1
|
+
const e=async({context:e})=>{let{sequelize:t}=e;await t.query(`
|
|
6
2
|
CREATE TABLE IF NOT EXISTS "custom_field_definitions" (
|
|
7
3
|
"id" UUID NOT NULL DEFAULT gen_random_uuid(),
|
|
8
4
|
"name" VARCHAR NOT NULL,
|
|
@@ -22,12 +18,10 @@ const up = async ({ context: queryInterface }) => {
|
|
|
22
18
|
"deleted_at" TIMESTAMPTZ,
|
|
23
19
|
PRIMARY KEY ("id")
|
|
24
20
|
)
|
|
25
|
-
`)
|
|
26
|
-
await sequelize.query(`
|
|
21
|
+
`),await t.query(`
|
|
27
22
|
CREATE UNIQUE INDEX IF NOT EXISTS "unique_name_model_type"
|
|
28
23
|
ON "custom_field_definitions" ("model_type", "entity_id", "name")
|
|
29
|
-
`)
|
|
30
|
-
await sequelize.query(`
|
|
24
|
+
`),await t.query(`
|
|
31
25
|
CREATE TABLE IF NOT EXISTS "custom_field_values" (
|
|
32
26
|
"model_id" UUID NOT NULL,
|
|
33
27
|
"custom_field_definition_id" UUID NOT NULL
|
|
@@ -38,13 +32,11 @@ const up = async ({ context: queryInterface }) => {
|
|
|
38
32
|
"deleted_at" TIMESTAMPTZ,
|
|
39
33
|
PRIMARY KEY ("model_id", "custom_field_definition_id")
|
|
40
34
|
)
|
|
41
|
-
`)
|
|
42
|
-
await sequelize.query(`
|
|
35
|
+
`),await t.query(`
|
|
43
36
|
CREATE INDEX IF NOT EXISTS "idx_custom_field_values_active_definition_id"
|
|
44
37
|
ON "custom_field_values" ("custom_field_definition_id")
|
|
45
38
|
WHERE "deleted_at" IS NULL
|
|
46
|
-
`)
|
|
47
|
-
await sequelize.query(`
|
|
39
|
+
`),await t.query(`
|
|
48
40
|
CREATE TABLE IF NOT EXISTS "custom_validators" (
|
|
49
41
|
"id" UUID NOT NULL DEFAULT gen_random_uuid(),
|
|
50
42
|
"entity_id" UUID NOT NULL,
|
|
@@ -56,15 +48,5 @@ const up = async ({ context: queryInterface }) => {
|
|
|
56
48
|
"updated_at" TIMESTAMPTZ,
|
|
57
49
|
PRIMARY KEY ("id")
|
|
58
50
|
)
|
|
59
|
-
`);
|
|
60
|
-
|
|
61
|
-
const down = async ({ context: queryInterface }) => {
|
|
62
|
-
const { sequelize } = queryInterface;
|
|
63
|
-
await sequelize.query("DROP TABLE IF EXISTS \"custom_field_values\"");
|
|
64
|
-
await sequelize.query("DROP TABLE IF EXISTS \"custom_field_definitions\"");
|
|
65
|
-
await sequelize.query("DROP TABLE IF EXISTS \"custom_validators\"");
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
//#endregion
|
|
69
|
-
exports.down = down;
|
|
70
|
-
exports.up = up;
|
|
51
|
+
`)},t=async({context:e})=>{let{sequelize:t}=e;await t.query(`DROP TABLE IF EXISTS "custom_field_values"`),await t.query(`DROP TABLE IF EXISTS "custom_field_definitions"`),await t.query(`DROP TABLE IF EXISTS "custom_validators"`)};exports.down=t,exports.up=e;
|
|
52
|
+
//# sourceMappingURL=001-create-core-tables.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"001-create-core-tables.cjs","names":["up: MigrationFn<QueryInterface>","down: MigrationFn<QueryInterface>"],"sources":["../../src/migrations/001-create-core-tables.ts"],"sourcesContent":["import type { MigrationFn } from 'umzug';\nimport type { QueryInterface } from 'sequelize';\n\nexport const up: MigrationFn<QueryInterface> = async ({ context: queryInterface }) => {\n const { sequelize } = queryInterface;\n\n await sequelize.query(`\n CREATE TABLE IF NOT EXISTS \"custom_field_definitions\" (\n \"id\" UUID NOT NULL DEFAULT gen_random_uuid(),\n \"name\" VARCHAR NOT NULL,\n \"display_name\" VARCHAR,\n \"field_type\" VARCHAR NOT NULL,\n \"validation\" JSONB,\n \"entity_id\" UUID NOT NULL,\n \"entity_type\" VARCHAR NOT NULL,\n \"model_type\" VARCHAR NOT NULL,\n \"description\" TEXT,\n \"required\" BOOLEAN DEFAULT false,\n \"disabled\" BOOLEAN DEFAULT false,\n \"default_value\" JSONB,\n \"block_editing_from_u_i\" BOOLEAN NOT NULL DEFAULT false,\n \"created_at\" TIMESTAMPTZ NOT NULL,\n \"updated_at\" TIMESTAMPTZ,\n \"deleted_at\" TIMESTAMPTZ,\n PRIMARY KEY (\"id\")\n )\n `);\n\n await sequelize.query(`\n CREATE UNIQUE INDEX IF NOT EXISTS \"unique_name_model_type\"\n ON \"custom_field_definitions\" (\"model_type\", \"entity_id\", \"name\")\n `);\n\n await sequelize.query(`\n CREATE TABLE IF NOT EXISTS \"custom_field_values\" (\n \"model_id\" UUID NOT NULL,\n \"custom_field_definition_id\" UUID NOT NULL\n REFERENCES \"custom_field_definitions\" (\"id\") ON DELETE CASCADE ON UPDATE CASCADE,\n \"value\" JSONB,\n \"created_at\" TIMESTAMPTZ NOT NULL,\n \"updated_at\" TIMESTAMPTZ,\n \"deleted_at\" TIMESTAMPTZ,\n PRIMARY KEY (\"model_id\", \"custom_field_definition_id\")\n )\n `);\n\n await sequelize.query(`\n CREATE INDEX IF NOT EXISTS \"idx_custom_field_values_active_definition_id\"\n ON \"custom_field_values\" (\"custom_field_definition_id\")\n WHERE \"deleted_at\" IS NULL\n `);\n\n await sequelize.query(`\n CREATE TABLE IF NOT EXISTS \"custom_validators\" (\n \"id\" UUID NOT NULL DEFAULT gen_random_uuid(),\n \"entity_id\" UUID NOT NULL,\n \"entity_type\" VARCHAR NOT NULL,\n \"model_type\" VARCHAR NOT NULL,\n \"schema\" JSONB NOT NULL,\n \"disabled\" BOOLEAN NOT NULL DEFAULT false,\n \"created_at\" TIMESTAMPTZ NOT NULL,\n \"updated_at\" TIMESTAMPTZ,\n PRIMARY KEY (\"id\")\n )\n `);\n};\n\nexport const down: MigrationFn<QueryInterface> = async ({ context: queryInterface }) => {\n const { sequelize } = queryInterface;\n await sequelize.query('DROP TABLE IF EXISTS \"custom_field_values\"');\n await sequelize.query('DROP TABLE IF EXISTS \"custom_field_definitions\"');\n await sequelize.query('DROP TABLE IF EXISTS \"custom_validators\"');\n};\n"],"mappings":"AAGA,MAAaA,EAAkC,MAAO,CAAE,QAAS,KAAqB,CACpF,GAAM,CAAE,aAAc,EAEtB,MAAM,EAAU,MAAM;;;;;;;;;;;;;;;;;;;;IAoBpB,CAEF,MAAM,EAAU,MAAM;;;IAGpB,CAEF,MAAM,EAAU,MAAM;;;;;;;;;;;IAWpB,CAEF,MAAM,EAAU,MAAM;;;;IAIpB,CAEF,MAAM,EAAU,MAAM;;;;;;;;;;;;IAYpB,EAGSC,EAAoC,MAAO,CAAE,QAAS,KAAqB,CACtF,GAAM,CAAE,aAAc,EACtB,MAAM,EAAU,MAAM,6CAA6C,CACnE,MAAM,EAAU,MAAM,kDAAkD,CACxE,MAAM,EAAU,MAAM,2CAA2C"}
|