@adobe/data 0.4.5 → 0.4.7
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/README.md +310 -0
- package/dist/cache/functions/bind-functions.d.ts +6 -0
- package/dist/cache/functions/bind-functions.js +33 -0
- package/dist/cache/functions/bind-functions.js.map +1 -0
- package/dist/cache/functions/hashing/arrayBufferToHex.d.ts +1 -0
- package/dist/cache/functions/hashing/arrayBufferToHex.js +27 -0
- package/dist/cache/functions/hashing/arrayBufferToHex.js.map +1 -0
- package/dist/cache/functions/omit.d.ts +1 -0
- package/dist/cache/functions/omit.js +29 -0
- package/dist/cache/functions/omit.js.map +1 -0
- package/dist/cache/functions/types.d.ts +1 -0
- package/dist/cache/functions/types.js +23 -0
- package/dist/cache/functions/types.js.map +1 -0
- package/dist/core/data.d.ts +22 -0
- package/dist/core/data.js +52 -0
- package/dist/core/data.js.map +1 -0
- package/dist/core/data.test.js +48 -0
- package/dist/core/data.test.js.map +1 -0
- package/dist/core/functions/array-equals.d.ts +1 -0
- package/dist/core/functions/array-equals.js +34 -0
- package/dist/core/functions/array-equals.js.map +1 -0
- package/dist/core/functions/deep-merge.d.ts +32 -0
- package/dist/core/functions/deep-merge.js +54 -0
- package/dist/core/functions/deep-merge.js.map +1 -0
- package/dist/core/functions/deep-merge.test.d.ts +1 -0
- package/dist/core/functions/deep-merge.test.js +94 -0
- package/dist/core/functions/deep-merge.test.js.map +1 -0
- package/dist/core/functions/index.d.ts +3 -0
- package/dist/core/functions/index.js +25 -0
- package/dist/core/functions/index.js.map +1 -0
- package/dist/core/functions/is-async-generator.d.ts +1 -0
- package/dist/core/functions/is-async-generator.js +25 -0
- package/dist/core/functions/is-async-generator.js.map +1 -0
- package/dist/core/functions/is-promise.d.ts +1 -0
- package/dist/core/functions/is-promise.js +26 -0
- package/dist/core/functions/is-promise.js.map +1 -0
- package/dist/core/functions/with-validation.d.ts +5 -0
- package/dist/core/functions/with-validation.js +38 -0
- package/dist/core/functions/with-validation.js.map +1 -0
- package/dist/core/functions/with-validation.test.d.ts +1 -0
- package/dist/core/functions/with-validation.test.js +96 -0
- package/dist/core/functions/with-validation.test.js.map +1 -0
- package/dist/core/index.d.ts +3 -0
- package/dist/core/index.js +25 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/schema/dynamic/dynamic-schema.d.ts +27 -0
- package/dist/core/schema/dynamic/dynamic-schema.js +2 -0
- package/dist/core/schema/dynamic/dynamic-schema.js.map +1 -0
- package/dist/core/schema/dynamic/enumerate-patches.d.ts +9 -0
- package/dist/core/schema/dynamic/enumerate-patches.js +50 -0
- package/dist/core/schema/dynamic/enumerate-patches.js.map +1 -0
- package/dist/core/schema/dynamic/enumerate-patches.test.d.ts +134 -0
- package/dist/core/schema/dynamic/enumerate-patches.test.js +209 -0
- package/dist/core/schema/dynamic/enumerate-patches.test.js.map +1 -0
- package/dist/core/schema/dynamic/get-dynamic-schema.d.ts +5 -0
- package/dist/core/schema/dynamic/get-dynamic-schema.js +26 -0
- package/dist/core/schema/dynamic/get-dynamic-schema.js.map +1 -0
- package/dist/core/schema/dynamic/get-dynamic-schema.test.d.ts +1 -0
- package/dist/core/schema/dynamic/get-dynamic-schema.test.js +94 -0
- package/dist/core/schema/dynamic/get-dynamic-schema.test.js.map +1 -0
- package/dist/core/schema/dynamic/index.d.ts +1 -0
- package/dist/core/schema/dynamic/index.js +2 -0
- package/dist/core/schema/dynamic/index.js.map +1 -0
- package/dist/core/schema/dynamic/schema-path-value-path.d.ts +5 -0
- package/dist/core/schema/dynamic/schema-path-value-path.js +12 -0
- package/dist/core/schema/dynamic/schema-path-value-path.js.map +1 -0
- package/dist/core/schema/dynamic-schema.d.ts +27 -0
- package/dist/core/schema/dynamic-schema.js +2 -0
- package/dist/core/schema/dynamic-schema.js.map +1 -0
- package/dist/core/schema/index.d.ts +4 -0
- package/dist/core/schema/index.js +26 -0
- package/dist/core/schema/index.js.map +1 -0
- package/dist/core/schema/schema.d.ts +122 -0
- package/dist/core/schema/schema.js +34 -0
- package/dist/core/schema/schema.js.map +1 -0
- package/dist/core/schema/schemas.d.ts +45 -0
- package/dist/core/schema/schemas.js +39 -0
- package/dist/core/schema/schemas.js.map +1 -0
- package/dist/core/schema/ui-schema.d.ts +25 -0
- package/dist/core/schema/ui-schema.js +2 -0
- package/dist/core/schema/ui-schema.js.map +1 -0
- package/dist/core/schema/validation/is-valid.d.ts +2 -0
- package/dist/core/schema/validation/is-valid.js +14 -0
- package/dist/core/schema/validation/is-valid.js.map +1 -0
- package/dist/core/schema/validation/is-valid.test.d.ts +1 -0
- package/dist/{functions/serialization.test.js → core/schema/validation/is-valid.test.js} +16 -20
- package/dist/core/schema/validation/is-valid.test.js.map +1 -0
- package/dist/core/schema/validation/validate.d.ts +2 -0
- package/dist/core/schema/validation/validate.js +38 -0
- package/dist/core/schema/validation/validate.js.map +1 -0
- package/dist/core/schema/validation/validate.test.d.ts +1 -0
- package/dist/core/schema/validation/validate.test.js +106 -0
- package/dist/core/schema/validation/validate.test.js.map +1 -0
- package/dist/core/schema/validation/with-validation.d.ts +5 -0
- package/dist/core/schema/validation/with-validation.js +16 -0
- package/dist/core/schema/validation/with-validation.js.map +1 -0
- package/dist/core/schema/validation/with-validation.test.d.ts +1 -0
- package/dist/core/schema/validation/with-validation.test.js +96 -0
- package/dist/core/schema/validation/with-validation.test.js.map +1 -0
- package/dist/core/schema.d.ts +86 -0
- package/dist/core/schema.js +33 -0
- package/dist/core/schema.js.map +1 -0
- package/dist/core/schema.test.d.ts +1 -0
- package/dist/core/schema.test.js +16 -0
- package/dist/core/schema.test.js.map +1 -0
- package/dist/core/schemas.d.ts +45 -0
- package/dist/core/schemas.js +39 -0
- package/dist/core/schemas.js.map +1 -0
- package/dist/ecs/action-ecs/action-ecs.d.ts +19 -0
- package/dist/ecs/action-ecs/action-ecs.js +203 -0
- package/dist/ecs/action-ecs/action-ecs.js.map +1 -0
- package/dist/ecs/action-ecs/action-ecs.test.d.ts +1 -0
- package/dist/ecs/action-ecs/action-ecs.test.js +362 -0
- package/dist/ecs/action-ecs/action-ecs.test.js.map +1 -0
- package/dist/ecs/action-ecs/action-types.d.ts +106 -0
- package/dist/ecs/action-ecs/action-types.js +19 -0
- package/dist/ecs/action-ecs/action-types.js.map +1 -0
- package/dist/ecs/action-ecs/index.d.ts +2 -0
- package/dist/ecs/action-ecs/index.js +23 -0
- package/dist/ecs/action-ecs/index.js.map +1 -0
- package/dist/ecs/component-schemas.d.ts +2 -1
- package/dist/ecs/core-ecs/core-ecs-serialization.test.d.ts +1 -0
- package/dist/ecs/core-ecs/core-ecs-serialization.test.js +230 -0
- package/dist/ecs/core-ecs/core-ecs-serialization.test.js.map +1 -0
- package/dist/ecs/core-ecs/core-ecs-types.d.ts +141 -0
- package/dist/ecs/core-ecs/core-ecs-types.js +23 -0
- package/dist/ecs/core-ecs/core-ecs-types.js.map +1 -0
- package/dist/ecs/core-ecs/core-ecs.d.ts +7 -0
- package/dist/ecs/core-ecs/core-ecs.js +492 -0
- package/dist/ecs/core-ecs/core-ecs.js.map +1 -0
- package/dist/ecs/core-ecs/core-ecs.test.d.ts +1 -0
- package/dist/ecs/core-ecs/core-ecs.test.js +425 -0
- package/dist/ecs/core-ecs/core-ecs.test.js.map +1 -0
- package/dist/ecs/core-ecs/index.d.ts +1 -0
- package/dist/ecs/core-ecs/index.js +2 -0
- package/dist/ecs/core-ecs/index.js.map +1 -0
- package/dist/ecs/database/database.d.ts +3 -3
- package/dist/ecs/database/index.d.ts +0 -1
- package/dist/ecs/database/index.js +0 -1
- package/dist/ecs/database/index.js.map +1 -1
- package/dist/ecs/database/register-database-codec.d.ts +1 -0
- package/dist/ecs/database/register-database-codec.js +35 -0
- package/dist/ecs/database/register-database-codec.js.map +1 -0
- package/dist/ecs/database/register-database-codecs.d.ts +1 -0
- package/dist/ecs/database/register-database-codecs.js +35 -0
- package/dist/ecs/database/register-database-codecs.js.map +1 -0
- package/dist/ecs/database/register-store-codec.d.ts +1 -0
- package/dist/ecs/database/register-store-codec.js +35 -0
- package/dist/ecs/database/register-store-codec.js.map +1 -0
- package/dist/ecs/database/register-typed-buffer-codecs.d.ts +1 -0
- package/dist/ecs/database/register-typed-buffer-codecs.js +80 -0
- package/dist/ecs/database/register-typed-buffer-codecs.js.map +1 -0
- package/dist/ecs/database/transactional-store/apply-operations.d.ts +2 -2
- package/dist/ecs/database/transactional-store/apply-operations.js.map +1 -1
- package/dist/ecs/database/transactional-store/apply-write-operations.d.ts +7 -0
- package/dist/ecs/database/transactional-store/apply-write-operations.js +20 -0
- package/dist/ecs/database/transactional-store/apply-write-operations.js.map +1 -0
- package/dist/ecs/database/transactional-store/applyWriteOperations.d.ts +7 -0
- package/dist/ecs/database/transactional-store/applyWriteOperations.js +20 -0
- package/dist/ecs/database/transactional-store/applyWriteOperations.js.map +1 -0
- package/dist/ecs/database/transactional-store/create-transactional-store.js +5 -6
- package/dist/ecs/database/transactional-store/create-transactional-store.js.map +1 -1
- package/dist/ecs/database/transactional-store/index.d.ts +0 -1
- package/dist/ecs/database/transactional-store/index.js +0 -1
- package/dist/ecs/database/transactional-store/index.js.map +1 -1
- package/dist/ecs/database/transactional-store/patch.d.ts +3 -0
- package/dist/ecs/database/transactional-store/patch.js +7 -0
- package/dist/ecs/database/transactional-store/patch.js.map +1 -0
- package/dist/ecs/database/transactional-store/transactional-store.d.ts +1 -6
- package/dist/ecs/database/transactional-store/undoable.d.ts +13 -0
- package/dist/ecs/database/transactional-store/undoable.js +23 -0
- package/dist/ecs/database/transactional-store/undoable.js.map +1 -0
- package/dist/ecs/database/transactional-store/with-undoable.d.ts +10 -0
- package/dist/ecs/database/transactional-store/with-undoable.js +13 -0
- package/dist/ecs/database/transactional-store/with-undoable.js.map +1 -0
- package/dist/ecs/database/with-undoable.d.ts +10 -0
- package/dist/ecs/database/with-undoable.js +13 -0
- package/dist/ecs/database/with-undoable.js.map +1 -0
- package/dist/ecs/ecs/ecs-types.d.ts +132 -0
- package/dist/ecs/ecs/ecs-types.js +23 -0
- package/dist/ecs/ecs/ecs-types.js.map +1 -0
- package/dist/ecs/ecs/ecs-where-functions.d.ts +6 -0
- package/dist/ecs/ecs/ecs-where-functions.js +91 -0
- package/dist/ecs/ecs/ecs-where-functions.js.map +1 -0
- package/dist/ecs/ecs/ecs.d.ts +13 -0
- package/dist/ecs/ecs/ecs.js +177 -0
- package/dist/ecs/ecs/ecs.js.map +1 -0
- package/dist/ecs/ecs/ecs.test.d.ts +1 -0
- package/dist/ecs/ecs/ecs.test.js +399 -0
- package/dist/ecs/ecs/ecs.test.js.map +1 -0
- package/dist/ecs/ecs/index.d.ts +3 -0
- package/dist/ecs/ecs/index.js +3 -0
- package/dist/ecs/ecs/index.js.map +1 -0
- package/dist/ecs/entity-location-table/register-database-codec.d.ts +1 -0
- package/dist/ecs/entity-location-table/register-database-codec.js +35 -0
- package/dist/ecs/entity-location-table/register-database-codec.js.map +1 -0
- package/dist/ecs/entity-location-table/register-entity-location-table-codec.d.ts +1 -0
- package/dist/ecs/entity-location-table/register-entity-location-table-codec.js +42 -0
- package/dist/ecs/entity-location-table/register-entity-location-table-codec.js.map +1 -0
- package/dist/ecs/entity-location-table/register-entity-location-table-codec.test.d.ts +1 -0
- package/dist/ecs/entity-location-table/register-entity-location-table-codec.test.js +70 -0
- package/dist/ecs/entity-location-table/register-entity-location-table-codec.test.js.map +1 -0
- package/dist/ecs/persistence-service/create-persistence-service.d.ts +6 -0
- package/dist/ecs/persistence-service/create-persistence-service.js +24 -0
- package/dist/ecs/persistence-service/create-persistence-service.js.map +1 -0
- package/dist/ecs/persistence-service/create-session-persistence-service.d.ts +8 -0
- package/dist/ecs/persistence-service/create-session-persistence-service.js +49 -0
- package/dist/ecs/persistence-service/create-session-persistence-service.js.map +1 -0
- package/dist/ecs/persistence-service/persistence-service copy.d.ts +5 -0
- package/dist/ecs/persistence-service/persistence-service copy.js +2 -0
- package/dist/ecs/persistence-service/persistence-service copy.js.map +1 -0
- package/dist/ecs/persistence-service/to-blob-refs.d.ts +2 -0
- package/dist/ecs/persistence-service/to-blob-refs.js +3 -0
- package/dist/ecs/persistence-service/to-blob-refs.js.map +1 -0
- package/dist/ecs/persistence-service/undo-redo-service.d.ts +11 -0
- package/dist/ecs/persistence-service/undo-redo-service.js +23 -0
- package/dist/ecs/persistence-service/undo-redo-service.js.map +1 -0
- package/dist/ecs/resource-schemas.d.ts +4 -3
- package/dist/ecs/resource-schemas.js +21 -0
- package/dist/ecs/resource-schemas.js.map +1 -1
- package/dist/ecs/store/core/core.d.ts +8 -0
- package/dist/ecs/store/core/create-core.js +5 -0
- package/dist/ecs/store/core/create-core.js.map +1 -1
- package/dist/ecs/store/core/create-core.test.js +109 -0
- package/dist/ecs/store/core/create-core.test.js.map +1 -1
- package/dist/ecs/store/core/register-core-codec.d.ts +1 -0
- package/dist/ecs/store/core/register-core-codec.js +45 -0
- package/dist/ecs/store/core/register-core-codec.js.map +1 -0
- package/dist/ecs/store/core/register-core-codec.test.d.ts +1 -0
- package/dist/ecs/store/core/register-core-codec.test.js +136 -0
- package/dist/ecs/store/core/register-core-codec.test.js.map +1 -0
- package/dist/ecs/store/create-store.js.map +1 -1
- package/dist/ecs/store/index.d.ts +1 -0
- package/dist/ecs/store/index.js +1 -0
- package/dist/ecs/store/index.js.map +1 -1
- package/dist/ecs/store/query.d.ts +47 -0
- package/dist/ecs/store/query.js +2 -0
- package/dist/ecs/store/query.js.map +1 -0
- package/dist/ecs/store/register-core-codec.d.ts +1 -0
- package/dist/ecs/store/register-core-codec.js +38 -0
- package/dist/ecs/store/register-core-codec.js.map +1 -0
- package/dist/ecs/store/register-store-codec.d.ts +1 -0
- package/dist/ecs/store/register-store-codec.js +38 -0
- package/dist/ecs/store/register-store-codec.js.map +1 -0
- package/dist/ecs/store/restore-store.d.ts +12 -0
- package/dist/ecs/store/restore-store.js +91 -0
- package/dist/ecs/store/restore-store.js.map +1 -0
- package/dist/ecs/store/select-options.d.ts +1 -0
- package/dist/ecs/store/select-options.js +16 -0
- package/dist/ecs/store/select-options.js.map +1 -0
- package/dist/ecs/store/select.d.ts +44 -0
- package/dist/ecs/store/select.js +2 -0
- package/dist/ecs/store/select.js.map +1 -0
- package/dist/ecs/store/store-schema/create-store-schema-test.d.ts +1 -0
- package/dist/ecs/store/store-schema/create-store-schema-test.js +36 -0
- package/dist/ecs/store/store-schema/create-store-schema-test.js.map +1 -0
- package/dist/ecs/store/store-schema/create-store-schema.d.ts +9 -0
- package/dist/ecs/store/store-schema/create-store-schema.js +26 -0
- package/dist/ecs/store/store-schema/create-store-schema.js.map +1 -0
- package/dist/ecs/store/store-schema/index.d.ts +2 -0
- package/dist/ecs/store/store-schema/index.js +24 -0
- package/dist/ecs/store/store-schema/index.js.map +1 -0
- package/dist/ecs/store/store-schema/store-schema.d.ts +12 -0
- package/dist/ecs/store/store-schema/store-schema.js +23 -0
- package/dist/ecs/store/store-schema/store-schema.js.map +1 -0
- package/dist/ecs/store/store.d.ts +6 -0
- package/dist/ecs/transaction-ecs/index.d.ts +2 -0
- package/dist/ecs/transaction-ecs/index.js +24 -0
- package/dist/ecs/transaction-ecs/index.js.map +1 -0
- package/dist/ecs/transaction-ecs/transaction-ecs.d.ts +11 -0
- package/dist/ecs/transaction-ecs/transaction-ecs.js +184 -0
- package/dist/ecs/transaction-ecs/transaction-ecs.js.map +1 -0
- package/dist/ecs/transaction-ecs/transaction-ecs.test.d.ts +1 -0
- package/dist/ecs/transaction-ecs/transaction-ecs.test.js +599 -0
- package/dist/ecs/transaction-ecs/transaction-ecs.test.js.map +1 -0
- package/dist/ecs/transaction-ecs/transaction-types.d.ts +135 -0
- package/dist/ecs/transaction-ecs/transaction-types.js +2 -0
- package/dist/ecs/transaction-ecs/transaction-types.js.map +1 -0
- package/dist/ecs/transaction-ecs/transactions.d.ts +5 -0
- package/dist/ecs/transaction-ecs/transactions.js +158 -0
- package/dist/ecs/transaction-ecs/transactions.js.map +1 -0
- package/dist/ecs/undo-redo/create-undo-redo-actions.js +21 -0
- package/dist/ecs/undo-redo/create-undo-redo-actions.js.map +1 -1
- package/dist/ecs/undo-redo/create-undo-redo-actions.test.js.map +1 -1
- package/dist/ecs/undo-redo/do.d.ts +3 -0
- package/dist/ecs/undo-redo/do.js +3 -0
- package/dist/ecs/undo-redo/do.js.map +1 -0
- package/dist/ecs/undo-redo/index.d.ts +1 -0
- package/dist/ecs/undo-redo/index.js +23 -0
- package/dist/ecs/undo-redo/index.js.map +1 -0
- package/dist/functions/serialization/deserialize.d.ts +1 -4
- package/dist/functions/serialization/deserialize.js +1 -14
- package/dist/functions/serialization/deserialize.js.map +1 -1
- package/dist/functions/serialization/register-typed-array-codecs copy.d.ts +1 -0
- package/dist/functions/serialization/register-typed-array-codecs copy.js +13 -0
- package/dist/functions/serialization/register-typed-array-codecs copy.js.map +1 -0
- package/dist/functions/serialization/serialize-to-blobs copy.d.ts +8 -0
- package/dist/functions/serialization/serialize-to-blobs copy.js +21 -0
- package/dist/functions/serialization/serialize-to-blobs copy.js.map +1 -0
- package/dist/functions/serialization/serialize-to-blobs.js.map +1 -1
- package/dist/observe/to-async-generator.js +0 -4
- package/dist/observe/to-async-generator.js.map +1 -1
- package/dist/observe/with-map copy.d.ts +5 -0
- package/dist/observe/with-map copy.js +14 -0
- package/dist/observe/with-map copy.js.map +1 -0
- package/dist/package.json +129 -0
- package/dist/schema/f32 copy.d.ts +6 -0
- package/dist/schema/f32 copy.js +6 -0
- package/dist/schema/f32 copy.js.map +1 -0
- package/dist/schemas/index.d.ts +1 -0
- package/dist/schemas/index.js +23 -0
- package/dist/schemas/index.js.map +1 -0
- package/dist/schemas/schemas.d.ts +45 -0
- package/dist/schemas/schemas.js +39 -0
- package/dist/schemas/schemas.js.map +1 -0
- package/dist/service/sequential-action.d.ts +18 -0
- package/dist/service/sequential-action.js +45 -0
- package/dist/service/sequential-action.js.map +1 -0
- package/dist/table/ensure-capacity copy.d.ts +2 -0
- package/dist/table/ensure-capacity copy.js +15 -0
- package/dist/table/ensure-capacity copy.js.map +1 -0
- package/dist/table/filter-rows.d.ts +2 -0
- package/dist/table/filter-rows.js +15 -0
- package/dist/table/filter-rows.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/typed-buffer/structs/get-struct-layout.js +7 -10
- package/dist/typed-buffer/structs/get-struct-layout.js.map +1 -1
- package/dist/typed-buffer/structs/get-struct-layout.test.js +148 -11
- package/dist/typed-buffer/structs/get-struct-layout.test.js.map +1 -1
- package/package.json +3 -3
- package/dist/ecs/database/database-schema/create-database-from-schema.d.ts +0 -12
- package/dist/ecs/database/database-schema/create-database-from-schema.js +0 -8
- package/dist/ecs/database/database-schema/create-database-from-schema.js.map +0 -1
- package/dist/functions/serialization/serialization.d.ts +0 -23
- package/dist/functions/serialization/serialization.js +0 -58
- package/dist/functions/serialization/serialization.js.map +0 -1
- package/dist/functions/serialization.d.ts +0 -23
- package/dist/functions/serialization.js +0 -58
- package/dist/functions/serialization.js.map +0 -1
- package/dist/functions/serialization.test.js.map +0 -1
- package/dist/functions/serialize.d.ts +0 -17
- package/dist/functions/serialize.js +0 -66
- package/dist/functions/serialize.js.map +0 -1
- /package/dist/{functions/serialization.test.d.ts → core/data.test.d.ts} +0 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { DeepReadonly } from "../../types/types.js";
|
|
2
|
+
type JSONPath = string;
|
|
3
|
+
type JSONMergePatch = unknown;
|
|
4
|
+
/**
|
|
5
|
+
* Conditional patch applied to the path when the enclosing schema branch is active
|
|
6
|
+
* and `match` is not present or validates against the root.
|
|
7
|
+
* This is used for dynamic schemas which change in response to the value of the data.
|
|
8
|
+
*/
|
|
9
|
+
export type Conditional = {
|
|
10
|
+
match?: Schema;
|
|
11
|
+
path: JSONPath;
|
|
12
|
+
value: JSONMergePatch;
|
|
13
|
+
};
|
|
14
|
+
export interface UIProperties {
|
|
15
|
+
name?: string;
|
|
16
|
+
icon?: string;
|
|
17
|
+
summary?: string;
|
|
18
|
+
premium?: boolean;
|
|
19
|
+
placeholder?: string;
|
|
20
|
+
details?: string;
|
|
21
|
+
visible?: boolean;
|
|
22
|
+
enabled?: boolean;
|
|
23
|
+
infoUrl?: string;
|
|
24
|
+
group?: string;
|
|
25
|
+
order?: number;
|
|
26
|
+
groups?: {
|
|
27
|
+
readonly [key: string]: UIProperties;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export interface Schema {
|
|
31
|
+
type?: 'number' | 'integer' | 'string' | 'boolean' | 'null' | 'array' | 'object';
|
|
32
|
+
conditionals?: readonly Conditional[];
|
|
33
|
+
ui?: UIProperties;
|
|
34
|
+
default?: any;
|
|
35
|
+
precision?: 1 | 2;
|
|
36
|
+
multipleOf?: number;
|
|
37
|
+
mediaType?: string;
|
|
38
|
+
minimum?: number;
|
|
39
|
+
maximum?: number;
|
|
40
|
+
minLength?: number;
|
|
41
|
+
maxLength?: number;
|
|
42
|
+
exclusiveMinimum?: number;
|
|
43
|
+
exclusiveMaximum?: number;
|
|
44
|
+
pattern?: string;
|
|
45
|
+
minItems?: number;
|
|
46
|
+
maxItems?: number;
|
|
47
|
+
items?: Schema;
|
|
48
|
+
properties?: {
|
|
49
|
+
readonly [key: string]: Schema;
|
|
50
|
+
};
|
|
51
|
+
required?: readonly string[];
|
|
52
|
+
additionalProperties?: boolean | Schema;
|
|
53
|
+
oneOf?: readonly Schema[];
|
|
54
|
+
const?: any;
|
|
55
|
+
enum?: readonly any[];
|
|
56
|
+
}
|
|
57
|
+
export type FromSchema<T, Depth extends number = 5> = DeepReadonly<Depth extends 0 ? any : T extends {
|
|
58
|
+
const: infer Const;
|
|
59
|
+
} ? Const : T extends {
|
|
60
|
+
enum: infer Enum;
|
|
61
|
+
} ? Enum extends ReadonlyArray<any> ? Enum[number] : never : T extends {
|
|
62
|
+
oneOf: infer Schemas;
|
|
63
|
+
} ? Schemas extends ReadonlyArray<Schema> ? FromOneOfSchema<Schemas, Decrement<Depth>> : never : T extends {
|
|
64
|
+
type: 'number' | 'integer';
|
|
65
|
+
} ? number : T extends {
|
|
66
|
+
type: 'string';
|
|
67
|
+
} ? string : T extends {
|
|
68
|
+
type: 'boolean';
|
|
69
|
+
} ? boolean : T extends {
|
|
70
|
+
type: 'null';
|
|
71
|
+
} ? null : T extends {
|
|
72
|
+
type: 'array';
|
|
73
|
+
} | {
|
|
74
|
+
items: any;
|
|
75
|
+
} ? FromSchemaArray<T, Decrement<Depth>> : T extends {
|
|
76
|
+
type: 'object';
|
|
77
|
+
} | {
|
|
78
|
+
properties: any;
|
|
79
|
+
} ? FromSchemaObject<T, Decrement<Depth>> : any>;
|
|
80
|
+
type Decrement<N extends number> = ((...x: any[]) => void) extends (arg: any, ...rest: infer R) => void ? R['length'] : never;
|
|
81
|
+
type FromSchemaArray<T, Depth extends number> = T extends {
|
|
82
|
+
items: infer Items;
|
|
83
|
+
} ? T extends {
|
|
84
|
+
minItems: infer Min;
|
|
85
|
+
maxItems: infer Max;
|
|
86
|
+
} ? Equal<Min, Max> extends true ? BuildTuple<FromSchema<Items, Depth>, Min> : FromSchema<Items, Depth>[] : FromSchema<Items, Depth>[] : any[];
|
|
87
|
+
type BuildTuple<T, N, R extends unknown[] = []> = R['length'] extends N ? R : BuildTuple<T, N, [...R, T]>;
|
|
88
|
+
type FromSchemaObject<T extends Schema, Depth extends number> = T extends {
|
|
89
|
+
properties: infer P;
|
|
90
|
+
} ? Simplify<{
|
|
91
|
+
[K in RequiredKeys<T>]: FromSchema<P[K], Depth>;
|
|
92
|
+
} & {
|
|
93
|
+
[K in OptionalKeys<T>]?: FromSchema<P[K], Depth>;
|
|
94
|
+
} & (T extends {
|
|
95
|
+
additionalProperties: infer AP;
|
|
96
|
+
} ? AP extends false ? {} : AP extends Schema ? {
|
|
97
|
+
[key: string]: FromSchema<AP, Depth>;
|
|
98
|
+
} : {
|
|
99
|
+
[key: string]: any;
|
|
100
|
+
} : {
|
|
101
|
+
[key: string]: any;
|
|
102
|
+
})> : T extends {
|
|
103
|
+
additionalProperties: infer AP;
|
|
104
|
+
} ? AP extends Schema ? {
|
|
105
|
+
[key: string]: FromSchema<AP, Depth>;
|
|
106
|
+
} : {
|
|
107
|
+
[key: string]: any;
|
|
108
|
+
} : {
|
|
109
|
+
[key: string]: any;
|
|
110
|
+
};
|
|
111
|
+
type RequiredKeys<T> = T extends {
|
|
112
|
+
required: infer R;
|
|
113
|
+
} ? R extends readonly (infer K)[] ? K extends string ? K : never : never : never;
|
|
114
|
+
type OptionalKeys<T> = T extends {
|
|
115
|
+
properties: infer P;
|
|
116
|
+
} ? Exclude<keyof P, RequiredKeys<T>> : never;
|
|
117
|
+
type Equal<A, B> = (<T>() => T extends A ? 1 : 2) extends <T>() => T extends B ? 1 : 2 ? true : false;
|
|
118
|
+
type Simplify<T> = T extends infer O ? {
|
|
119
|
+
[K in keyof O]: O[K];
|
|
120
|
+
} : never;
|
|
121
|
+
type FromOneOfSchema<Schemas extends ReadonlyArray<Schema>, Depth extends number> = Schemas[number] extends infer S ? S extends Schema ? FromSchema<S, Depth> : never : never;
|
|
122
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/*MIT License
|
|
2
|
+
|
|
3
|
+
© Copyright 2025 Adobe. All rights reserved.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.*/
|
|
22
|
+
;
|
|
23
|
+
const mySchema = {
|
|
24
|
+
type: 'object',
|
|
25
|
+
properties: {
|
|
26
|
+
a: { type: 'number' },
|
|
27
|
+
b: { type: 'string' },
|
|
28
|
+
c: { enum: [1, 2, 3] }
|
|
29
|
+
},
|
|
30
|
+
required: ['a', 'c'],
|
|
31
|
+
additionalProperties: false,
|
|
32
|
+
};
|
|
33
|
+
export {};
|
|
34
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/core/schema/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;WAoBW;AA6DV,CAAC;AAiIF,MAAM,QAAQ,GAAG;IACf,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACV,CAAC,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QACrB,CAAC,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QACrB,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE;KACvB;IACD,QAAQ,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC;IACpB,oBAAoB,EAAE,KAAK;CACF,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Schema } from "../index.js";
|
|
2
|
+
export declare function Nullable<T extends Schema>(schema: T): {
|
|
3
|
+
oneOf: [T, {
|
|
4
|
+
type: "null";
|
|
5
|
+
}];
|
|
6
|
+
};
|
|
7
|
+
export declare function Tuple<T extends Schema, N extends number>(items: T, length: N): {
|
|
8
|
+
readonly type: "array";
|
|
9
|
+
readonly items: T;
|
|
10
|
+
readonly minItems: N;
|
|
11
|
+
readonly maxItems: N;
|
|
12
|
+
};
|
|
13
|
+
export declare const TrueSchema: {
|
|
14
|
+
readonly const: true;
|
|
15
|
+
};
|
|
16
|
+
export declare const BooleanSchema: {
|
|
17
|
+
readonly type: "boolean";
|
|
18
|
+
};
|
|
19
|
+
export declare const Float32Schema: {
|
|
20
|
+
readonly type: "number";
|
|
21
|
+
readonly precision: 1;
|
|
22
|
+
};
|
|
23
|
+
export declare const Float64Schema: {
|
|
24
|
+
readonly type: "number";
|
|
25
|
+
readonly precision: 2;
|
|
26
|
+
};
|
|
27
|
+
export declare const TimeSchema: {
|
|
28
|
+
readonly type: "number";
|
|
29
|
+
readonly precision: 2;
|
|
30
|
+
};
|
|
31
|
+
export declare const Uint8Schema: {
|
|
32
|
+
readonly type: "integer";
|
|
33
|
+
readonly minimum: 0;
|
|
34
|
+
readonly maximum: 255;
|
|
35
|
+
};
|
|
36
|
+
export declare const Uint16Schema: {
|
|
37
|
+
readonly type: "integer";
|
|
38
|
+
readonly minimum: 0;
|
|
39
|
+
readonly maximum: 65535;
|
|
40
|
+
};
|
|
41
|
+
export declare const Uint32Schema: {
|
|
42
|
+
readonly type: "integer";
|
|
43
|
+
readonly minimum: 0;
|
|
44
|
+
readonly maximum: 4294967295;
|
|
45
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export function Nullable(schema) {
|
|
2
|
+
return {
|
|
3
|
+
oneOf: [schema, { type: "null" }],
|
|
4
|
+
};
|
|
5
|
+
}
|
|
6
|
+
export function Tuple(items, length) {
|
|
7
|
+
return { type: "array", items, minItems: length, maxItems: length };
|
|
8
|
+
}
|
|
9
|
+
export const TrueSchema = {
|
|
10
|
+
const: true,
|
|
11
|
+
};
|
|
12
|
+
export const BooleanSchema = {
|
|
13
|
+
type: "boolean",
|
|
14
|
+
};
|
|
15
|
+
export const Float32Schema = {
|
|
16
|
+
type: "number",
|
|
17
|
+
precision: 1,
|
|
18
|
+
};
|
|
19
|
+
export const Float64Schema = {
|
|
20
|
+
type: "number",
|
|
21
|
+
precision: 2,
|
|
22
|
+
};
|
|
23
|
+
export const TimeSchema = Float64Schema;
|
|
24
|
+
export const Uint8Schema = {
|
|
25
|
+
type: "integer",
|
|
26
|
+
minimum: 0,
|
|
27
|
+
maximum: 0xff,
|
|
28
|
+
};
|
|
29
|
+
export const Uint16Schema = {
|
|
30
|
+
type: "integer",
|
|
31
|
+
minimum: 0,
|
|
32
|
+
maximum: 0xffff,
|
|
33
|
+
};
|
|
34
|
+
export const Uint32Schema = {
|
|
35
|
+
type: "integer",
|
|
36
|
+
minimum: 0,
|
|
37
|
+
maximum: 0xffffffff,
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=schemas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemas.js","sourceRoot":"","sources":["../../../src/core/schema/schemas.ts"],"names":[],"mappings":"AAuBA,MAAM,UAAU,QAAQ,CACtB,MAAS;IAET,OAAO;QACL,KAAK,EAAE,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;KAClC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,KAAK,CAAqC,KAAQ,EAAE,MAAS;IAC3E,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAA4B,CAAC;AAChG,CAAC;AAED,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,KAAK,EAAE,IAAI;CACc,CAAC;AAE5B,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,IAAI,EAAE,SAAS;CACU,CAAC;AAE5B,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,IAAI,EAAE,QAAQ;IACd,SAAS,EAAE,CAAC;CACa,CAAC;AAE5B,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,IAAI,EAAE,QAAQ;IACd,SAAS,EAAE,CAAC;CACa,CAAC;AAE5B,MAAM,CAAC,MAAM,UAAU,GAAG,aAAa,CAAC;AAExC,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,IAAI,EAAE,SAAS;IACf,OAAO,EAAE,CAAC;IACV,OAAO,EAAE,IAAI;CACY,CAAC;AAE5B,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,IAAI,EAAE,SAAS;IACf,OAAO,EAAE,CAAC;IACV,OAAO,EAAE,MAAM;CACU,CAAC;AAE5B,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,IAAI,EAAE,SAAS;IACf,OAAO,EAAE,CAAC;IACV,OAAO,EAAE,UAAU;CACM,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Schema } from "./schema.js";
|
|
2
|
+
export type UIProperties = {
|
|
3
|
+
name?: string;
|
|
4
|
+
icon?: string;
|
|
5
|
+
summary?: string;
|
|
6
|
+
placeholder?: string;
|
|
7
|
+
details?: string;
|
|
8
|
+
visible?: boolean;
|
|
9
|
+
enabled?: boolean;
|
|
10
|
+
infoUrl?: string;
|
|
11
|
+
group?: string;
|
|
12
|
+
order?: number;
|
|
13
|
+
groups?: {
|
|
14
|
+
readonly [key: string]: UIProperties;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
export type UISchema = Schema & {
|
|
18
|
+
items?: UISchema;
|
|
19
|
+
ui?: UIProperties;
|
|
20
|
+
properties?: {
|
|
21
|
+
readonly [key: string]: UISchema;
|
|
22
|
+
};
|
|
23
|
+
additionalProperties?: boolean | UISchema;
|
|
24
|
+
oneOf?: readonly UISchema[];
|
|
25
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ui-schema.js","sourceRoot":"","sources":["../../../src/core/schema/ui-schema.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { validate } from "./validate.js";
|
|
2
|
+
export function isValid(schema, data) {
|
|
3
|
+
if (data === undefined) {
|
|
4
|
+
debugger;
|
|
5
|
+
}
|
|
6
|
+
try {
|
|
7
|
+
return validate(schema, data ?? null).length === 0;
|
|
8
|
+
}
|
|
9
|
+
catch (error) {
|
|
10
|
+
console.error(`Error during validation:`, error);
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=is-valid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-valid.js","sourceRoot":"","sources":["../../../../src/core/schema/validation/is-valid.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,MAAM,UAAU,OAAO,CAAC,MAAc,EAAE,IAAS;IAC7C,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACrB,QAAQ,CAAC;IACb,CAAC;IACD,IAAI,CAAC;QACD,OAAO,QAAQ,CAAC,MAAM,EAAE,IAAI,IAAI,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC;IACvD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,0BAA0B,EAAE,KAAK,CAAC,CAAC;QACjD,OAAO,KAAK,CAAC;IACjB,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -19,26 +19,22 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
21
|
SOFTWARE.*/
|
|
22
|
-
import { serialize, deserialize } from './serialization/serialization.js';
|
|
23
22
|
import { describe, it, expect } from 'vitest';
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
expect(
|
|
39
|
-
expect(payload.binary).toBeInstanceOf(Array);
|
|
40
|
-
const roundTrip = deserialize(payload);
|
|
41
|
-
expect(roundTrip).toEqual(original);
|
|
23
|
+
import { isValid } from './is-valid.js';
|
|
24
|
+
describe('isValid', () => {
|
|
25
|
+
const schema = {
|
|
26
|
+
type: 'object',
|
|
27
|
+
properties: {
|
|
28
|
+
foo: { type: 'string' }
|
|
29
|
+
},
|
|
30
|
+
required: ['foo']
|
|
31
|
+
};
|
|
32
|
+
it('returns true for valid data', () => {
|
|
33
|
+
expect(isValid(schema, { foo: 'bar' })).toBe(true);
|
|
34
|
+
});
|
|
35
|
+
it('returns false for invalid data', () => {
|
|
36
|
+
expect(isValid(schema, { foo: 123 })).toBe(false);
|
|
37
|
+
expect(isValid(schema, {})).toBe(false);
|
|
42
38
|
});
|
|
43
39
|
});
|
|
44
|
-
//# sourceMappingURL=
|
|
40
|
+
//# sourceMappingURL=is-valid.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-valid.test.js","sourceRoot":"","sources":["../../../../src/core/schema/validation/is-valid.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;WAoBW;AACX,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAGxC,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE;IACrB,MAAM,MAAM,GAAW;QACnB,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACR,GAAG,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;SAC1B;QACD,QAAQ,EAAE,CAAC,KAAK,CAAC;KACpB,CAAC;IAEF,EAAE,CAAC,6BAA6B,EAAE,GAAG,EAAE;QACnC,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,gCAAgC,EAAE,GAAG,EAAE;QACtC,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAClD,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC5C,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/*MIT License
|
|
2
|
+
|
|
3
|
+
© Copyright 2025 Adobe. All rights reserved.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.*/
|
|
22
|
+
import { Validator } from '@cfworker/json-schema';
|
|
23
|
+
// Cache of validators using WeakMap to avoid memory leaks
|
|
24
|
+
const validatorCache = new WeakMap();
|
|
25
|
+
export function validate(schema, data) {
|
|
26
|
+
// Get or create validator from cache
|
|
27
|
+
let validator = validatorCache.get(schema);
|
|
28
|
+
if (!validator) {
|
|
29
|
+
validator = new Validator(schema);
|
|
30
|
+
validatorCache.set(schema, validator);
|
|
31
|
+
}
|
|
32
|
+
const result = validator.validate(data);
|
|
33
|
+
if (result.valid) {
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
return result.errors.map((error) => error.error);
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=validate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../../../../src/core/schema/validation/validate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;WAoBW;AACX,OAAO,EAAE,SAAS,EAAwB,MAAM,uBAAuB,CAAC;AAGxE,0DAA0D;AAC1D,MAAM,cAAc,GAAG,IAAI,OAAO,EAAqB,CAAC;AAExD,MAAM,UAAU,QAAQ,CAAC,MAAc,EAAE,IAAS;IAC9C,qCAAqC;IACrC,IAAI,SAAS,GAAG,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC3C,IAAI,CAAC,SAAS,EAAE,CAAC;QACb,SAAS,GAAG,IAAI,SAAS,CAAC,MAAoB,CAAC,CAAC;QAChD,cAAc,CAAC,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAC1C,CAAC;IAED,MAAM,MAAM,GAAG,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IACxC,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;QACf,OAAO,EAAE,CAAC;IACd,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AACrD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/*MIT License
|
|
2
|
+
|
|
3
|
+
© Copyright 2025 Adobe. All rights reserved.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.*/
|
|
22
|
+
import { describe, it, expect } from 'vitest';
|
|
23
|
+
import { validate } from './validate.js';
|
|
24
|
+
describe('validate', () => {
|
|
25
|
+
const userSchema = {
|
|
26
|
+
type: 'object',
|
|
27
|
+
properties: {
|
|
28
|
+
name: { type: 'string' },
|
|
29
|
+
age: { type: 'number' },
|
|
30
|
+
email: { type: 'string', pattern: '^[^@]+@[^@]+\\.[^@]+$' }
|
|
31
|
+
},
|
|
32
|
+
required: ['name', 'age', 'email']
|
|
33
|
+
};
|
|
34
|
+
it('should return empty array for valid data', () => {
|
|
35
|
+
const validData = {
|
|
36
|
+
name: 'John Doe',
|
|
37
|
+
age: 30,
|
|
38
|
+
email: 'john@example.com'
|
|
39
|
+
};
|
|
40
|
+
const errors = validate(userSchema, validData);
|
|
41
|
+
expect(errors).toEqual([]);
|
|
42
|
+
});
|
|
43
|
+
it('should return validation errors for invalid data', () => {
|
|
44
|
+
const invalidData = {
|
|
45
|
+
name: 'John Doe',
|
|
46
|
+
age: '30', // Should be a number
|
|
47
|
+
email: 'not-an-email'
|
|
48
|
+
};
|
|
49
|
+
const errors = validate(userSchema, invalidData);
|
|
50
|
+
expect(errors.length).toBeGreaterThan(0);
|
|
51
|
+
expect(errors).toContain('Property "age" does not match schema.');
|
|
52
|
+
expect(errors).toContain('Instance type "string" is invalid. Expected "number".');
|
|
53
|
+
});
|
|
54
|
+
it('should return errors for missing required fields', () => {
|
|
55
|
+
const incompleteData = {
|
|
56
|
+
name: 'John Doe'
|
|
57
|
+
// Missing age and email
|
|
58
|
+
};
|
|
59
|
+
const errors = validate(userSchema, incompleteData);
|
|
60
|
+
expect(errors.length).toBeGreaterThan(0);
|
|
61
|
+
expect(errors).toContain('Instance does not have required property "age".');
|
|
62
|
+
expect(errors).toContain('Instance does not have required property "email".');
|
|
63
|
+
});
|
|
64
|
+
it('should reuse validator instance for the same schema', () => {
|
|
65
|
+
const data1 = { name: 'John', age: 30, email: 'john@example.com' };
|
|
66
|
+
const data2 = { name: 'Jane', age: 25, email: 'jane@example.com' };
|
|
67
|
+
// First validation
|
|
68
|
+
const errors1 = validate(userSchema, data1);
|
|
69
|
+
expect(errors1).toEqual([]);
|
|
70
|
+
// Second validation with same schema
|
|
71
|
+
const errors2 = validate(userSchema, data2);
|
|
72
|
+
expect(errors2).toEqual([]);
|
|
73
|
+
// The validator should be reused from the WeakMap cache
|
|
74
|
+
// We can verify this by checking that the schema object is still the same reference
|
|
75
|
+
expect(userSchema).toBe(userSchema);
|
|
76
|
+
});
|
|
77
|
+
it('should handle nested schema validation', () => {
|
|
78
|
+
const nestedSchema = {
|
|
79
|
+
type: 'object',
|
|
80
|
+
properties: {
|
|
81
|
+
user: userSchema,
|
|
82
|
+
metadata: {
|
|
83
|
+
type: 'object',
|
|
84
|
+
properties: {
|
|
85
|
+
createdAt: { type: 'string', pattern: '^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$' }
|
|
86
|
+
},
|
|
87
|
+
required: ['createdAt']
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
required: ['user', 'metadata']
|
|
91
|
+
};
|
|
92
|
+
const validNestedData = {
|
|
93
|
+
user: {
|
|
94
|
+
name: 'John Doe',
|
|
95
|
+
age: 30,
|
|
96
|
+
email: 'john@example.com'
|
|
97
|
+
},
|
|
98
|
+
metadata: {
|
|
99
|
+
createdAt: '2024-03-20T12:00:00Z'
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
const errors = validate(nestedSchema, validNestedData);
|
|
103
|
+
expect(errors).toEqual([]);
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
//# sourceMappingURL=validate.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.test.js","sourceRoot":"","sources":["../../../../src/core/schema/validation/validate.test.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Schema, FromSchema } from '../index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a function which can wrap another function and validate the input against a JSON Schema.
|
|
4
|
+
*/
|
|
5
|
+
export declare function withValidation<T extends Schema>(schema: T): <F extends (arg: FromSchema<T>) => any>(fn: F) => F;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { validate } from './validate.js';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a function which can wrap another function and validate the input against a JSON Schema.
|
|
4
|
+
*/
|
|
5
|
+
export function withValidation(schema) {
|
|
6
|
+
return function (fn) {
|
|
7
|
+
return function (arg) {
|
|
8
|
+
const errors = validate(schema, arg);
|
|
9
|
+
if (errors.length > 0) {
|
|
10
|
+
throw new Error(`Validation failed: ${JSON.stringify(errors)}`);
|
|
11
|
+
}
|
|
12
|
+
return fn.call(this, arg);
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=with-validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with-validation.js","sourceRoot":"","sources":["../../../../src/core/schema/validation/with-validation.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC;;GAEG;AACH,MAAM,UAAU,cAAc,CAAmB,MAAS;IACtD,OAAO,UAAiD,EAAK;QACzD,OAAO,UAAqB,GAAkB;YAC1C,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;YAErC,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACpB,MAAM,IAAI,KAAK,CACX,sBAAsB,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CACjD,CAAC;YACN,CAAC;YAED,OAAO,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;QAC9B,CAAM,CAAC;IACX,CAAC,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/*MIT License
|
|
2
|
+
|
|
3
|
+
© Copyright 2025 Adobe. All rights reserved.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.*/
|
|
22
|
+
import { describe, it, expect } from 'vitest';
|
|
23
|
+
import { withValidation } from './with-validation.js';
|
|
24
|
+
// Define a test schema
|
|
25
|
+
const userSchema = {
|
|
26
|
+
type: 'object',
|
|
27
|
+
properties: {
|
|
28
|
+
name: { type: 'string' },
|
|
29
|
+
age: { type: 'number' },
|
|
30
|
+
foo: { type: 'string' },
|
|
31
|
+
email: { type: 'string', format: 'email' }
|
|
32
|
+
},
|
|
33
|
+
required: ['name', 'age', 'email']
|
|
34
|
+
};
|
|
35
|
+
describe('withValidation', () => {
|
|
36
|
+
it('should pass validation for valid input', () => {
|
|
37
|
+
const createUser = withValidation(userSchema)((user) => user);
|
|
38
|
+
const validUser = {
|
|
39
|
+
name: 'John Doe',
|
|
40
|
+
age: 30,
|
|
41
|
+
email: 'john@example.com'
|
|
42
|
+
};
|
|
43
|
+
expect(() => createUser(validUser)).not.toThrow();
|
|
44
|
+
expect(createUser(validUser)).toEqual(validUser);
|
|
45
|
+
});
|
|
46
|
+
it('should throw error for invalid input', () => {
|
|
47
|
+
const createUser = withValidation(userSchema)((user) => user);
|
|
48
|
+
const invalidUser = {
|
|
49
|
+
name: 'John Doe',
|
|
50
|
+
age: '30', // Should be a number
|
|
51
|
+
email: 'not-an-email'
|
|
52
|
+
};
|
|
53
|
+
expect(() => createUser(invalidUser)).toThrow(/Validation failed/);
|
|
54
|
+
});
|
|
55
|
+
it('should throw error for missing required fields', () => {
|
|
56
|
+
const createUser = withValidation(userSchema)((user) => user);
|
|
57
|
+
const incompleteUser = {
|
|
58
|
+
name: 'John Doe',
|
|
59
|
+
// Missing age and email
|
|
60
|
+
};
|
|
61
|
+
expect(() => createUser(incompleteUser)).toThrow(/Validation failed/);
|
|
62
|
+
});
|
|
63
|
+
it('should preserve function return type', () => {
|
|
64
|
+
const processUser = withValidation(userSchema)((user) => ({
|
|
65
|
+
...user,
|
|
66
|
+
processed: true
|
|
67
|
+
}));
|
|
68
|
+
const result = processUser({
|
|
69
|
+
name: 'John Doe',
|
|
70
|
+
age: 30,
|
|
71
|
+
email: 'john@example.com'
|
|
72
|
+
});
|
|
73
|
+
expect(result).toEqual({
|
|
74
|
+
name: 'John Doe',
|
|
75
|
+
age: 30,
|
|
76
|
+
email: 'john@example.com',
|
|
77
|
+
processed: true
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
it("should pass 'this' context to the wrapped function", () => {
|
|
81
|
+
const context = { value: 42 };
|
|
82
|
+
const fn = function (user) {
|
|
83
|
+
return this.value;
|
|
84
|
+
};
|
|
85
|
+
const wrapped = withValidation(userSchema)(fn);
|
|
86
|
+
const validUser = {
|
|
87
|
+
name: 'Jane Doe',
|
|
88
|
+
age: 25,
|
|
89
|
+
email: 'jane@example.com'
|
|
90
|
+
};
|
|
91
|
+
// Bind context and call
|
|
92
|
+
const result = wrapped.call(context, validUser);
|
|
93
|
+
expect(result).toBe(42);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
//# sourceMappingURL=with-validation.test.js.map
|