Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(framework): add class-validator support #6945

Open
wants to merge 85 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 80 commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
369ffaf
feat: add class-validator support
paulwer Nov 4, 2024
19c03c2
Merge branch 'next' into feat-package-class-validator-support
paulwer Nov 4, 2024
a16f147
Merge branch 'next' into feat-package-class-validator-support
paulwer Nov 5, 2024
1016672
Merge branch 'next' into feat-package-class-validator-support
rifont Nov 8, 2024
c2c0512
Update packages/framework/src/validators/class-validator.validator.ts
paulwer Nov 8, 2024
f343a9d
fixes
paulwer Nov 8, 2024
b91fe48
Merge branch 'next' into feat-package-class-validator-support
paulwer Nov 8, 2024
8662b2b
workaround for classValidator defaultStorage
paulwer Nov 8, 2024
df9128e
Update packages/framework/src/validators/class-validator.validator.ts
paulwer Nov 8, 2024
86bd4f9
fixes
paulwer Nov 8, 2024
5d2b8e9
Merge remote-tracking branch 'refs/remotes/origin/feat-package-class-…
paulwer Nov 8, 2024
2b8f000
Merge branch 'next' into feat-package-class-validator-support
paulwer Nov 8, 2024
f74470a
refactor(types): replace any with unknown in T_Controls
rifont Nov 8, 2024
e7f3ef8
Update packages/framework/src/validators/class-validator.validator.ts
rifont Nov 8, 2024
c5daec5
refactor(validator): simplify metadata storage import
rifont Nov 8, 2024
255115c
docs(validator): update TODO comment with @see link
rifont Nov 8, 2024
68e5c9c
test(validation): update tests for validation changes
rifont Nov 8, 2024
ecec05d
refactor(types): update class type inference logic
rifont Nov 8, 2024
836bde3
test: remove JSON stringify from test assertion
rifont Nov 8, 2024
f3decf0
docs(schema.types): update ClassType type description
rifont Nov 8, 2024
ed7c857
refactor(class-validator): improve type checking logic
rifont Nov 8, 2024
322d118
test(validator): extract class-validator fixtures
rifont Nov 8, 2024
7fb6368
Merge branch 'next' into feat-package-class-validator-support
rifont Nov 8, 2024
b432668
refactor: Remove IsOptional from name property
rifont Nov 8, 2024
11210c4
Merge branch 'feat-package-class-validator-support' of https://github…
rifont Nov 8, 2024
76de6fa
refactor(schema): remove zod dependency from schemas
rifont Nov 10, 2024
3eb118a
docs(import.types): clarify dependency import comment
rifont Nov 10, 2024
8049177
refactor(validators): update type imports and schema names
rifont Nov 10, 2024
0d0b31b
refactor(types): update import to use 'type' keyword
rifont Nov 10, 2024
15b9ab4
docs(zod): add comment for ZodSchema type
rifont Nov 10, 2024
ff1577e
fix(framework): Add dependency check import utilities
rifont Nov 10, 2024
dac4ef8
refactor(zod): simplify import and type usage
rifont Nov 11, 2024
34f9add
Merge branch 'import-utils-refactor-schemas' into feat-package-class-…
rifont Nov 11, 2024
d5c304b
Update packages/framework/src/types/schema.types/zod.schema.types.ts
rifont Nov 11, 2024
1281a14
Update packages/framework/src/client.test.ts
rifont Nov 11, 2024
d29556d
Update packages/framework/package.json
rifont Nov 11, 2024
0ab32ec
Update packages/framework/src/validators/class-validator.validator.ts
rifont Nov 11, 2024
5d76360
refactor(json-schema): update JSONSchema imports
rifont Nov 11, 2024
0c8857d
docs(json-schema-dto): update comment for clarity
rifont Nov 11, 2024
dbf050e
Merge branch 'import-utils-refactor-schemas' into feat-package-class-…
rifont Nov 11, 2024
37bc8bc
Update packages/framework/src/validators/validator.test.ts
rifont Nov 11, 2024
2b9c81f
refactor(json-schema-dto): simplify JSON schema types
rifont Nov 11, 2024
522d59a
refactor(api): replace json-schema with JSONSchemaDto
rifont Nov 11, 2024
8c24423
refactor(schema): update JSONSchema to JSONSchemaDefinition
rifont Nov 11, 2024
d35de47
Update apps/dashboard/package.json
rifont Nov 11, 2024
4aaa275
refactor: replace JsonSchema with JSONSchemaDto
rifont Nov 11, 2024
6d56c0a
Merge branch 'import-utils-refactor-schemas' of ssh://github.com/novu…
rifont Nov 11, 2024
2e5c3b5
refactor(json-schema-dto): use readonly types for safety
rifont Nov 11, 2024
6847ef5
Merge branch 'next' into import-utils-refactor-schemas
rifont Nov 11, 2024
7c2736e
refactor(api): remove json-schema-to-ts dependency
rifont Nov 11, 2024
e353b7e
Merge branch 'jsonschema-dto-everywhere' into import-utils-refactor-s…
rifont Nov 11, 2024
0fb4a20
refactor(types): refactor JSON schema type definitions
rifont Nov 11, 2024
ed7ab69
Merge branch 'jsonschema-dto-everywhere' into import-utils-refactor-s…
rifont Nov 11, 2024
c1bf7ff
chore: add 'combinators' to cspell.json dictionary
rifont Nov 11, 2024
fd340d9
Merge branch 'next' into jsonschema-dto-everywhere
rifont Nov 11, 2024
d28d16b
Merge branch 'jsonschema-dto-everywhere' into import-utils-refactor-s…
rifont Nov 11, 2024
b918978
Merge branch 'import-utils-refactor-schemas' into feat-package-class-…
rifont Nov 11, 2024
e663960
Merge branch 'next' into import-utils-refactor-schemas
rifont Nov 11, 2024
7e31412
Merge branch 'import-utils-refactor-schemas' of ssh://github.com/novu…
rifont Nov 11, 2024
4140bda
Merge branch 'import-utils-refactor-schemas' into feat-package-class-…
rifont Nov 11, 2024
d54f009
Merge branch 'next' into feat-package-class-validator-support
rifont Nov 12, 2024
d7ed75f
Update packages/framework/src/resources/workflow/discover-custom-step…
rifont Nov 12, 2024
229b530
Update packages/framework/src/types/schema.types/base.schema.types.ts
rifont Nov 12, 2024
41d8ff3
feat: add enum tests
paulwer Nov 12, 2024
f146791
feat: support nested array structures
paulwer Nov 12, 2024
deb1a7c
Merge branch 'feat-package-class-validator-support' of https://github…
paulwer Nov 12, 2024
c39591f
fixes
paulwer Nov 12, 2024
db76adb
chore: cleanup namings for fixtures & add tests for simple UnionTypes
paulwer Nov 12, 2024
42f85a6
Merge branch 'next' into feat-package-class-validator-support
paulwer Nov 12, 2024
d9c952c
fixes
paulwer Nov 12, 2024
771a6c5
Merge branch 'next' into feat-package-class-validator-support
paulwer Nov 27, 2024
8705bd8
Merge branch 'next' into feat-package-class-validator-support
scopsy Dec 2, 2024
bb0e949
feat: cspell
scopsy Dec 2, 2024
1c7dc73
test: Add tests for enhanced type inference system
rifont Dec 2, 2024
2c1a969
Merge branch 'feat-package-class-validator-support' of https://github…
rifont Dec 2, 2024
52886b1
refactor(workflow): improve data type coercion
rifont Dec 2, 2024
bb552b8
refactor(utils): relocate checkIsResponseError function
rifont Dec 3, 2024
52e7084
refactor(types): update test and stringify logic
rifont Dec 3, 2024
d14be75
build: exclude shared from circular check
rifont Dec 3, 2024
44a390f
Merge branch 'next' into feat-package-class-validator-support
rifont Dec 3, 2024
53dad23
refactor(schema): update SchemaError message wording
rifont Dec 3, 2024
905f6a5
docs: Fix typos in schema inference comments
rifont Dec 3, 2024
49cc45d
style(validator): fix import extensions warnings
rifont Dec 3, 2024
7beb058
Merge branch 'next' into feat-package-class-validator-support
rifont Dec 4, 2024
48a81af
Merge branch 'next' into feat-package-class-validator-support
rifont Dec 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,8 @@
"rstrip",
"truncatewords",
"xmlschema",
"jsonify"
"jsonify",
"metadatas"
],
"flagWords": [],
"patterns": [
Expand Down
22 changes: 21 additions & 1 deletion packages/framework/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"build:watch": "tsup --watch",
"postbuild": "pnpm run check:exports && pnpm check:circulars",
"check:exports": "attw --pack .",
"check:circulars": "madge --circular --extensions ts ./src",
"check:circulars": "madge --circular --extensions ts --exclude ../../shared ./src",
Copy link
Collaborator

@rifont rifont Dec 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SokratisVidros is seems that Framework is still detecting circular dependency issues from Framework, even though no issues are traced back to Framework (see logs below in collapsible). Note, shared does not report these issues using madge on it's own check:circulars script.

Furthermore it appears the PR removing shared circulars had a run pulled from local cache on CI, so this removal was never tested. I am reverting for now as it's a false-positive.

Details

1) ../../shared/dist/cjs/dto/index.d.ts > ../../shared/dist/cjs/dto/events/index.d.ts > ../../shared/dist/cjs/dto/events/event.interface.d.ts > ../../shared/dist/cjs/types/index.d.ts > ../../shared/dist/cjs/types/clerk/index.d.ts > ../../shared/dist/cjs/types/clerk/types.d.ts
2) ../../shared/dist/cjs/types/index.d.ts > ../../shared/dist/cjs/types/clerk/index.d.ts > ../../shared/dist/cjs/types/clerk/types.d.ts > ../../shared/dist/cjs/entities/user/index.d.ts > ../../shared/dist/cjs/entities/user/user.interface.d.ts
3) ../../shared/dist/cjs/types/index.d.ts > ../../shared/dist/cjs/types/subscriber/index.d.ts > ../../shared/dist/cjs/consts/index.d.ts > ../../shared/dist/cjs/consts/handlebar-helpers/index.d.ts > ../../shared/dist/cjs/consts/handlebar-helpers/getTemplateVariables.d.ts
4) ../../shared/dist/cjs/dto/index.d.ts > ../../shared/dist/cjs/dto/events/index.d.ts > ../../shared/dist/cjs/dto/events/event.interface.d.ts > ../../shared/dist/cjs/types/index.d.ts > ../../shared/dist/cjs/types/subscriber/index.d.ts > ../../shared/dist/cjs/consts/index.d.ts > ../../shared/dist/cjs/consts/notification-item-buttons/index.d.ts > ../../shared/dist/cjs/consts/notification-item-buttons/notificationItemButton.d.ts > ../../shared/dist/cjs/entities/messages/index.d.ts > ../../shared/dist/cjs/entities/messages/messages.interface.d.ts > ../../shared/dist/cjs/entities/notification-template/index.d.ts > ../../shared/dist/cjs/entities/notification-template/notification-template.interface.d.ts > ../../shared/dist/cjs/entities/message-template/index.d.ts > ../../shared/dist/cjs/entities/message-template/message-template.interface.d.ts
5) ../../shared/dist/cjs/entities/messages/index.d.ts > ../../shared/dist/cjs/entities/messages/messages.interface.d.ts > ../../shared/dist/cjs/entities/notification-template/index.d.ts > ../../shared/dist/cjs/entities/notification-template/notification-template.interface.d.ts > ../../shared/dist/cjs/entities/message-template/index.d.ts > ../../shared/dist/cjs/entities/message-template/message-template.interface.d.ts
6) ../../shared/dist/cjs/types/index.d.ts > ../../shared/dist/cjs/types/subscriber/index.d.ts > ../../shared/dist/cjs/consts/index.d.ts > ../../shared/dist/cjs/consts/notification-item-buttons/index.d.ts > ../../shared/dist/cjs/consts/notification-item-buttons/notificationItemButton.d.ts > ../../shared/dist/cjs/entities/messages/index.d.ts > ../../shared/dist/cjs/entities/messages/messages.interface.d.ts > ../../shared/dist/cjs/entities/notification-template/index.d.ts > ../../shared/dist/cjs/entities/notification-template/notification-template.interface.d.ts > ../../shared/dist/cjs/entities/message-template/index.d.ts > ../../shared/dist/cjs/entities/message-template/message-template.interface.d.ts
7) ../../shared/dist/cjs/types/index.d.ts > ../../shared/dist/cjs/types/subscriber/index.d.ts > ../../shared/dist/cjs/consts/index.d.ts > ../../shared/dist/cjs/consts/notification-item-buttons/index.d.ts > ../../shared/dist/cjs/consts/notification-item-buttons/notificationItemButton.d.ts > ../../shared/dist/cjs/entities/messages/index.d.ts > ../../shared/dist/cjs/entities/messages/messages.interface.d.ts > ../../shared/dist/cjs/entities/notification-template/index.d.ts > ../../shared/dist/cjs/entities/notification-template/notification-template.interface.d.ts > ../../shared/dist/cjs/entities/step/index.d.ts
8) ../../shared/dist/cjs/entities/notification-template/index.d.ts > ../../shared/dist/cjs/entities/notification-template/notification-template.interface.d.ts > ../../shared/dist/cjs/entities/subscriber-preference/index.d.ts > ../../shared/dist/cjs/entities/subscriber-preference/subscriber-preference.interface.d.ts
9) ../../shared/dist/cjs/types/index.d.ts > ../../shared/dist/cjs/types/subscriber/index.d.ts > ../../shared/dist/cjs/consts/index.d.ts > ../../shared/dist/cjs/consts/notification-item-buttons/index.d.ts > ../../shared/dist/cjs/consts/notification-item-buttons/notificationItemButton.d.ts > ../../shared/dist/cjs/entities/messages/index.d.ts > ../../shared/dist/cjs/entities/messages/messages.interface.d.ts > ../../shared/dist/cjs/entities/notification-template/index.d.ts > ../../shared/dist/cjs/entities/notification-template/notification-template.interface.d.ts > ../../shared/dist/cjs/entities/subscriber-preference/index.d.ts > ../../shared/dist/cjs/entities/subscriber-preference/subscriber-preference.interface.d.ts
10) ../../shared/dist/cjs/clients/index.d.ts > ../../shared/dist/cjs/clients/workflows-client.d.ts > ../../shared/dist/cjs/dto/index.d.ts > ../../shared/dist/cjs/dto/events/index.d.ts > ../../shared/dist/cjs/dto/events/event.interface.d.ts > ../../shared/dist/cjs/types/index.d.ts > ../../shared/dist/cjs/types/subscriber/index.d.ts > ../../shared/dist/cjs/consts/index.d.ts > ../../shared/dist/cjs/consts/notification-item-buttons/index.d.ts > ../../shared/dist/cjs/consts/notification-item-buttons/notificationItemButton.d.ts > ../../shared/dist/cjs/entities/messages/index.d.ts > ../../shared/dist/cjs/entities/messages/messages.interface.d.ts > ../../shared/dist/cjs/entities/notification-template/index.d.ts > ../../shared/dist/cjs/entities/notification-template/notification-template.interface.d.ts > ../../shared/dist/cjs/index.d.ts
11) ../../shared/dist/cjs/consts/index.d.ts > ../../shared/dist/cjs/consts/notification-item-buttons/index.d.ts > ../../shared/dist/cjs/consts/notification-item-buttons/notificationItemButton.d.ts > ../../shared/dist/cjs/entities/messages/index.d.ts > ../../shared/dist/cjs/entities/messages/messages.interface.d.ts > ../../shared/dist/cjs/entities/notification-template/index.d.ts > ../../shared/dist/cjs/entities/notification-template/notification-template.interface.d.ts > ../../shared/dist/cjs/index.d.ts
12) ../../shared/dist/cjs/dto/index.d.ts > ../../shared/dist/cjs/dto/events/index.d.ts > ../../shared/dist/cjs/dto/events/event.interface.d.ts > ../../shared/dist/cjs/types/index.d.ts > ../../shared/dist/cjs/types/subscriber/index.d.ts > ../../shared/dist/cjs/consts/index.d.ts > ../../shared/dist/cjs/consts/notification-item-buttons/index.d.ts > ../../shared/dist/cjs/consts/notification-item-buttons/notificationItemButton.d.ts > ../../shared/dist/cjs/entities/messages/index.d.ts > ../../shared/dist/cjs/entities/messages/messages.interface.d.ts > ../../shared/dist/cjs/entities/notification-template/index.d.ts > ../../shared/dist/cjs/entities/notification-template/notification-template.interface.d.ts > ../../shared/dist/cjs/index.d.ts
13) ../../shared/dist/cjs/types/index.d.ts > ../../shared/dist/cjs/types/subscriber/index.d.ts > ../../shared/dist/cjs/consts/index.d.ts > ../../shared/dist/cjs/consts/notification-item-buttons/index.d.ts > ../../shared/dist/cjs/consts/notification-item-buttons/notificationItemButton.d.ts > ../../shared/dist/cjs/entities/messages/index.d.ts > ../../shared/dist/cjs/entities/messages/messages.interface.d.ts > ../../shared/dist/cjs/entities/notification-template/index.d.ts > ../../shared/dist/cjs/entities/notification-template/notification-template.interface.d.ts > ../../shared/dist/cjs/index.d.ts > ../../shared/dist/cjs/entities/environment/index.d.ts > ../../shared/dist/cjs/entities/environment/environment.interface.d.ts
14) ../../shared/dist/cjs/entities/notification-template/index.d.ts > ../../shared/dist/cjs/entities/notification-template/notification-template.interface.d.ts > ../../shared/dist/cjs/index.d.ts > ../../shared/dist/cjs/entities/job/index.d.ts > ../../shared/dist/cjs/entities/job/job.interface.d.ts
15) ../../shared/dist/cjs/types/index.d.ts > ../../shared/dist/cjs/types/subscriber/index.d.ts > ../../shared/dist/cjs/consts/index.d.ts > ../../shared/dist/cjs/consts/notification-item-buttons/index.d.ts > ../../shared/dist/cjs/consts/notification-item-buttons/notificationItemButton.d.ts > ../../shared/dist/cjs/entities/messages/index.d.ts > ../../shared/dist/cjs/entities/messages/messages.interface.d.ts > ../../shared/dist/cjs/entities/notification-template/index.d.ts > ../../shared/dist/cjs/entities/notification-template/notification-template.interface.d.ts > ../../shared/dist/cjs/index.d.ts > ../../shared/dist/cjs/entities/job/index.d.ts > ../../shared/dist/cjs/entities/job/job.interface.d.ts
16) ../../shared/dist/cjs/types/index.d.ts > ../../shared/dist/cjs/types/subscriber/index.d.ts > ../../shared/dist/cjs/consts/index.d.ts > ../../shared/dist/cjs/consts/notification-item-buttons/index.d.ts > ../../shared/dist/cjs/consts/notification-item-buttons/notificationItemButton.d.ts > ../../shared/dist/cjs/entities/messages/index.d.ts > ../../shared/dist/cjs/entities/messages/messages.interface.d.ts > ../../shared/dist/cjs/entities/notification-template/index.d.ts > ../../shared/dist/cjs/entities/notification-template/notification-template.interface.d.ts > ../../shared/dist/cjs/index.d.ts > ../../shared/dist/cjs/entities/layout/index.d.ts > ../../shared/dist/cjs/entities/layout/layout.interface.d.ts
17) ../../shared/dist/cjs/entities/messages/index.d.ts > ../../shared/dist/cjs/entities/messages/messages.interface.d.ts > ../../shared/dist/cjs/entities/notification-template/index.d.ts > ../../shared/dist/cjs/entities/notification-template/notification-template.interface.d.ts > ../../shared/dist/cjs/index.d.ts
18) ../../shared/dist/cjs/entities/notification-template/index.d.ts > ../../shared/dist/cjs/entities/notification-template/notification-template.interface.d.ts > ../../shared/dist/cjs/index.d.ts
19) ../../shared/dist/cjs/dto/index.d.ts > ../../shared/dist/cjs/dto/events/index.d.ts > ../../shared/dist/cjs/dto/events/event.interface.d.ts > ../../shared/dist/cjs/types/index.d.ts > ../../shared/dist/cjs/types/subscriber/index.d.ts > ../../shared/dist/cjs/consts/index.d.ts > ../../shared/dist/cjs/consts/notification-item-buttons/index.d.ts > ../../shared/dist/cjs/consts/notification-item-buttons/notificationItemButton.d.ts > ../../shared/dist/cjs/entities/messages/index.d.ts > ../../shared/dist/cjs/entities/messages/messages.interface.d.ts > ../../shared/dist/cjs/entities/notification-template/index.d.ts > ../../shared/dist/cjs/entities/notification-template/notification-template.interface.d.ts > ../../shared/dist/cjs/index.d.ts > ../../shared/dist/cjs/entities/organization/index.d.ts > ../../shared/dist/cjs/entities/organization/organization.interface.d.ts
20) ../../shared/dist/cjs/types/index.d.ts > ../../shared/dist/cjs/types/subscriber/index.d.ts > ../../shared/dist/cjs/consts/index.d.ts > ../../shared/dist/cjs/consts/notification-item-buttons/index.d.ts > ../../shared/dist/cjs/consts/notification-item-buttons/notificationItemButton.d.ts > ../../shared/dist/cjs/entities/messages/index.d.ts > ../../shared/dist/cjs/entities/messages/messages.interface.d.ts > ../../shared/dist/cjs/entities/notification-template/index.d.ts > ../../shared/dist/cjs/entities/notification-template/notification-template.interface.d.ts > ../../shared/dist/cjs/index.d.ts > ../../shared/dist/cjs/entities/organization/index.d.ts > ../../shared/dist/cjs/entities/organization/organization.interface.d.ts
21) ../../shared/dist/cjs/consts/index.d.ts > ../../shared/dist/cjs/consts/notification-item-buttons/index.d.ts > ../../shared/dist/cjs/consts/notification-item-buttons/notificationItemButton.d.ts > ../../shared/dist/cjs/entities/messages/index.d.ts > ../../shared/dist/cjs/entities/messages/messages.interface.d.ts > ../../shared/dist/cjs/entities/notification-template/index.d.ts > ../../shared/dist/cjs/entities/notification-template/notification-template.interface.d.ts > ../../shared/dist/cjs/index.d.ts > ../../shared/dist/cjs/entities/subscriber/index.d.ts > ../../shared/dist/cjs/entities/subscriber/subscriber.interface.d.ts
22) ../../shared/dist/cjs/types/index.d.ts > ../../shared/dist/cjs/types/subscriber/index.d.ts > ../../shared/dist/cjs/consts/index.d.ts > ../../shared/dist/cjs/consts/notification-item-buttons/index.d.ts > ../../shared/dist/cjs/consts/notification-item-buttons/notificationItemButton.d.ts > ../../shared/dist/cjs/entities/messages/index.d.ts > ../../shared/dist/cjs/entities/messages/messages.interface.d.ts > ../../shared/dist/cjs/entities/notification-template/index.d.ts > ../../shared/dist/cjs/entities/notification-template/notification-template.interface.d.ts > ../../shared/dist/cjs/index.d.ts > ../../shared/dist/cjs/entities/subscriber/index.d.ts > ../../shared/dist/cjs/entities/subscriber/subscriber.interface.d.ts
23) ../../shared/dist/cjs/types/index.d.ts > ../../shared/dist/cjs/types/subscriber/index.d.ts > ../../shared/dist/cjs/consts/index.d.ts > ../../shared/dist/cjs/consts/notification-item-buttons/index.d.ts > ../../shared/dist/cjs/consts/notification-item-buttons/notificationItemButton.d.ts > ../../shared/dist/cjs/entities/messages/index.d.ts > ../../shared/dist/cjs/entities/messages/messages.interface.d.ts > ../../shared/dist/cjs/entities/notification-template/index.d.ts > ../../shared/dist/cjs/entities/notification-template/notification-template.interface.d.ts > ../../shared/dist/cjs/index.d.ts > ../../shared/dist/cjs/entities/tenant/index.d.ts > ../../shared/dist/cjs/entities/tenant/tenant.interface.d.ts
24) ../../shared/dist/cjs/entities/notification-template/index.d.ts > ../../shared/dist/cjs/entities/notification-template/notification-template.interface.d.ts > ../../shared/dist/cjs/index.d.ts > ../../shared/dist/cjs/entities/workflow-override/index.d.ts > ../../shared/dist/cjs/entities/workflow-override/workflow-override.interface.d.ts
25) ../../shared/dist/cjs/types/index.d.ts > ../../shared/dist/cjs/types/subscriber/index.d.ts > ../../shared/dist/cjs/consts/index.d.ts > ../../shared/dist/cjs/consts/notification-item-buttons/index.d.ts > ../../shared/dist/cjs/consts/notification-item-buttons/notificationItemButton.d.ts > ../../shared/dist/cjs/entities/messages/index.d.ts > ../../shared/dist/cjs/entities/messages/messages.interface.d.ts > ../../shared/dist/cjs/entities/notification-template/index.d.ts > ../../shared/dist/cjs/entities/notification-template/notification-template.interface.d.ts > ../../shared/dist/cjs/index.d.ts > ../../shared/dist/cjs/entities/workflow-override/index.d.ts > ../../shared/dist/cjs/entities/workflow-override/workflow-override.interface.d.ts
26) ../../shared/dist/cjs/types/index.d.ts > ../../shared/dist/cjs/types/subscriber/index.d.ts > ../../shared/dist/cjs/consts/index.d.ts > ../../shared/dist/cjs/consts/notification-item-buttons/index.d.ts > ../../shared/dist/cjs/consts/notification-item-buttons/notificationItemButton.d.ts > ../../shared/dist/cjs/entities/messages/index.d.ts > ../../shared/dist/cjs/entities/messages/messages.interface.d.ts > ../../shared/dist/cjs/entities/notification-template/index.d.ts > ../../shared/dist/cjs/entities/notification-template/notification-template.interface.d.ts > ../../shared/dist/cjs/index.d.ts
27) ../../shared/dist/cjs/entities/messages/index.d.ts > ../../shared/dist/cjs/entities/messages/messages.interface.d.ts > ../../shared/dist/cjs/entities/notification-template/index.d.ts > ../../shared/dist/cjs/entities/notification-template/notification-template.interface.d.ts > ../../shared/dist/cjs/index.d.ts > ../../shared/dist/cjs/utils/index.d.ts > ../../shared/dist/cjs/utils/bridge.utils.d.ts
28) ../../shared/dist/cjs/types/index.d.ts > ../../shared/dist/cjs/types/subscriber/index.d.ts > ../../shared/dist/cjs/consts/index.d.ts > ../../shared/dist/cjs/consts/notification-item-buttons/index.d.ts > ../../shared/dist/cjs/consts/notification-item-buttons/notificationItemButton.d.ts > ../../shared/dist/cjs/entities/messages/index.d.ts > ../../shared/dist/cjs/entities/messages/messages.interface.d.ts > ../../shared/dist/cjs/entities/notification-template/index.d.ts > ../../shared/dist/cjs/entities/notification-template/notification-template.interface.d.ts > ../../shared/dist/cjs/index.d.ts > ../../shared/dist/cjs/utils/index.d.ts > ../../shared/dist/cjs/utils/bridge.utils.d.ts
29) ../../shared/dist/cjs/types/index.d.ts > ../../shared/dist/cjs/types/subscriber/index.d.ts > ../../shared/dist/cjs/consts/index.d.ts > ../../shared/dist/cjs/consts/notification-item-buttons/index.d.ts > ../../shared/dist/cjs/consts/notification-item-buttons/notificationItemButton.d.ts > ../../shared/dist/cjs/entities/messages/index.d.ts > ../../shared/dist/cjs/entities/messages/messages.interface.d.ts > ../../shared/dist/cjs/entities/notification-template/index.d.ts > ../../shared/dist/cjs/entities/notification-template/notification-template.interface.d.ts > ../../shared/dist/cjs/index.d.ts > ../../shared/dist/cjs/utils/index.d.ts > ../../shared/dist/cjs/utils/buildWorkflowPreferences.d.ts
30) ../../shared/dist/cjs/types/index.d.ts > ../../shared/dist/cjs/types/subscriber/index.d.ts > ../../shared/dist/cjs/consts/index.d.ts > ../../shared/dist/cjs/consts/notification-item-buttons/index.d.ts > ../../shared/dist/cjs/consts/notification-item-buttons/notificationItemButton.d.ts > ../../shared/dist/cjs/entities/messages/index.d.ts > ../../shared/dist/cjs/entities/messages/messages.interface.d.ts > ../../shared/dist/cjs/entities/notification-template/index.d.ts > ../../shared/dist/cjs/entities/notification-template/notification-template.interface.d.ts > ../../shared/dist/cjs/index.d.ts > ../../shared/dist/cjs/utils/index.d.ts > ../../shared/dist/cjs/utils/checkIsResponseError.d.ts
31) ../../shared/dist/cjs/types/index.d.ts > ../../shared/dist/cjs/types/subscriber/index.d.ts > ../../shared/dist/cjs/consts/index.d.ts > ../../shared/dist/cjs/consts/notification-item-buttons/index.d.ts > ../../shared/dist/cjs/consts/notification-item-buttons/notificationItemButton.d.ts > ../../shared/dist/cjs/entities/messages/index.d.ts > ../../shared/dist/cjs/entities/messages/messages.interface.d.ts > ../../shared/dist/cjs/entities/notification-template/index.d.ts > ../../shared/dist/cjs/entities/notification-template/notification-template.interface.d.ts
32) ../../shared/dist/cjs/types/index.d.ts > ../../shared/dist/cjs/types/subscriber/index.d.ts > ../../shared/dist/cjs/consts/index.d.ts > ../../shared/dist/cjs/consts/notification-item-buttons/index.d.ts > ../../shared/dist/cjs/consts/notification-item-buttons/notificationItemButton.d.ts > ../../shared/dist/cjs/entities/messages/index.d.ts > ../../shared/dist/cjs/entities/messages/messages.interface.d.ts
33) ../../shared/dist/cjs/types/index.d.ts > ../../shared/dist/cjs/types/subscriber/index.d.ts > ../../shared/dist/cjs/consts/index.d.ts > ../../shared/dist/cjs/consts/preferences/index.d.ts > ../../shared/dist/cjs/consts/preferences/preferences.const.d.ts
34) ../../shared/dist/cjs/types/index.d.ts > ../../shared/dist/cjs/types/subscriber/index.d.ts > ../../shared/dist/cjs/consts/index.d.ts > ../../shared/dist/cjs/consts/productFeatureEnabledForServiceLevel.d.ts
35) ../../shared/dist/cjs/types/index.d.ts > ../../shared/dist/cjs/types/subscriber/index.d.ts > ../../shared/dist/cjs/consts/index.d.ts > ../../shared/dist/cjs/consts/providers/index.d.ts > ../../shared/dist/cjs/consts/providers/credentials/index.d.ts > ../../shared/dist/cjs/consts/providers/credentials/provider-credentials.d.ts > ../../shared/dist/cjs/consts/providers/provider.interface.d.ts
36) ../../shared/dist/cjs/types/index.d.ts > ../../shared/dist/cjs/types/subscriber/index.d.ts > ../../shared/dist/cjs/consts/index.d.ts > ../../shared/dist/cjs/consts/rate-limiting/index.d.ts > ../../shared/dist/cjs/consts/rate-limiting/apiRateLimits.d.ts
37) ../../shared/dist/cjs/dto/workflows/workflow-commons-fields.d.ts > ../../shared/dist/cjs/dto/workflows/workflow-response-dto.d.ts > ../../shared/dist/cjs/dto/workflows/create-workflow-dto.d.ts
38) ../../shared/dist/cjs/dto/workflows/update-workflow-dto.d.ts > ../../shared/dist/cjs/dto/workflows/workflow-commons-fields.d.ts > ../../shared/dist/cjs/dto/workflows/workflow-response-dto.d.ts
39) ../../shared/dist/cjs/dto/workflows/workflow-commons-fields.d.ts > ../../shared/dist/cjs/dto/workflows/workflow-response-dto.d.ts

"$comment:bump:prerelease": "This is a workaround to support `npm version prerelease` with lerna",
"bump:prerelease": "npm version prerelease --preid=alpha & PID=$!; (sleep 1 && kill -9 $PID) & wait $PID",
"release:alpha": "pnpm bump:prerelease || pnpm build && npm publish",
Expand Down Expand Up @@ -169,9 +169,13 @@
"@sveltejs/kit": ">=1.27.3",
"@vercel/node": ">=2.15.9",
"aws-lambda": ">=1.0.7",
"class-transformer": ">=0.5.1",
"class-validator": ">=0.14.0",
"class-validator-jsonschema": ">=5.0.0",
"express": ">=4.19.2",
"h3": ">=1.8.1",
"next": ">=12.0.0",
"reflect-metadata": ">=0.2.2",
"zod": ">=3.0.0",
"zod-to-json-schema": ">=3.0.0"
},
Expand Down Expand Up @@ -200,6 +204,18 @@
"next": {
"optional": true
},
"class-transformer": {
"optional": true
},
"class-validator": {
"optional": true
},
"class-validator-jsonschema": {
"optional": true
},
"reflect-metadata": {
"optional": true
},
rifont marked this conversation as resolved.
Show resolved Hide resolved
"zod": {
"optional": true
},
Expand All @@ -218,11 +234,15 @@
"@types/sanitize-html": "2.11.0",
"@vercel/node": "^2.15.9",
"aws-lambda": "^1.0.7",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.1",
"class-validator-jsonschema": "^5.0.1",
"express": "^4.19.2",
"h3": "^1.11.1",
"madge": "^8.0.0",
"next": "^13.5.4",
"prettier": "^3.2.5",
"reflect-metadata": "^0.2.2",
"ts-node": "^10.9.2",
"tsup": "^8.0.2",
"tsx": "4.16.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,27 +109,69 @@ describe('workflow function types', () => {
additionalProperties: false,
} as const;

it('should infer an unknown record type when the provided schema is for a primitive type', () => {
it('should infer an error message type when the provided schema is for a primitive type', () => {
const primitiveSchema = { type: 'string' } as const;
workflow('without-schema', async ({ step }) => {
await step.email(
'without-schema',
async (controls) => {
expectTypeOf(controls).toEqualTypeOf<Record<string, unknown>>();
expectTypeOf(controls).toEqualTypeOf<{
SchemaError: "Schema must describe an object data structure. Got data type: 'string'";
}>();

return {
subject: 'Test subject',
body: 'Test body',
};
},
{
// @ts-expect-error - schema is for a primitive type
controlSchema: primitiveSchema,
}
);
});
});

it('should infer an error message type when the provided schema is for an array type', () => {
const arraySchema = { type: 'array', items: { type: 'string' } } as const;
workflow('without-schema', async ({ step }) => {
await step.email(
'without-schema',
async (controls) => {
expectTypeOf(controls).toEqualTypeOf<{
SchemaError: `Schema must describe an object data structure. Got data type: 'string[]'`;
}>();

return {
subject: 'Test subject',
body: 'Test body',
};
},
{
controlSchema: arraySchema,
}
);
});
});

it('should infer an unknown record type when the provided schema is undefined', () => {
workflow('without-schema', async ({ step }) => {
await step.email(
'without-schema',
async (controls) => {
expectTypeOf(controls).toEqualTypeOf<Record<string, unknown>>();

return {
subject: 'Test subject',
body: 'Test body',
};
},
{
controlSchema: undefined,
}
);
});
});

it('should infer correct types in the step controls', async () => {
workflow('json-schema', async ({ step }) => {
await step.email(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ export function workflow<
if (validationResult.success === false) {
throw new WorkflowPayloadInvalidError(workflowId, validationResult.errors);
}
validatedData = validationResult.data as T_PayloadValidated;
// Coerce the validated data to handle unknown matching to SchemaError
validatedData = validationResult.data as Record<string, unknown> as T_PayloadValidated;
} else {
// This type coercion provides support to trigger Workflows without a payload schema
validatedData = event.payload as unknown as T_PayloadValidated;
Expand Down
106 changes: 89 additions & 17 deletions packages/framework/src/types/schema.types/base.schema.types.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,65 @@ import { FromSchema, FromSchemaUnvalidated, Schema } from './base.schema.types';

describe('FromSchema', () => {
it('should infer an unknown record type when a generic schema is provided', () => {
expectTypeOf<FromSchema<Schema>>().toEqualTypeOf<Record<string, unknown>>();
type Test = FromSchema<Schema>;

expectTypeOf<Test>().toEqualTypeOf<Record<string, unknown>>();
});

it('should not compile when the schema is primitive', () => {
it('should not compile and infer an unknown record type when the schema is undefined', () => {
// @ts-expect-error - Type 'undefined' does not satisfy the constraint 'Schema'.
type Test = FromSchema<undefined>;

expectTypeOf<Test>().toEqualTypeOf<Record<string, unknown>>();
});

it('not compile when the schema is undefined', () => {
// @ts-expect-error - Type 'undefined' does not satisfy the constraint 'Schema'.
type Test = FromSchemaUnvalidated<undefined>;

expectTypeOf<Test>().toEqualTypeOf<Record<string, unknown>>();
});

it('should infer an error message type when the schema describes a primitive type', () => {
const primitiveSchema = { type: 'string' } as const;
type Test = FromSchema<typeof primitiveSchema>;

expectTypeOf<Test>().toEqualTypeOf<{
SchemaError: `Schema must describe an object data structure. Got data type: 'string'`;
}>();
});

it('should infer an error message type when the schema describes an array of primitive types', () => {
const primitiveSchema = { type: 'array', items: { type: 'string' } } as const;
type Test = FromSchema<typeof primitiveSchema>;

expectTypeOf<Test>().toEqualTypeOf<{
SchemaError: `Schema must describe an object data structure. Got data type: 'string[]'`;
}>();
});

it('should infer an error message type when the schema describes an array of objects', () => {
const primitiveSchema = {
type: 'array',
items: { type: 'object' },
} as const;
type Test = FromSchema<typeof primitiveSchema>;

expectTypeOf<Test>().toEqualTypeOf<{
SchemaError: `Schema must describe an object data structure. Got data type: '{ [x: string]: unknown; }[]'`;
}>();
});

// @ts-expect-error - Type '{ type: string; }' is not assignable to type '{ type: "object"; }'.
it('should infer an error message type when the schema describes an array of unknown types', () => {
const primitiveSchema = {
type: 'array',
items: {},
} as const;
type Test = FromSchema<typeof primitiveSchema>;

expectTypeOf<Test>().toEqualTypeOf<never>();
expectTypeOf<Test>().toEqualTypeOf<{
SchemaError: `Schema must describe an object data structure. Got data type: 'unknown[]'`;
}>();
});

it('should infer a Json Schema type', () => {
Expand All @@ -26,7 +75,9 @@ describe('FromSchema', () => {
additionalProperties: false,
} as const;

expectTypeOf<FromSchema<typeof testJsonSchema>>().toEqualTypeOf<{ foo: string; bar?: string }>();
type Test = FromSchema<typeof testJsonSchema>;

expectTypeOf<Test>().toEqualTypeOf<{ foo: string; bar?: string }>();
});

it('should infer a Zod Schema type', () => {
Expand All @@ -35,22 +86,28 @@ describe('FromSchema', () => {
bar: z.string().optional(),
});

expectTypeOf<FromSchema<typeof testZodSchema>>().toEqualTypeOf<{ foo: string; bar?: string }>();
type Test = FromSchema<typeof testZodSchema>;

expectTypeOf<Test>().toEqualTypeOf<{ foo: string; bar?: string }>();
});

it('should infer a Class Schema type', () => {
class TestSchema {
foo: string = 'bar';
bar?: string;
}

type Test = FromSchema<typeof TestSchema>;

expectTypeOf<Test>().toEqualTypeOf<{ foo: string; bar?: string }>();
});
});

describe('FromSchemaUnvalidated', () => {
it('should infer an unknown record type when a generic schema is provided', () => {
expectTypeOf<FromSchemaUnvalidated<Schema>>().toEqualTypeOf<Record<string, unknown>>();
});
type Test = FromSchemaUnvalidated<Schema>;

it('should not compile when the schema is primitive', () => {
const primitiveSchema = { type: 'string' } as const;

// @ts-expect-error - Type '{ type: string; }' is not assignable to type '{ type: "object"; }'.
type Test = FromSchemaUnvalidated<typeof primitiveSchema>;

expectTypeOf<Test>().toEqualTypeOf<never>();
expectTypeOf<Test>().toEqualTypeOf<Record<string, unknown>>();
});

it('should infer a Json Schema type', () => {
Expand All @@ -63,7 +120,9 @@ describe('FromSchemaUnvalidated', () => {
additionalProperties: false,
} as const;

expectTypeOf<FromSchemaUnvalidated<typeof testJsonSchema>>().toEqualTypeOf<{ foo?: string; bar?: string }>();
type Test = FromSchemaUnvalidated<typeof testJsonSchema>;

expectTypeOf<Test>().toEqualTypeOf<{ foo?: string; bar?: string }>();
});

it('should infer a Zod Schema type', () => {
Expand All @@ -72,6 +131,19 @@ describe('FromSchemaUnvalidated', () => {
bar: z.string().optional(),
});

expectTypeOf<FromSchemaUnvalidated<typeof testZodSchema>>().toEqualTypeOf<{ foo?: string; bar?: string }>();
type Test = FromSchemaUnvalidated<typeof testZodSchema>;

expectTypeOf<Test>().toEqualTypeOf<{ foo?: string; bar?: string }>();
});

it('should infer a Class Schema type', () => {
class TestClassSchema {
foo?: string = 'bar';
bar?: string;
}

type Test = FromSchemaUnvalidated<typeof TestClassSchema>;

expectTypeOf<Test>().toEqualTypeOf<{ foo?: string; bar?: string }>();
});
});
31 changes: 29 additions & 2 deletions packages/framework/src/types/schema.types/base.schema.types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import type { InferJsonSchema, JsonSchemaMinimal } from './json.schema.types';
import type { InferZodSchema, ZodSchemaMinimal } from './zod.schema.types';
import type { InferClassValidatorSchema, ClassValidatorSchema } from './class.schema.types';
import type { Stringify } from '../util.types';

/**
* A schema used to validate a JSON object.
*/
export type Schema = JsonSchemaMinimal | ZodSchemaMinimal;
export type Schema = JsonSchemaMinimal | ZodSchemaMinimal | ClassValidatorSchema;

/**
* Main utility type for schema inference
Expand All @@ -14,7 +16,32 @@
*/
type InferSchema<T extends Schema, Options extends { validated: boolean }> =
| InferJsonSchema<T, Options>
| InferZodSchema<T, Options>;
| InferClassValidatorSchema<T, Options>
| InferZodSchema<T, Options>
| never extends infer U
? /*
* Use a distributive conditional type to detect if all inferred types are `never`.
* When all inferred types are `never`, return an unknown record.
*
* Each schema inferrence must return `never` type when:

Check warning on line 26 in packages/framework/src/types/schema.types/base.schema.types.ts

View workflow job for this annotation

GitHub Actions / Spell check

Unknown word (inferrence)
* - The schema is generic (i.e. not a concrete schema type)
* - The schema is not supported (i.e. tried to specify `string` as the schema type)
* - The schema is undefined
*
* @see - https://www.typescriptlang.org/docs/handbook/2/conditional-types.html#distributive-conditional-types
*/
[U] extends [never]
? // When all inferred types are `never`, return an unknown record.
Record<string, unknown>
: // The type inferrence did not return `never`. Ensure the inferred type is a record type, as only objects are supported.

Check warning on line 36 in packages/framework/src/types/schema.types/base.schema.types.ts

View workflow job for this annotation

GitHub Actions / Spell check

Unknown word (inferrence)
U extends Record<string, unknown>
? // Got a record type, return it.
U
: // The schema describes a non-record type, return an error message.
{
SchemaError: `Schema must describe an object data structure. Got data type: '${Stringify<U>}'`;
}
: never;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handle all the error cases here. We now provide a nice error message when attempting to access data where an invalid schema is provided, for example:
image


/**
* Infer the type of a Schema for unvalidated data.
Expand Down
Loading
Loading