@opensaas/stack-core 0.43.0 → 0.44.0-alpha.1
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/CHANGELOG.md +2720 -0
- package/README.md +182 -115
- package/dist/.build-hash +1 -0
- package/dist/access/declared-dependencies.d.ts +102 -88
- package/dist/access/declared-dependencies.d.ts.map +1 -1
- package/dist/access/declared-dependencies.js +83 -71
- package/dist/access/declared-dependencies.js.map +1 -1
- package/dist/access/depth-limits.d.ts +4 -0
- package/dist/access/depth-limits.d.ts.map +1 -1
- package/dist/access/depth-limits.js +4 -0
- package/dist/access/depth-limits.js.map +1 -1
- package/dist/access/engine.d.ts +68 -20
- package/dist/access/engine.d.ts.map +1 -1
- package/dist/access/engine.js +151 -37
- package/dist/access/engine.js.map +1 -1
- package/dist/access/errors.d.ts +33 -48
- package/dist/access/errors.d.ts.map +1 -1
- package/dist/access/errors.js +73 -63
- package/dist/access/errors.js.map +1 -1
- package/dist/access/field-access.d.ts +76 -5
- package/dist/access/field-access.d.ts.map +1 -1
- package/dist/access/field-access.js +235 -61
- package/dist/access/field-access.js.map +1 -1
- package/dist/access/field-visibility.d.ts +50 -4
- package/dist/access/field-visibility.d.ts.map +1 -1
- package/dist/access/field-visibility.js +143 -160
- package/dist/access/field-visibility.js.map +1 -1
- package/dist/access/index.d.ts +5 -12
- package/dist/access/index.d.ts.map +1 -1
- package/dist/access/index.js +6 -19
- package/dist/access/index.js.map +1 -1
- package/dist/access/orm-client.d.ts +19 -0
- package/dist/access/orm-client.d.ts.map +1 -0
- package/dist/access/orm-client.js +37 -0
- package/dist/access/orm-client.js.map +1 -0
- package/dist/access/query-validation.d.ts +7 -129
- package/dist/access/query-validation.d.ts.map +1 -1
- package/dist/access/query-validation.js +12 -314
- package/dist/access/query-validation.js.map +1 -1
- package/dist/access/system-fields.d.ts +2 -0
- package/dist/access/system-fields.d.ts.map +1 -0
- package/dist/access/system-fields.js +7 -0
- package/dist/access/system-fields.js.map +1 -0
- package/dist/access/transaction-registry.d.ts +25 -2
- package/dist/access/transaction-registry.d.ts.map +1 -1
- package/dist/access/transaction-registry.js +34 -17
- package/dist/access/transaction-registry.js.map +1 -1
- package/dist/access/types.d.ts +217 -131
- package/dist/access/types.d.ts.map +1 -1
- package/dist/config/field-kind.d.ts +66 -0
- package/dist/config/field-kind.d.ts.map +1 -0
- package/dist/config/field-kind.js +63 -0
- package/dist/config/field-kind.js.map +1 -0
- package/dist/config/hook-only-fields.d.ts +3 -0
- package/dist/config/hook-only-fields.d.ts.map +1 -0
- package/dist/config/hook-only-fields.js +17 -0
- package/dist/config/hook-only-fields.js.map +1 -0
- package/dist/config/index.d.ts +3 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +6 -3
- package/dist/config/index.js.map +1 -1
- package/dist/config/mcp-tool-names.d.ts +3 -0
- package/dist/config/mcp-tool-names.d.ts.map +1 -0
- package/dist/config/mcp-tool-names.js +25 -0
- package/dist/config/mcp-tool-names.js.map +1 -0
- package/dist/config/nav-count.d.ts.map +1 -1
- package/dist/config/nav-count.js +4 -4
- package/dist/config/nav-count.js.map +1 -1
- package/dist/config/plugin-engine.d.ts +8 -2
- package/dist/config/plugin-engine.d.ts.map +1 -1
- package/dist/config/plugin-engine.js +102 -38
- package/dist/config/plugin-engine.js.map +1 -1
- package/dist/config/types.d.ts +966 -614
- package/dist/config/types.d.ts.map +1 -1
- package/dist/context/apply-defaults.d.ts +18 -1
- package/dist/context/apply-defaults.d.ts.map +1 -1
- package/dist/context/apply-defaults.js +30 -4
- package/dist/context/apply-defaults.js.map +1 -1
- package/dist/context/engine-context.d.ts +73 -0
- package/dist/context/engine-context.d.ts.map +1 -0
- package/dist/context/engine-context.js +67 -0
- package/dist/context/engine-context.js.map +1 -0
- package/dist/context/hook-pipeline.d.ts +9 -2
- package/dist/context/hook-pipeline.d.ts.map +1 -1
- package/dist/context/hook-pipeline.js +5 -4
- package/dist/context/hook-pipeline.js.map +1 -1
- package/dist/context/index.d.ts +98 -89
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +917 -722
- package/dist/context/index.js.map +1 -1
- package/dist/context/junction.d.ts +59 -0
- package/dist/context/junction.d.ts.map +1 -0
- package/dist/context/junction.js +126 -0
- package/dist/context/junction.js.map +1 -0
- package/dist/context/plugin-field-read.d.ts +33 -0
- package/dist/context/plugin-field-read.d.ts.map +1 -0
- package/dist/context/plugin-field-read.js +41 -0
- package/dist/context/plugin-field-read.js.map +1 -0
- package/dist/context/plugin-field-write.d.ts +104 -0
- package/dist/context/plugin-field-write.d.ts.map +1 -0
- package/dist/context/plugin-field-write.js +184 -0
- package/dist/context/plugin-field-write.js.map +1 -0
- package/dist/context/relationship-input.d.ts +146 -0
- package/dist/context/relationship-input.d.ts.map +1 -0
- package/dist/context/relationship-input.js +453 -0
- package/dist/context/relationship-input.js.map +1 -0
- package/dist/context/transaction-boundary.d.ts +54 -28
- package/dist/context/transaction-boundary.d.ts.map +1 -1
- package/dist/context/transaction-boundary.js +87 -169
- package/dist/context/transaction-boundary.js.map +1 -1
- package/dist/context/write-pipeline.d.ts +33 -51
- package/dist/context/write-pipeline.d.ts.map +1 -1
- package/dist/context/write-pipeline.js +372 -185
- package/dist/context/write-pipeline.js.map +1 -1
- package/dist/contract/dependencies.d.ts +88 -0
- package/dist/contract/dependencies.d.ts.map +1 -0
- package/dist/contract/dependencies.js +237 -0
- package/dist/contract/dependencies.js.map +1 -0
- package/dist/contract/derive.d.ts +49 -0
- package/dist/contract/derive.d.ts.map +1 -0
- package/dist/contract/derive.js +540 -0
- package/dist/contract/derive.js.map +1 -0
- package/dist/contract/fixtures/contract-configs.d.ts +64 -0
- package/dist/contract/fixtures/contract-configs.d.ts.map +1 -0
- package/dist/contract/fixtures/contract-configs.js +345 -0
- package/dist/contract/fixtures/contract-configs.js.map +1 -0
- package/dist/contract/id-boundary.d.ts +53 -0
- package/dist/contract/id-boundary.d.ts.map +1 -0
- package/dist/contract/id-boundary.js +76 -0
- package/dist/contract/id-boundary.js.map +1 -0
- package/dist/contract/index.d.ts +8 -0
- package/dist/contract/index.d.ts.map +1 -0
- package/dist/contract/index.js +11 -0
- package/dist/contract/index.js.map +1 -0
- package/dist/contract/prisma.d.ts +58 -0
- package/dist/contract/prisma.d.ts.map +1 -0
- package/dist/contract/prisma.js +282 -0
- package/dist/contract/prisma.js.map +1 -0
- package/dist/contract/relation-graph.d.ts +70 -0
- package/dist/contract/relation-graph.d.ts.map +1 -0
- package/dist/contract/relation-graph.js +113 -0
- package/dist/contract/relation-graph.js.map +1 -0
- package/dist/contract/types.d.ts +135 -0
- package/dist/contract/types.d.ts.map +1 -0
- package/dist/contract/types.js +2 -0
- package/dist/contract/types.js.map +1 -0
- package/dist/db/client.d.ts +55 -0
- package/dist/db/client.d.ts.map +1 -0
- package/dist/db/client.js +73 -0
- package/dist/db/client.js.map +1 -0
- package/dist/db/dev-database.d.ts +124 -0
- package/dist/db/dev-database.d.ts.map +1 -0
- package/dist/db/dev-database.js +291 -0
- package/dist/db/dev-database.js.map +1 -0
- package/dist/db/password-front.d.ts +10 -0
- package/dist/db/password-front.d.ts.map +1 -0
- package/dist/db/password-front.js +147 -0
- package/dist/db/password-front.js.map +1 -0
- package/dist/db/process-identity.d.ts +36 -0
- package/dist/db/process-identity.d.ts.map +1 -0
- package/dist/db/process-identity.js +114 -0
- package/dist/db/process-identity.js.map +1 -0
- package/dist/db/state-file.d.ts +54 -0
- package/dist/db/state-file.d.ts.map +1 -0
- package/dist/db/state-file.js +91 -0
- package/dist/db/state-file.js.map +1 -0
- package/dist/db/url.d.ts +89 -0
- package/dist/db/url.d.ts.map +1 -0
- package/dist/db/url.js +118 -0
- package/dist/db/url.js.map +1 -0
- package/dist/extend.d.ts +13 -2
- package/dist/extend.d.ts.map +1 -1
- package/dist/extend.js +24 -1
- package/dist/extend.js.map +1 -1
- package/dist/fields/index.d.ts +87 -42
- package/dist/fields/index.d.ts.map +1 -1
- package/dist/fields/index.js +457 -677
- package/dist/fields/index.js.map +1 -1
- package/dist/filter/collect.d.ts +3 -4
- package/dist/filter/collect.d.ts.map +1 -1
- package/dist/filter/collect.js +2 -2
- package/dist/filter/collect.js.map +1 -1
- package/dist/filter/index.d.ts +1 -2
- package/dist/filter/index.d.ts.map +1 -1
- package/dist/filter/index.js +0 -1
- package/dist/filter/index.js.map +1 -1
- package/dist/filter/map.d.ts +12 -5
- package/dist/filter/map.d.ts.map +1 -1
- package/dist/filter/map.js +47 -19
- package/dist/filter/map.js.map +1 -1
- package/dist/filter/types.d.ts +10 -24
- package/dist/filter/types.d.ts.map +1 -1
- package/dist/filter/types.js +2 -11
- package/dist/filter/types.js.map +1 -1
- package/dist/hooks/index.d.ts +22 -31
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +33 -37
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/transition-guard.d.ts +61 -0
- package/dist/hooks/transition-guard.d.ts.map +1 -0
- package/dist/hooks/transition-guard.js +93 -0
- package/dist/hooks/transition-guard.js.map +1 -0
- package/dist/index.d.ts +52 -16
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +105 -51
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +4 -2
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +16 -0
- package/dist/internal.js.map +1 -1
- package/dist/lib/case-utils.d.ts +0 -1
- package/dist/lib/case-utils.d.ts.map +1 -1
- package/dist/lib/case-utils.js +0 -3
- package/dist/lib/case-utils.js.map +1 -1
- package/dist/lib/client-safe-error.d.ts +9 -0
- package/dist/lib/client-safe-error.d.ts.map +1 -0
- package/dist/lib/client-safe-error.js +23 -0
- package/dist/lib/client-safe-error.js.map +1 -0
- package/dist/lib/database-errors.d.ts +78 -0
- package/dist/lib/database-errors.d.ts.map +1 -0
- package/dist/lib/database-errors.js +148 -0
- package/dist/lib/database-errors.js.map +1 -0
- package/dist/lib/null-prototype-registry.d.ts +9 -0
- package/dist/lib/null-prototype-registry.d.ts.map +1 -0
- package/dist/lib/null-prototype-registry.js +11 -0
- package/dist/lib/null-prototype-registry.js.map +1 -0
- package/dist/lib/prisma-errors.d.ts +30 -32
- package/dist/lib/prisma-errors.d.ts.map +1 -1
- package/dist/lib/prisma-errors.js +86 -46
- package/dist/lib/prisma-errors.js.map +1 -1
- package/dist/lib/process-global.d.ts +23 -0
- package/dist/lib/process-global.d.ts.map +1 -0
- package/dist/lib/process-global.js +33 -0
- package/dist/lib/process-global.js.map +1 -0
- package/dist/lib/warn-once.d.ts +7 -0
- package/dist/lib/warn-once.d.ts.map +1 -0
- package/dist/lib/warn-once.js +13 -0
- package/dist/lib/warn-once.js.map +1 -0
- package/dist/mcp/advertise.d.ts +16 -0
- package/dist/mcp/advertise.d.ts.map +1 -0
- package/dist/mcp/advertise.js +25 -0
- package/dist/mcp/advertise.js.map +1 -0
- package/dist/mcp/arguments.d.ts +10 -0
- package/dist/mcp/arguments.d.ts.map +1 -0
- package/dist/mcp/arguments.js +143 -0
- package/dist/mcp/arguments.js.map +1 -0
- package/dist/mcp/field-schema.d.ts +50 -5
- package/dist/mcp/field-schema.d.ts.map +1 -1
- package/dist/mcp/field-schema.js +137 -14
- package/dist/mcp/field-schema.js.map +1 -1
- package/dist/mcp/handler.d.ts +16 -5
- package/dist/mcp/handler.d.ts.map +1 -1
- package/dist/mcp/handler.js +404 -126
- package/dist/mcp/handler.js.map +1 -1
- package/dist/mcp/index.d.ts +1 -0
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +1 -0
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/projection.d.ts +42 -34
- package/dist/mcp/projection.d.ts.map +1 -1
- package/dist/mcp/projection.js +246 -200
- package/dist/mcp/projection.js.map +1 -1
- package/dist/mcp/tool-error.d.ts +8 -0
- package/dist/mcp/tool-error.d.ts.map +1 -0
- package/dist/mcp/tool-error.js +11 -0
- package/dist/mcp/tool-error.js.map +1 -0
- package/dist/mcp/types.d.ts +3 -2
- package/dist/mcp/types.d.ts.map +1 -1
- package/dist/mcp/where-id-boundary.d.ts +28 -0
- package/dist/mcp/where-id-boundary.d.ts.map +1 -0
- package/dist/mcp/where-id-boundary.js +187 -0
- package/dist/mcp/where-id-boundary.js.map +1 -0
- package/dist/origin.d.ts +147 -0
- package/dist/origin.d.ts.map +1 -0
- package/dist/origin.js +191 -0
- package/dist/origin.js.map +1 -0
- package/dist/query/relationship-options.d.ts +35 -6
- package/dist/query/relationship-options.d.ts.map +1 -1
- package/dist/query/relationship-options.js +33 -23
- package/dist/query/relationship-options.js.map +1 -1
- package/dist/secured/aggregate.d.ts +32 -0
- package/dist/secured/aggregate.d.ts.map +1 -0
- package/dist/secured/aggregate.js +31 -0
- package/dist/secured/aggregate.js.map +1 -0
- package/dist/secured/include.d.ts +320 -0
- package/dist/secured/include.d.ts.map +1 -0
- package/dist/secured/include.js +650 -0
- package/dist/secured/include.js.map +1 -0
- package/dist/secured/lock.d.ts +127 -0
- package/dist/secured/lock.d.ts.map +1 -0
- package/dist/secured/lock.js +275 -0
- package/dist/secured/lock.js.map +1 -0
- package/dist/secured/lower.d.ts +82 -0
- package/dist/secured/lower.d.ts.map +1 -0
- package/dist/secured/lower.js +162 -0
- package/dist/secured/lower.js.map +1 -0
- package/dist/secured/operators.d.ts +7 -0
- package/dist/secured/operators.d.ts.map +1 -0
- package/dist/secured/operators.js +18 -0
- package/dist/secured/operators.js.map +1 -0
- package/dist/secured/read.d.ts +208 -0
- package/dist/secured/read.d.ts.map +1 -0
- package/dist/secured/read.js +1245 -0
- package/dist/secured/read.js.map +1 -0
- package/dist/secured/select.d.ts +87 -0
- package/dist/secured/select.d.ts.map +1 -0
- package/dist/secured/select.js +250 -0
- package/dist/secured/select.js.map +1 -0
- package/dist/secured/vector.d.ts +58 -0
- package/dist/secured/vector.d.ts.map +1 -0
- package/dist/secured/vector.js +113 -0
- package/dist/secured/vector.js.map +1 -0
- package/dist/secured/vocabulary.d.ts +227 -0
- package/dist/secured/vocabulary.d.ts.map +1 -0
- package/dist/secured/vocabulary.js +578 -0
- package/dist/secured/vocabulary.js.map +1 -0
- package/dist/secured/write.d.ts +58 -0
- package/dist/secured/write.d.ts.map +1 -0
- package/dist/secured/write.js +87 -0
- package/dist/secured/write.js.map +1 -0
- package/dist/testing/context.d.ts +236 -0
- package/dist/testing/context.d.ts.map +1 -0
- package/dist/testing/context.js +457 -0
- package/dist/testing/context.js.map +1 -0
- package/dist/testing/escape.d.ts +83 -0
- package/dist/testing/escape.d.ts.map +1 -0
- package/dist/testing/escape.js +148 -0
- package/dist/testing/escape.js.map +1 -0
- package/dist/testing/extensions.d.ts +48 -0
- package/dist/testing/extensions.d.ts.map +1 -0
- package/dist/testing/extensions.js +107 -0
- package/dist/testing/extensions.js.map +1 -0
- package/dist/testing/index.d.ts +5 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +11 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/plans.d.ts +64 -0
- package/dist/testing/plans.d.ts.map +1 -0
- package/dist/testing/plans.js +47 -0
- package/dist/testing/plans.js.map +1 -0
- package/dist/types/context.d.ts +110 -0
- package/dist/types/context.d.ts.map +1 -0
- package/dist/types/context.js +2 -0
- package/dist/types/context.js.map +1 -0
- package/dist/types/contract.d.ts +198 -0
- package/dist/types/contract.d.ts.map +1 -0
- package/dist/types/contract.js +2 -0
- package/dist/types/contract.js.map +1 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +11 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/inputs.d.ts +83 -0
- package/dist/types/inputs.d.ts.map +1 -0
- package/dist/types/inputs.js +2 -0
- package/dist/types/inputs.js.map +1 -0
- package/dist/types/rows.d.ts +76 -0
- package/dist/types/rows.d.ts.map +1 -0
- package/dist/types/rows.js +2 -0
- package/dist/types/rows.js.map +1 -0
- package/dist/types/secured-list.d.ts +396 -0
- package/dist/types/secured-list.d.ts.map +1 -0
- package/dist/types/secured-list.js +2 -0
- package/dist/types/secured-list.js.map +1 -0
- package/dist/unsafe.d.ts +162 -0
- package/dist/unsafe.d.ts.map +1 -0
- package/dist/unsafe.js +177 -0
- package/dist/unsafe.js.map +1 -0
- package/dist/validation/config-refusal.d.ts +16 -0
- package/dist/validation/config-refusal.d.ts.map +1 -0
- package/dist/validation/config-refusal.js +2 -0
- package/dist/validation/config-refusal.js.map +1 -0
- package/dist/validation/database-config.d.ts +19 -0
- package/dist/validation/database-config.d.ts.map +1 -0
- package/dist/validation/database-config.js +221 -0
- package/dist/validation/database-config.js.map +1 -0
- package/dist/validation/default-value.d.ts +21 -0
- package/dist/validation/default-value.d.ts.map +1 -0
- package/dist/validation/default-value.js +72 -0
- package/dist/validation/default-value.js.map +1 -0
- package/dist/validation/extension-packs.d.ts +11 -0
- package/dist/validation/extension-packs.d.ts.map +1 -0
- package/dist/validation/extension-packs.js +53 -0
- package/dist/validation/extension-packs.js.map +1 -0
- package/dist/validation/field-config.d.ts +35 -21
- package/dist/validation/field-config.d.ts.map +1 -1
- package/dist/validation/field-config.js +51 -41
- package/dist/validation/field-config.js.map +1 -1
- package/dist/validation/field-names.d.ts +15 -0
- package/dist/validation/field-names.d.ts.map +1 -0
- package/dist/validation/field-names.js +155 -0
- package/dist/validation/field-names.js.map +1 -0
- package/dist/validation/identifier-names.d.ts +4 -0
- package/dist/validation/identifier-names.d.ts.map +1 -0
- package/dist/validation/identifier-names.js +39 -0
- package/dist/validation/identifier-names.js.map +1 -0
- package/dist/validation/needs-closure.d.ts +20 -30
- package/dist/validation/needs-closure.d.ts.map +1 -1
- package/dist/validation/needs-closure.js +29 -105
- package/dist/validation/needs-closure.js.map +1 -1
- package/dist/validation/relations.d.ts +17 -0
- package/dist/validation/relations.d.ts.map +1 -0
- package/dist/validation/relations.js +268 -0
- package/dist/validation/relations.js.map +1 -0
- package/dist/validation/schema.d.ts.map +1 -1
- package/dist/validation/schema.js +1 -3
- package/dist/validation/schema.js.map +1 -1
- package/dist/where/like.d.ts +32 -0
- package/dist/where/like.d.ts.map +1 -0
- package/dist/where/like.js +42 -0
- package/dist/where/like.js.map +1 -0
- package/package.json +70 -8
- package/.turbo/turbo-build.log +0 -4
- package/CLAUDE.md +0 -609
- package/dist/access/access-filter.d.ts +0 -241
- package/dist/access/access-filter.d.ts.map +0 -1
- package/dist/access/access-filter.js +0 -692
- package/dist/access/access-filter.js.map +0 -1
- package/dist/access/access-filter.test.d.ts +0 -2
- package/dist/access/access-filter.test.d.ts.map +0 -1
- package/dist/access/access-filter.test.js +0 -1256
- package/dist/access/access-filter.test.js.map +0 -1
- package/dist/access/declared-dependencies.test.d.ts +0 -2
- package/dist/access/declared-dependencies.test.d.ts.map +0 -1
- package/dist/access/declared-dependencies.test.js +0 -226
- package/dist/access/declared-dependencies.test.js.map +0 -1
- package/dist/access/denied-relation-visibility.test.d.ts +0 -2
- package/dist/access/denied-relation-visibility.test.d.ts.map +0 -1
- package/dist/access/denied-relation-visibility.test.js +0 -114
- package/dist/access/denied-relation-visibility.test.js.map +0 -1
- package/dist/access/engine.test.d.ts +0 -2
- package/dist/access/engine.test.d.ts.map +0 -1
- package/dist/access/engine.test.js +0 -56
- package/dist/access/engine.test.js.map +0 -1
- package/dist/access/field-access.test.d.ts +0 -2
- package/dist/access/field-access.test.d.ts.map +0 -1
- package/dist/access/field-access.test.js +0 -635
- package/dist/access/field-access.test.js.map +0 -1
- package/dist/access/multi-column-read-write.test.d.ts +0 -2
- package/dist/access/multi-column-read-write.test.d.ts.map +0 -1
- package/dist/access/multi-column-read-write.test.js +0 -183
- package/dist/access/multi-column-read-write.test.js.map +0 -1
- package/dist/access/relationship-count.d.ts +0 -98
- package/dist/access/relationship-count.d.ts.map +0 -1
- package/dist/access/relationship-count.js +0 -262
- package/dist/access/relationship-count.js.map +0 -1
- package/dist/access/relationship-count.test.d.ts +0 -2
- package/dist/access/relationship-count.test.d.ts.map +0 -1
- package/dist/access/relationship-count.test.js +0 -247
- package/dist/access/relationship-count.test.js.map +0 -1
- package/dist/access/relationship-label-filter.d.ts +0 -45
- package/dist/access/relationship-label-filter.d.ts.map +0 -1
- package/dist/access/relationship-label-filter.js +0 -22
- package/dist/access/relationship-label-filter.js.map +0 -1
- package/dist/access/relationship-label-filter.test.d.ts +0 -2
- package/dist/access/relationship-label-filter.test.d.ts.map +0 -1
- package/dist/access/relationship-label-filter.test.js +0 -89
- package/dist/access/relationship-label-filter.test.js.map +0 -1
- package/dist/access/synthetic-include-read.test.d.ts +0 -2
- package/dist/access/synthetic-include-read.test.d.ts.map +0 -1
- package/dist/access/synthetic-include-read.test.js +0 -121
- package/dist/access/synthetic-include-read.test.js.map +0 -1
- package/dist/context/nested-operations.d.ts +0 -74
- package/dist/context/nested-operations.d.ts.map +0 -1
- package/dist/context/nested-operations.js +0 -847
- package/dist/context/nested-operations.js.map +0 -1
- package/dist/fields/calendar-day.test.d.ts +0 -2
- package/dist/fields/calendar-day.test.d.ts.map +0 -1
- package/dist/fields/calendar-day.test.js +0 -246
- package/dist/fields/calendar-day.test.js.map +0 -1
- package/dist/fields/format-prisma-default.d.ts +0 -35
- package/dist/fields/format-prisma-default.d.ts.map +0 -1
- package/dist/fields/format-prisma-default.js +0 -49
- package/dist/fields/format-prisma-default.js.map +0 -1
- package/dist/fields/format-prisma-default.test.d.ts +0 -2
- package/dist/fields/format-prisma-default.test.d.ts.map +0 -1
- package/dist/fields/format-prisma-default.test.js +0 -54
- package/dist/fields/format-prisma-default.test.js.map +0 -1
- package/dist/fields/relationship-foreign-key.test.d.ts +0 -2
- package/dist/fields/relationship-foreign-key.test.d.ts.map +0 -1
- package/dist/fields/relationship-foreign-key.test.js +0 -18
- package/dist/fields/relationship-foreign-key.test.js.map +0 -1
- package/dist/fields/select.test.d.ts +0 -2
- package/dist/fields/select.test.d.ts.map +0 -1
- package/dist/fields/select.test.js +0 -279
- package/dist/fields/select.test.js.map +0 -1
- package/dist/fields/text-keystone-compat.test.d.ts +0 -2
- package/dist/fields/text-keystone-compat.test.d.ts.map +0 -1
- package/dist/fields/text-keystone-compat.test.js +0 -93
- package/dist/fields/text-keystone-compat.test.js.map +0 -1
- package/dist/filter/filter.test.d.ts +0 -2
- package/dist/filter/filter.test.d.ts.map +0 -1
- package/dist/filter/filter.test.js +0 -431
- package/dist/filter/filter.test.js.map +0 -1
- package/dist/filter/serialize.test.d.ts +0 -2
- package/dist/filter/serialize.test.d.ts.map +0 -1
- package/dist/filter/serialize.test.js +0 -83
- package/dist/filter/serialize.test.js.map +0 -1
- package/dist/index.test.d.ts +0 -2
- package/dist/index.test.d.ts.map +0 -1
- package/dist/index.test.js +0 -33
- package/dist/index.test.js.map +0 -1
- package/dist/lib/case-utils.test.d.ts +0 -2
- package/dist/lib/case-utils.test.d.ts.map +0 -1
- package/dist/lib/case-utils.test.js +0 -123
- package/dist/lib/case-utils.test.js.map +0 -1
- package/dist/query/index.d.ts +0 -127
- package/dist/query/index.d.ts.map +0 -1
- package/dist/query/index.js +0 -179
- package/dist/query/index.js.map +0 -1
- package/dist/query/index.test.d.ts +0 -2
- package/dist/query/index.test.d.ts.map +0 -1
- package/dist/query/index.test.js +0 -632
- package/dist/query/index.test.js.map +0 -1
- package/dist/query/relationship-options.test.d.ts +0 -2
- package/dist/query/relationship-options.test.d.ts.map +0 -1
- package/dist/query/relationship-options.test.js +0 -150
- package/dist/query/relationship-options.test.js.map +0 -1
- package/dist/validation/field-config.test.d.ts +0 -2
- package/dist/validation/field-config.test.d.ts.map +0 -1
- package/dist/validation/field-config.test.js +0 -159
- package/dist/validation/field-config.test.js.map +0 -1
- package/dist/validation/schema.test.d.ts +0 -2
- package/dist/validation/schema.test.d.ts.map +0 -1
- package/dist/validation/schema.test.js +0 -409
- package/dist/validation/schema.test.js.map +0 -1
- package/docs/type-distribution-fix.md +0 -136
- package/src/access/access-filter.test.ts +0 -1919
- package/src/access/access-filter.ts +0 -1041
- package/src/access/declared-dependencies.test.ts +0 -277
- package/src/access/declared-dependencies.ts +0 -220
- package/src/access/denied-relation-visibility.test.ts +0 -173
- package/src/access/depth-limits.ts +0 -27
- package/src/access/engine.test.ts +0 -67
- package/src/access/engine.ts +0 -193
- package/src/access/errors.ts +0 -242
- package/src/access/field-access.test.ts +0 -792
- package/src/access/field-access.ts +0 -353
- package/src/access/field-transforms.ts +0 -68
- package/src/access/field-visibility.ts +0 -569
- package/src/access/index.ts +0 -82
- package/src/access/multi-column-read-write.test.ts +0 -305
- package/src/access/query-validation.ts +0 -486
- package/src/access/relationship-count.test.ts +0 -344
- package/src/access/relationship-count.ts +0 -346
- package/src/access/relationship-label-filter.test.ts +0 -128
- package/src/access/relationship-label-filter.ts +0 -63
- package/src/access/synthetic-include-read.test.ts +0 -179
- package/src/access/transaction-registry.ts +0 -58
- package/src/access/types.ts +0 -391
- package/src/config/index.ts +0 -177
- package/src/config/label.ts +0 -51
- package/src/config/nav-count.ts +0 -77
- package/src/config/plugin-engine.ts +0 -261
- package/src/config/types.ts +0 -3270
- package/src/context/apply-defaults.ts +0 -47
- package/src/context/hook-pipeline.ts +0 -137
- package/src/context/index.ts +0 -1737
- package/src/context/nested-operations.ts +0 -1470
- package/src/context/transaction-boundary.ts +0 -485
- package/src/context/write-pipeline.ts +0 -732
- package/src/extend.ts +0 -28
- package/src/fields/calendar-day.test.ts +0 -291
- package/src/fields/format-prisma-default.test.ts +0 -64
- package/src/fields/format-prisma-default.ts +0 -64
- package/src/fields/index.ts +0 -1901
- package/src/fields/relationship-foreign-key.test.ts +0 -29
- package/src/fields/select.test.ts +0 -336
- package/src/fields/text-keystone-compat.test.ts +0 -126
- package/src/filter/collect.ts +0 -108
- package/src/filter/filter.test.ts +0 -538
- package/src/filter/index.ts +0 -26
- package/src/filter/map.ts +0 -63
- package/src/filter/parse.ts +0 -99
- package/src/filter/serialize.test.ts +0 -115
- package/src/filter/serialize.ts +0 -73
- package/src/filter/types.ts +0 -120
- package/src/hooks/index.ts +0 -752
- package/src/index.test.ts +0 -50
- package/src/index.ts +0 -192
- package/src/internal.ts +0 -61
- package/src/lib/case-utils.test.ts +0 -159
- package/src/lib/case-utils.ts +0 -68
- package/src/lib/prisma-errors.ts +0 -86
- package/src/mcp/constants.ts +0 -24
- package/src/mcp/field-schema.ts +0 -84
- package/src/mcp/handler.ts +0 -633
- package/src/mcp/index.ts +0 -7
- package/src/mcp/projection.ts +0 -497
- package/src/mcp/types.ts +0 -18
- package/src/query/index.test.ts +0 -830
- package/src/query/index.ts +0 -352
- package/src/query/relationship-options.test.ts +0 -194
- package/src/query/relationship-options.ts +0 -78
- package/src/utils/password.ts +0 -80
- package/src/validation/field-config.test.ts +0 -199
- package/src/validation/field-config.ts +0 -139
- package/src/validation/needs-closure.ts +0 -188
- package/src/validation/schema.test.ts +0 -487
- package/src/validation/schema.ts +0 -51
- package/tests/access-relationships.test.ts +0 -646
- package/tests/access.test.ts +0 -590
- package/tests/apply-defaults.test.ts +0 -119
- package/tests/bare-read-scalars.test.ts +0 -147
- package/tests/computed-field-selective-evaluation.test.ts +0 -418
- package/tests/config.test.ts +0 -242
- package/tests/context.test.ts +0 -3146
- package/tests/default-value-create.test.ts +0 -299
- package/tests/field-hooks.test.ts +0 -410
- package/tests/field-types.test.ts +0 -1291
- package/tests/hook-context-secured.test.ts +0 -424
- package/tests/hook-pipeline.test.ts +0 -233
- package/tests/hooks.test.ts +0 -481
- package/tests/interactive-transaction.test.ts +0 -444
- package/tests/label.test.ts +0 -135
- package/tests/mcp-fields-projection-access.test.ts +0 -250
- package/tests/mcp-handler.test.ts +0 -1411
- package/tests/multi-column-validation-ordering.test.ts +0 -305
- package/tests/nav-count.test.ts +0 -189
- package/tests/needs-declared-dependencies.test.ts +0 -503
- package/tests/nested-access-and-hooks.test.ts +0 -2566
- package/tests/nested-operation-registry.test.ts +0 -317
- package/tests/nested-write-hooks.test.ts +0 -864
- package/tests/nested-write-synthetic-relation.test.ts +0 -437
- package/tests/password-type-distribution.test.ts +0 -154
- package/tests/password-types.test.ts +0 -174
- package/tests/password.test.ts +0 -263
- package/tests/plugin-engine.test.ts +0 -1155
- package/tests/prisma-errors.test.ts +0 -141
- package/tests/resolve-chain.test.ts +0 -411
- package/tests/singleton.test.ts +0 -421
- package/tests/sudo.test.ts +0 -676
- package/tests/to-one-include-access-filter.test.ts +0 -172
- package/tests/transaction-boundary-hooks.test.ts +0 -710
- package/tests/transaction-boundary-outermost.test.ts +0 -530
- package/tests/virtual-fields.test.ts +0 -421
- package/tests/with-session.test.ts +0 -243
- package/tests/write-pipeline.test.ts +0 -617
- package/tsconfig.json +0 -12
- package/tsconfig.tsbuildinfo +0 -1
- package/vitest.config.ts +0 -69
|
@@ -1,1155 +0,0 @@
|
|
|
1
|
-
import { describe, test, expect, vi } from 'vitest'
|
|
2
|
-
import {
|
|
3
|
-
executePlugins,
|
|
4
|
-
executeBeforeGenerateHooks,
|
|
5
|
-
executeAfterGenerateHooks,
|
|
6
|
-
} from '../src/config/plugin-engine.js'
|
|
7
|
-
import type { OpenSaasConfig, Plugin, PluginContext } from '../src/config/types.js'
|
|
8
|
-
import { text, integer } from '../src/fields/index.js'
|
|
9
|
-
|
|
10
|
-
describe('Plugin Engine', () => {
|
|
11
|
-
describe('dependency resolution', () => {
|
|
12
|
-
test('executes plugins with no dependencies', async () => {
|
|
13
|
-
const initSpy = vi.fn()
|
|
14
|
-
const plugin: Plugin = {
|
|
15
|
-
name: 'test-plugin',
|
|
16
|
-
init: initSpy,
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const config: OpenSaasConfig = {
|
|
20
|
-
lists: {},
|
|
21
|
-
plugins: [plugin],
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
await executePlugins(config)
|
|
25
|
-
expect(initSpy).toHaveBeenCalledTimes(1)
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
test('sorts plugins by dependencies', async () => {
|
|
29
|
-
const executionOrder: string[] = []
|
|
30
|
-
|
|
31
|
-
const pluginA: Plugin = {
|
|
32
|
-
name: 'plugin-a',
|
|
33
|
-
init: async () => {
|
|
34
|
-
executionOrder.push('a')
|
|
35
|
-
},
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const pluginB: Plugin = {
|
|
39
|
-
name: 'plugin-b',
|
|
40
|
-
dependencies: ['plugin-a'],
|
|
41
|
-
init: async () => {
|
|
42
|
-
executionOrder.push('b')
|
|
43
|
-
},
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const pluginC: Plugin = {
|
|
47
|
-
name: 'plugin-c',
|
|
48
|
-
dependencies: ['plugin-b', 'plugin-a'],
|
|
49
|
-
init: async () => {
|
|
50
|
-
executionOrder.push('c')
|
|
51
|
-
},
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const config: OpenSaasConfig = {
|
|
55
|
-
lists: {},
|
|
56
|
-
plugins: [pluginC, pluginB, pluginA], // Reverse order
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
await executePlugins(config)
|
|
60
|
-
expect(executionOrder).toEqual(['a', 'b', 'c'])
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
test('detects circular dependencies', async () => {
|
|
64
|
-
const pluginA: Plugin = {
|
|
65
|
-
name: 'plugin-a',
|
|
66
|
-
dependencies: ['plugin-b'],
|
|
67
|
-
init: async () => {},
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const pluginB: Plugin = {
|
|
71
|
-
name: 'plugin-b',
|
|
72
|
-
dependencies: ['plugin-a'],
|
|
73
|
-
init: async () => {},
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const config: OpenSaasConfig = {
|
|
77
|
-
lists: {},
|
|
78
|
-
plugins: [pluginA, pluginB],
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
await expect(executePlugins(config)).rejects.toThrow('Circular dependency detected')
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
test('throws on missing dependencies', async () => {
|
|
85
|
-
const plugin: Plugin = {
|
|
86
|
-
name: 'plugin-a',
|
|
87
|
-
dependencies: ['missing-plugin'],
|
|
88
|
-
init: async () => {},
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const config: OpenSaasConfig = {
|
|
92
|
-
lists: {},
|
|
93
|
-
plugins: [plugin],
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
await expect(executePlugins(config)).rejects.toThrow(
|
|
97
|
-
'Plugin "missing-plugin" is required by "plugin-a" but not found',
|
|
98
|
-
)
|
|
99
|
-
})
|
|
100
|
-
|
|
101
|
-
test('throws on duplicate plugin names', async () => {
|
|
102
|
-
const plugin1: Plugin = {
|
|
103
|
-
name: 'duplicate',
|
|
104
|
-
init: async () => {},
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
const plugin2: Plugin = {
|
|
108
|
-
name: 'duplicate',
|
|
109
|
-
init: async () => {},
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const config: OpenSaasConfig = {
|
|
113
|
-
lists: {},
|
|
114
|
-
plugins: [plugin1, plugin2],
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
await expect(executePlugins(config)).rejects.toThrow('Duplicate plugin name: duplicate')
|
|
118
|
-
})
|
|
119
|
-
|
|
120
|
-
test('handles complex dependency chains', async () => {
|
|
121
|
-
const executionOrder: string[] = []
|
|
122
|
-
|
|
123
|
-
const plugins: Plugin[] = [
|
|
124
|
-
{
|
|
125
|
-
name: 'base',
|
|
126
|
-
init: async () => executionOrder.push('base'),
|
|
127
|
-
},
|
|
128
|
-
{
|
|
129
|
-
name: 'auth',
|
|
130
|
-
dependencies: ['base'],
|
|
131
|
-
init: async () => executionOrder.push('auth'),
|
|
132
|
-
},
|
|
133
|
-
{
|
|
134
|
-
name: 'profile',
|
|
135
|
-
dependencies: ['auth'],
|
|
136
|
-
init: async () => executionOrder.push('profile'),
|
|
137
|
-
},
|
|
138
|
-
{
|
|
139
|
-
name: 'notifications',
|
|
140
|
-
dependencies: ['auth'],
|
|
141
|
-
init: async () => executionOrder.push('notifications'),
|
|
142
|
-
},
|
|
143
|
-
{
|
|
144
|
-
name: 'admin',
|
|
145
|
-
dependencies: ['auth', 'profile', 'notifications'],
|
|
146
|
-
init: async () => executionOrder.push('admin'),
|
|
147
|
-
},
|
|
148
|
-
]
|
|
149
|
-
|
|
150
|
-
const config: OpenSaasConfig = {
|
|
151
|
-
lists: {},
|
|
152
|
-
plugins: plugins.reverse(), // Reversed to test sorting
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
await executePlugins(config)
|
|
156
|
-
|
|
157
|
-
// Verify base runs first, auth before profile/notifications, and admin last
|
|
158
|
-
expect(executionOrder.indexOf('base')).toBeLessThan(executionOrder.indexOf('auth'))
|
|
159
|
-
expect(executionOrder.indexOf('auth')).toBeLessThan(executionOrder.indexOf('profile'))
|
|
160
|
-
expect(executionOrder.indexOf('auth')).toBeLessThan(executionOrder.indexOf('notifications'))
|
|
161
|
-
expect(executionOrder.indexOf('profile')).toBeLessThan(executionOrder.indexOf('admin'))
|
|
162
|
-
expect(executionOrder.indexOf('notifications')).toBeLessThan(executionOrder.indexOf('admin'))
|
|
163
|
-
})
|
|
164
|
-
})
|
|
165
|
-
|
|
166
|
-
describe('plugin initialization', () => {
|
|
167
|
-
test('provides correct context to init', async () => {
|
|
168
|
-
let receivedContext: PluginContext | undefined
|
|
169
|
-
|
|
170
|
-
const plugin: Plugin = {
|
|
171
|
-
name: 'test-plugin',
|
|
172
|
-
init: async (context) => {
|
|
173
|
-
receivedContext = context
|
|
174
|
-
},
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
const config: OpenSaasConfig = {
|
|
178
|
-
lists: {
|
|
179
|
-
Post: {
|
|
180
|
-
fields: {
|
|
181
|
-
title: text(),
|
|
182
|
-
},
|
|
183
|
-
},
|
|
184
|
-
},
|
|
185
|
-
plugins: [plugin],
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
await executePlugins(config)
|
|
189
|
-
|
|
190
|
-
expect(receivedContext).toBeDefined()
|
|
191
|
-
expect(receivedContext!.config).toBeDefined()
|
|
192
|
-
expect(receivedContext!.config.lists.Post).toBeDefined()
|
|
193
|
-
expect(typeof receivedContext!.addList).toBe('function')
|
|
194
|
-
expect(typeof receivedContext!.extendList).toBe('function')
|
|
195
|
-
expect(typeof receivedContext!.registerFieldType).toBe('function')
|
|
196
|
-
expect(typeof receivedContext!.registerMcpTool).toBe('function')
|
|
197
|
-
expect(typeof receivedContext!.setPluginData).toBe('function')
|
|
198
|
-
})
|
|
199
|
-
|
|
200
|
-
test('stores plugin data correctly', async () => {
|
|
201
|
-
const pluginData = { apiKey: 'secret', enabled: true }
|
|
202
|
-
|
|
203
|
-
const plugin: Plugin = {
|
|
204
|
-
name: 'test-plugin',
|
|
205
|
-
init: async (context) => {
|
|
206
|
-
context.setPluginData('test-plugin', pluginData)
|
|
207
|
-
},
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
const config: OpenSaasConfig = {
|
|
211
|
-
lists: {},
|
|
212
|
-
plugins: [plugin],
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
const result = await executePlugins(config)
|
|
216
|
-
|
|
217
|
-
expect(result._pluginData).toBeDefined()
|
|
218
|
-
expect(result._pluginData!['test-plugin']).toEqual(pluginData)
|
|
219
|
-
})
|
|
220
|
-
|
|
221
|
-
test('allows multiple plugins to store data', async () => {
|
|
222
|
-
const plugin1: Plugin = {
|
|
223
|
-
name: 'plugin-1',
|
|
224
|
-
init: async (context) => {
|
|
225
|
-
context.setPluginData('plugin-1', { value: 1 })
|
|
226
|
-
},
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
const plugin2: Plugin = {
|
|
230
|
-
name: 'plugin-2',
|
|
231
|
-
init: async (context) => {
|
|
232
|
-
context.setPluginData('plugin-2', { value: 2 })
|
|
233
|
-
},
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
const config: OpenSaasConfig = {
|
|
237
|
-
lists: {},
|
|
238
|
-
plugins: [plugin1, plugin2],
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
const result = await executePlugins(config)
|
|
242
|
-
|
|
243
|
-
expect(result._pluginData!['plugin-1']).toEqual({ value: 1 })
|
|
244
|
-
expect(result._pluginData!['plugin-2']).toEqual({ value: 2 })
|
|
245
|
-
})
|
|
246
|
-
|
|
247
|
-
test('handles empty plugin list', async () => {
|
|
248
|
-
const config: OpenSaasConfig = {
|
|
249
|
-
lists: {},
|
|
250
|
-
plugins: [],
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
const result = await executePlugins(config)
|
|
254
|
-
expect(result).toEqual(config)
|
|
255
|
-
})
|
|
256
|
-
|
|
257
|
-
test('handles no plugins property', async () => {
|
|
258
|
-
const config: OpenSaasConfig = {
|
|
259
|
-
lists: {},
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
const result = await executePlugins(config)
|
|
263
|
-
expect(result).toEqual(config)
|
|
264
|
-
})
|
|
265
|
-
})
|
|
266
|
-
|
|
267
|
-
describe('addList', () => {
|
|
268
|
-
test('adds a new list to config', async () => {
|
|
269
|
-
const plugin: Plugin = {
|
|
270
|
-
name: 'test-plugin',
|
|
271
|
-
init: async (context) => {
|
|
272
|
-
context.addList('User', {
|
|
273
|
-
fields: {
|
|
274
|
-
email: text(),
|
|
275
|
-
age: integer(),
|
|
276
|
-
},
|
|
277
|
-
})
|
|
278
|
-
},
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
const config: OpenSaasConfig = {
|
|
282
|
-
lists: {},
|
|
283
|
-
plugins: [plugin],
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
const result = await executePlugins(config)
|
|
287
|
-
|
|
288
|
-
expect(result.lists.User).toBeDefined()
|
|
289
|
-
expect(result.lists.User.fields.email).toBeDefined()
|
|
290
|
-
expect(result.lists.User.fields.age).toBeDefined()
|
|
291
|
-
})
|
|
292
|
-
|
|
293
|
-
test('throws when adding duplicate list', async () => {
|
|
294
|
-
const plugin: Plugin = {
|
|
295
|
-
name: 'test-plugin',
|
|
296
|
-
init: async (context) => {
|
|
297
|
-
context.addList('Post', {
|
|
298
|
-
fields: {
|
|
299
|
-
title: text(),
|
|
300
|
-
},
|
|
301
|
-
})
|
|
302
|
-
},
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
const config: OpenSaasConfig = {
|
|
306
|
-
lists: {
|
|
307
|
-
Post: {
|
|
308
|
-
fields: {
|
|
309
|
-
content: text(),
|
|
310
|
-
},
|
|
311
|
-
},
|
|
312
|
-
},
|
|
313
|
-
plugins: [plugin],
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
await expect(executePlugins(config)).rejects.toThrow(
|
|
317
|
-
'Plugin "test-plugin" tried to add list "Post" but it already exists',
|
|
318
|
-
)
|
|
319
|
-
})
|
|
320
|
-
|
|
321
|
-
test('multiple plugins can add different lists', async () => {
|
|
322
|
-
const plugin1: Plugin = {
|
|
323
|
-
name: 'plugin-1',
|
|
324
|
-
init: async (context) => {
|
|
325
|
-
context.addList('User', { fields: { email: text() } })
|
|
326
|
-
},
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
const plugin2: Plugin = {
|
|
330
|
-
name: 'plugin-2',
|
|
331
|
-
init: async (context) => {
|
|
332
|
-
context.addList('Session', { fields: { token: text() } })
|
|
333
|
-
},
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
const config: OpenSaasConfig = {
|
|
337
|
-
lists: {},
|
|
338
|
-
plugins: [plugin1, plugin2],
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
const result = await executePlugins(config)
|
|
342
|
-
|
|
343
|
-
expect(result.lists.User).toBeDefined()
|
|
344
|
-
expect(result.lists.Session).toBeDefined()
|
|
345
|
-
})
|
|
346
|
-
})
|
|
347
|
-
|
|
348
|
-
describe('extendList', () => {
|
|
349
|
-
test('extends existing list with new fields', async () => {
|
|
350
|
-
const plugin: Plugin = {
|
|
351
|
-
name: 'test-plugin',
|
|
352
|
-
init: async (context) => {
|
|
353
|
-
context.extendList('Post', {
|
|
354
|
-
fields: {
|
|
355
|
-
views: integer(),
|
|
356
|
-
},
|
|
357
|
-
})
|
|
358
|
-
},
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
const config: OpenSaasConfig = {
|
|
362
|
-
lists: {
|
|
363
|
-
Post: {
|
|
364
|
-
fields: {
|
|
365
|
-
title: text(),
|
|
366
|
-
},
|
|
367
|
-
},
|
|
368
|
-
},
|
|
369
|
-
plugins: [plugin],
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
const result = await executePlugins(config)
|
|
373
|
-
|
|
374
|
-
expect(result.lists.Post.fields.title).toBeDefined()
|
|
375
|
-
expect(result.lists.Post.fields.views).toBeDefined()
|
|
376
|
-
})
|
|
377
|
-
|
|
378
|
-
test('throws when extending non-existent list', async () => {
|
|
379
|
-
const plugin: Plugin = {
|
|
380
|
-
name: 'test-plugin',
|
|
381
|
-
init: async (context) => {
|
|
382
|
-
context.extendList('User', {
|
|
383
|
-
fields: {
|
|
384
|
-
name: text(),
|
|
385
|
-
},
|
|
386
|
-
})
|
|
387
|
-
},
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
const config: OpenSaasConfig = {
|
|
391
|
-
lists: {},
|
|
392
|
-
plugins: [plugin],
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
await expect(executePlugins(config)).rejects.toThrow(
|
|
396
|
-
'Plugin "test-plugin" tried to extend list "User" but it doesn\'t exist',
|
|
397
|
-
)
|
|
398
|
-
})
|
|
399
|
-
|
|
400
|
-
test('merges fields from multiple plugins', async () => {
|
|
401
|
-
const plugin1: Plugin = {
|
|
402
|
-
name: 'plugin-1',
|
|
403
|
-
init: async (context) => {
|
|
404
|
-
context.extendList('Post', {
|
|
405
|
-
fields: { views: integer() },
|
|
406
|
-
})
|
|
407
|
-
},
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
const plugin2: Plugin = {
|
|
411
|
-
name: 'plugin-2',
|
|
412
|
-
init: async (context) => {
|
|
413
|
-
context.extendList('Post', {
|
|
414
|
-
fields: { likes: integer() },
|
|
415
|
-
})
|
|
416
|
-
},
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
const config: OpenSaasConfig = {
|
|
420
|
-
lists: {
|
|
421
|
-
Post: {
|
|
422
|
-
fields: {
|
|
423
|
-
title: text(),
|
|
424
|
-
},
|
|
425
|
-
},
|
|
426
|
-
},
|
|
427
|
-
plugins: [plugin1, plugin2],
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
const result = await executePlugins(config)
|
|
431
|
-
|
|
432
|
-
expect(result.lists.Post.fields.title).toBeDefined()
|
|
433
|
-
expect(result.lists.Post.fields.views).toBeDefined()
|
|
434
|
-
expect(result.lists.Post.fields.likes).toBeDefined()
|
|
435
|
-
})
|
|
436
|
-
})
|
|
437
|
-
|
|
438
|
-
describe('hook merging', () => {
|
|
439
|
-
test('merges resolveInput hooks from multiple plugins', async () => {
|
|
440
|
-
const values: string[] = []
|
|
441
|
-
|
|
442
|
-
const plugin1: Plugin = {
|
|
443
|
-
name: 'plugin-1',
|
|
444
|
-
init: async (context) => {
|
|
445
|
-
context.extendList('Post', {
|
|
446
|
-
hooks: {
|
|
447
|
-
resolveInput: async ({ resolvedData }) => {
|
|
448
|
-
values.push('plugin-1')
|
|
449
|
-
return { ...resolvedData, field1: 'value1' }
|
|
450
|
-
},
|
|
451
|
-
},
|
|
452
|
-
})
|
|
453
|
-
},
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
const plugin2: Plugin = {
|
|
457
|
-
name: 'plugin-2',
|
|
458
|
-
init: async (context) => {
|
|
459
|
-
context.extendList('Post', {
|
|
460
|
-
hooks: {
|
|
461
|
-
resolveInput: async ({ resolvedData }) => {
|
|
462
|
-
values.push('plugin-2')
|
|
463
|
-
return { ...resolvedData, field2: 'value2' }
|
|
464
|
-
},
|
|
465
|
-
},
|
|
466
|
-
})
|
|
467
|
-
},
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
const config: OpenSaasConfig = {
|
|
471
|
-
lists: {
|
|
472
|
-
Post: {
|
|
473
|
-
fields: { title: text() },
|
|
474
|
-
},
|
|
475
|
-
},
|
|
476
|
-
plugins: [plugin1, plugin2],
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
const result = await executePlugins(config)
|
|
480
|
-
|
|
481
|
-
// Test that hooks are chained
|
|
482
|
-
const resolvedData = await result.lists.Post.hooks!.resolveInput!({
|
|
483
|
-
operation: 'create',
|
|
484
|
-
resolvedData: { title: 'test' },
|
|
485
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
486
|
-
} as any)
|
|
487
|
-
|
|
488
|
-
expect(values).toEqual(['plugin-1', 'plugin-2'])
|
|
489
|
-
expect(resolvedData).toEqual({
|
|
490
|
-
title: 'test',
|
|
491
|
-
field1: 'value1',
|
|
492
|
-
field2: 'value2',
|
|
493
|
-
})
|
|
494
|
-
})
|
|
495
|
-
|
|
496
|
-
test('merges validateInput hooks from multiple plugins', async () => {
|
|
497
|
-
const validations: string[] = []
|
|
498
|
-
|
|
499
|
-
const plugin1: Plugin = {
|
|
500
|
-
name: 'plugin-1',
|
|
501
|
-
init: async (context) => {
|
|
502
|
-
context.extendList('Post', {
|
|
503
|
-
hooks: {
|
|
504
|
-
validateInput: async () => {
|
|
505
|
-
validations.push('plugin-1')
|
|
506
|
-
},
|
|
507
|
-
},
|
|
508
|
-
})
|
|
509
|
-
},
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
const plugin2: Plugin = {
|
|
513
|
-
name: 'plugin-2',
|
|
514
|
-
init: async (context) => {
|
|
515
|
-
context.extendList('Post', {
|
|
516
|
-
hooks: {
|
|
517
|
-
validateInput: async () => {
|
|
518
|
-
validations.push('plugin-2')
|
|
519
|
-
},
|
|
520
|
-
},
|
|
521
|
-
})
|
|
522
|
-
},
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
const config: OpenSaasConfig = {
|
|
526
|
-
lists: {
|
|
527
|
-
Post: {
|
|
528
|
-
fields: { title: text() },
|
|
529
|
-
},
|
|
530
|
-
},
|
|
531
|
-
plugins: [plugin1, plugin2],
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
const result = await executePlugins(config)
|
|
535
|
-
|
|
536
|
-
// Test that both validators run
|
|
537
|
-
await result.lists.Post.hooks!.validateInput!({
|
|
538
|
-
operation: 'create',
|
|
539
|
-
resolvedData: { title: 'test' },
|
|
540
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
541
|
-
} as any)
|
|
542
|
-
|
|
543
|
-
expect(validations).toEqual(['plugin-1', 'plugin-2'])
|
|
544
|
-
})
|
|
545
|
-
|
|
546
|
-
test('merges beforeOperation hooks from multiple plugins', async () => {
|
|
547
|
-
const operations: string[] = []
|
|
548
|
-
|
|
549
|
-
const plugin1: Plugin = {
|
|
550
|
-
name: 'plugin-1',
|
|
551
|
-
init: async (context) => {
|
|
552
|
-
context.extendList('Post', {
|
|
553
|
-
hooks: {
|
|
554
|
-
beforeOperation: async () => {
|
|
555
|
-
operations.push('plugin-1')
|
|
556
|
-
},
|
|
557
|
-
},
|
|
558
|
-
})
|
|
559
|
-
},
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
const plugin2: Plugin = {
|
|
563
|
-
name: 'plugin-2',
|
|
564
|
-
init: async (context) => {
|
|
565
|
-
context.extendList('Post', {
|
|
566
|
-
hooks: {
|
|
567
|
-
beforeOperation: async () => {
|
|
568
|
-
operations.push('plugin-2')
|
|
569
|
-
},
|
|
570
|
-
},
|
|
571
|
-
})
|
|
572
|
-
},
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
const config: OpenSaasConfig = {
|
|
576
|
-
lists: {
|
|
577
|
-
Post: {
|
|
578
|
-
fields: { title: text() },
|
|
579
|
-
},
|
|
580
|
-
},
|
|
581
|
-
plugins: [plugin1, plugin2],
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
const result = await executePlugins(config)
|
|
585
|
-
|
|
586
|
-
// Test that both hooks run
|
|
587
|
-
await result.lists.Post.hooks!.beforeOperation!({
|
|
588
|
-
operation: 'create',
|
|
589
|
-
resolvedData: { title: 'test' },
|
|
590
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
591
|
-
} as any)
|
|
592
|
-
|
|
593
|
-
expect(operations).toEqual(['plugin-1', 'plugin-2'])
|
|
594
|
-
})
|
|
595
|
-
|
|
596
|
-
test('merges afterOperation hooks from multiple plugins', async () => {
|
|
597
|
-
const operations: string[] = []
|
|
598
|
-
|
|
599
|
-
const plugin1: Plugin = {
|
|
600
|
-
name: 'plugin-1',
|
|
601
|
-
init: async (context) => {
|
|
602
|
-
context.extendList('Post', {
|
|
603
|
-
hooks: {
|
|
604
|
-
afterOperation: async () => {
|
|
605
|
-
operations.push('plugin-1')
|
|
606
|
-
},
|
|
607
|
-
},
|
|
608
|
-
})
|
|
609
|
-
},
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
const plugin2: Plugin = {
|
|
613
|
-
name: 'plugin-2',
|
|
614
|
-
init: async (context) => {
|
|
615
|
-
context.extendList('Post', {
|
|
616
|
-
hooks: {
|
|
617
|
-
afterOperation: async () => {
|
|
618
|
-
operations.push('plugin-2')
|
|
619
|
-
},
|
|
620
|
-
},
|
|
621
|
-
})
|
|
622
|
-
},
|
|
623
|
-
}
|
|
624
|
-
|
|
625
|
-
const config: OpenSaasConfig = {
|
|
626
|
-
lists: {
|
|
627
|
-
Post: {
|
|
628
|
-
fields: { title: text() },
|
|
629
|
-
},
|
|
630
|
-
},
|
|
631
|
-
plugins: [plugin1, plugin2],
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
const result = await executePlugins(config)
|
|
635
|
-
|
|
636
|
-
// Test that both hooks run
|
|
637
|
-
await result.lists.Post.hooks!.afterOperation!({
|
|
638
|
-
operation: 'create',
|
|
639
|
-
item: { id: '1', title: 'test' },
|
|
640
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
641
|
-
} as any)
|
|
642
|
-
|
|
643
|
-
expect(operations).toEqual(['plugin-1', 'plugin-2'])
|
|
644
|
-
})
|
|
645
|
-
|
|
646
|
-
test('handles single hook without merging', async () => {
|
|
647
|
-
const plugin: Plugin = {
|
|
648
|
-
name: 'plugin-1',
|
|
649
|
-
init: async (context) => {
|
|
650
|
-
context.extendList('Post', {
|
|
651
|
-
hooks: {
|
|
652
|
-
resolveInput: async ({ resolvedData }) => {
|
|
653
|
-
return { ...resolvedData, modified: true }
|
|
654
|
-
},
|
|
655
|
-
},
|
|
656
|
-
})
|
|
657
|
-
},
|
|
658
|
-
}
|
|
659
|
-
|
|
660
|
-
const config: OpenSaasConfig = {
|
|
661
|
-
lists: {
|
|
662
|
-
Post: {
|
|
663
|
-
fields: { title: text() },
|
|
664
|
-
},
|
|
665
|
-
},
|
|
666
|
-
plugins: [plugin],
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
const result = await executePlugins(config)
|
|
670
|
-
|
|
671
|
-
const resolvedData = await result.lists.Post.hooks!.resolveInput!({
|
|
672
|
-
operation: 'create',
|
|
673
|
-
resolvedData: { title: 'test' },
|
|
674
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
675
|
-
} as any)
|
|
676
|
-
|
|
677
|
-
expect(resolvedData).toEqual({
|
|
678
|
-
title: 'test',
|
|
679
|
-
modified: true,
|
|
680
|
-
})
|
|
681
|
-
})
|
|
682
|
-
})
|
|
683
|
-
|
|
684
|
-
describe('access control guardrail (ADR-0013)', () => {
|
|
685
|
-
test('throws when an extension carries operation access for a pre-existing list', async () => {
|
|
686
|
-
const plugin: Plugin = {
|
|
687
|
-
name: 'test-plugin',
|
|
688
|
-
init: async (context) => {
|
|
689
|
-
context.extendList('Post', {
|
|
690
|
-
access: {
|
|
691
|
-
operation: {
|
|
692
|
-
query: () => true,
|
|
693
|
-
create: ({ session }) => !!session,
|
|
694
|
-
},
|
|
695
|
-
},
|
|
696
|
-
})
|
|
697
|
-
},
|
|
698
|
-
}
|
|
699
|
-
|
|
700
|
-
const config: OpenSaasConfig = {
|
|
701
|
-
lists: {
|
|
702
|
-
Post: {
|
|
703
|
-
fields: { title: text() },
|
|
704
|
-
access: {
|
|
705
|
-
operation: {
|
|
706
|
-
update: ({ session }) => !!session,
|
|
707
|
-
},
|
|
708
|
-
},
|
|
709
|
-
},
|
|
710
|
-
},
|
|
711
|
-
plugins: [plugin],
|
|
712
|
-
}
|
|
713
|
-
|
|
714
|
-
await expect(executePlugins(config)).rejects.toThrow(
|
|
715
|
-
'Plugin "test-plugin" tried to set operation-level access while extending list "Post"',
|
|
716
|
-
)
|
|
717
|
-
})
|
|
718
|
-
|
|
719
|
-
test('extension attempting to override existing access throws instead of silently winning', async () => {
|
|
720
|
-
const plugin: Plugin = {
|
|
721
|
-
name: 'test-plugin',
|
|
722
|
-
init: async (context) => {
|
|
723
|
-
context.extendList('Post', {
|
|
724
|
-
access: {
|
|
725
|
-
operation: {
|
|
726
|
-
query: () => false,
|
|
727
|
-
},
|
|
728
|
-
},
|
|
729
|
-
})
|
|
730
|
-
},
|
|
731
|
-
}
|
|
732
|
-
|
|
733
|
-
const originalQuery = vi.fn(() => true)
|
|
734
|
-
|
|
735
|
-
const config: OpenSaasConfig = {
|
|
736
|
-
lists: {
|
|
737
|
-
Post: {
|
|
738
|
-
fields: { title: text() },
|
|
739
|
-
access: {
|
|
740
|
-
operation: {
|
|
741
|
-
query: originalQuery,
|
|
742
|
-
},
|
|
743
|
-
},
|
|
744
|
-
},
|
|
745
|
-
},
|
|
746
|
-
plugins: [plugin],
|
|
747
|
-
}
|
|
748
|
-
|
|
749
|
-
await expect(executePlugins(config)).rejects.toThrow('Post')
|
|
750
|
-
|
|
751
|
-
// The host's access is untouched — the throw happens before any mutation.
|
|
752
|
-
expect(config.lists.Post.access?.operation?.query).toBe(originalQuery)
|
|
753
|
-
})
|
|
754
|
-
|
|
755
|
-
test('extension providing only fields/hooks for a pre-existing list leaves its access untouched', async () => {
|
|
756
|
-
const originalQuery = vi.fn(() => true)
|
|
757
|
-
|
|
758
|
-
const plugin: Plugin = {
|
|
759
|
-
name: 'test-plugin',
|
|
760
|
-
init: async (context) => {
|
|
761
|
-
context.extendList('Post', {
|
|
762
|
-
fields: { views: integer() },
|
|
763
|
-
})
|
|
764
|
-
},
|
|
765
|
-
}
|
|
766
|
-
|
|
767
|
-
const config: OpenSaasConfig = {
|
|
768
|
-
lists: {
|
|
769
|
-
Post: {
|
|
770
|
-
fields: { title: text() },
|
|
771
|
-
access: {
|
|
772
|
-
operation: {
|
|
773
|
-
query: originalQuery,
|
|
774
|
-
},
|
|
775
|
-
},
|
|
776
|
-
},
|
|
777
|
-
},
|
|
778
|
-
plugins: [plugin],
|
|
779
|
-
}
|
|
780
|
-
|
|
781
|
-
const result = await executePlugins(config)
|
|
782
|
-
|
|
783
|
-
expect(result.lists.Post.fields.views).toBeDefined()
|
|
784
|
-
expect(result.lists.Post.access?.operation?.query).toBe(originalQuery)
|
|
785
|
-
})
|
|
786
|
-
|
|
787
|
-
test('a plugin creating a new list may still set its access via addList', async () => {
|
|
788
|
-
const plugin: Plugin = {
|
|
789
|
-
name: 'test-plugin',
|
|
790
|
-
init: async (context) => {
|
|
791
|
-
context.addList('Widget', {
|
|
792
|
-
fields: { name: text() },
|
|
793
|
-
access: {
|
|
794
|
-
operation: {
|
|
795
|
-
query: () => true,
|
|
796
|
-
},
|
|
797
|
-
},
|
|
798
|
-
})
|
|
799
|
-
},
|
|
800
|
-
}
|
|
801
|
-
|
|
802
|
-
const config: OpenSaasConfig = {
|
|
803
|
-
lists: {},
|
|
804
|
-
plugins: [plugin],
|
|
805
|
-
}
|
|
806
|
-
|
|
807
|
-
const result = await executePlugins(config)
|
|
808
|
-
|
|
809
|
-
expect(result.lists.Widget.access?.operation?.query).toBeDefined()
|
|
810
|
-
})
|
|
811
|
-
})
|
|
812
|
-
|
|
813
|
-
describe('MCP integration', () => {
|
|
814
|
-
test('registers MCP tools from plugins', async () => {
|
|
815
|
-
const customTool = {
|
|
816
|
-
name: 'customTool',
|
|
817
|
-
listKey: 'Post',
|
|
818
|
-
handler: async () => ({ success: true }),
|
|
819
|
-
description: 'Custom tool',
|
|
820
|
-
inputSchema: {
|
|
821
|
-
type: 'object' as const,
|
|
822
|
-
properties: {},
|
|
823
|
-
},
|
|
824
|
-
}
|
|
825
|
-
|
|
826
|
-
const plugin: Plugin = {
|
|
827
|
-
name: 'test-plugin',
|
|
828
|
-
init: async (context) => {
|
|
829
|
-
context.registerMcpTool(customTool)
|
|
830
|
-
},
|
|
831
|
-
}
|
|
832
|
-
|
|
833
|
-
const config: OpenSaasConfig = {
|
|
834
|
-
lists: {},
|
|
835
|
-
plugins: [plugin],
|
|
836
|
-
}
|
|
837
|
-
|
|
838
|
-
const result = await executePlugins(config)
|
|
839
|
-
|
|
840
|
-
expect(result._pluginData?.__mcpTools).toEqual([customTool])
|
|
841
|
-
})
|
|
842
|
-
|
|
843
|
-
test('merges MCP config on list extension', async () => {
|
|
844
|
-
const plugin: Plugin = {
|
|
845
|
-
name: 'test-plugin',
|
|
846
|
-
init: async (context) => {
|
|
847
|
-
context.extendList('Post', {
|
|
848
|
-
mcp: {
|
|
849
|
-
enabled: true,
|
|
850
|
-
customTools: [
|
|
851
|
-
{
|
|
852
|
-
name: 'publishPost',
|
|
853
|
-
handler: async () => ({ success: true }),
|
|
854
|
-
description: 'Publish a post',
|
|
855
|
-
inputSchema: {
|
|
856
|
-
type: 'object' as const,
|
|
857
|
-
properties: {},
|
|
858
|
-
},
|
|
859
|
-
},
|
|
860
|
-
],
|
|
861
|
-
},
|
|
862
|
-
})
|
|
863
|
-
},
|
|
864
|
-
}
|
|
865
|
-
|
|
866
|
-
const config: OpenSaasConfig = {
|
|
867
|
-
lists: {
|
|
868
|
-
Post: {
|
|
869
|
-
fields: { title: text() },
|
|
870
|
-
mcp: {
|
|
871
|
-
enabled: false,
|
|
872
|
-
},
|
|
873
|
-
},
|
|
874
|
-
},
|
|
875
|
-
plugins: [plugin],
|
|
876
|
-
}
|
|
877
|
-
|
|
878
|
-
const result = await executePlugins(config)
|
|
879
|
-
|
|
880
|
-
expect(result.lists.Post.mcp?.enabled).toBe(true)
|
|
881
|
-
expect(result.lists.Post.mcp?.customTools).toHaveLength(1)
|
|
882
|
-
})
|
|
883
|
-
})
|
|
884
|
-
|
|
885
|
-
describe('field type registration', () => {
|
|
886
|
-
test('registers custom field types', async () => {
|
|
887
|
-
const customFieldBuilder = () => ({
|
|
888
|
-
type: 'customField',
|
|
889
|
-
getZodSchema: () => undefined,
|
|
890
|
-
getPrismaType: () => ({ type: 'String', modifiers: '' }),
|
|
891
|
-
getTypeScriptType: () => ({ type: 'string', optional: false }),
|
|
892
|
-
})
|
|
893
|
-
|
|
894
|
-
let registeredBuilder
|
|
895
|
-
|
|
896
|
-
const plugin: Plugin = {
|
|
897
|
-
name: 'test-plugin',
|
|
898
|
-
init: async (context) => {
|
|
899
|
-
context.registerFieldType('customField', customFieldBuilder)
|
|
900
|
-
// Store reference for testing
|
|
901
|
-
registeredBuilder = customFieldBuilder
|
|
902
|
-
},
|
|
903
|
-
}
|
|
904
|
-
|
|
905
|
-
const config: OpenSaasConfig = {
|
|
906
|
-
lists: {},
|
|
907
|
-
plugins: [plugin],
|
|
908
|
-
}
|
|
909
|
-
|
|
910
|
-
await executePlugins(config)
|
|
911
|
-
|
|
912
|
-
// Field type is registered in plugin context but not directly testable
|
|
913
|
-
// In real usage, it would be available for field creation
|
|
914
|
-
expect(registeredBuilder).toBeDefined()
|
|
915
|
-
})
|
|
916
|
-
|
|
917
|
-
test('throws when registering duplicate field type', async () => {
|
|
918
|
-
const customFieldBuilder = () => ({
|
|
919
|
-
type: 'customField',
|
|
920
|
-
getZodSchema: () => undefined,
|
|
921
|
-
getPrismaType: () => ({ type: 'String', modifiers: '' }),
|
|
922
|
-
getTypeScriptType: () => ({ type: 'string', optional: false }),
|
|
923
|
-
})
|
|
924
|
-
|
|
925
|
-
const plugin: Plugin = {
|
|
926
|
-
name: 'test-plugin',
|
|
927
|
-
init: async (context) => {
|
|
928
|
-
context.registerFieldType('customField', customFieldBuilder)
|
|
929
|
-
context.registerFieldType('customField', customFieldBuilder) // Duplicate
|
|
930
|
-
},
|
|
931
|
-
}
|
|
932
|
-
|
|
933
|
-
const config: OpenSaasConfig = {
|
|
934
|
-
lists: {},
|
|
935
|
-
plugins: [plugin],
|
|
936
|
-
}
|
|
937
|
-
|
|
938
|
-
await expect(executePlugins(config)).rejects.toThrow(
|
|
939
|
-
'Plugin "test-plugin" tried to register field type "customField" but it\'s already registered',
|
|
940
|
-
)
|
|
941
|
-
})
|
|
942
|
-
})
|
|
943
|
-
|
|
944
|
-
describe('generation lifecycle hooks', () => {
|
|
945
|
-
test('executes beforeGenerate hooks', async () => {
|
|
946
|
-
const beforeGenerate = vi.fn((config: OpenSaasConfig) => {
|
|
947
|
-
return {
|
|
948
|
-
...config,
|
|
949
|
-
lists: {
|
|
950
|
-
...config.lists,
|
|
951
|
-
NewList: {
|
|
952
|
-
fields: {
|
|
953
|
-
title: text(),
|
|
954
|
-
},
|
|
955
|
-
},
|
|
956
|
-
},
|
|
957
|
-
}
|
|
958
|
-
})
|
|
959
|
-
|
|
960
|
-
const plugin: Plugin = {
|
|
961
|
-
name: 'test-plugin',
|
|
962
|
-
init: async () => {},
|
|
963
|
-
beforeGenerate,
|
|
964
|
-
}
|
|
965
|
-
|
|
966
|
-
const config: OpenSaasConfig = {
|
|
967
|
-
lists: {},
|
|
968
|
-
plugins: [plugin],
|
|
969
|
-
}
|
|
970
|
-
|
|
971
|
-
const result = await executeBeforeGenerateHooks(config)
|
|
972
|
-
|
|
973
|
-
expect(beforeGenerate).toHaveBeenCalledTimes(1)
|
|
974
|
-
expect(result.lists.NewList).toBeDefined()
|
|
975
|
-
})
|
|
976
|
-
|
|
977
|
-
test('chains beforeGenerate hooks', async () => {
|
|
978
|
-
const plugin1: Plugin = {
|
|
979
|
-
name: 'plugin-1',
|
|
980
|
-
init: async () => {},
|
|
981
|
-
beforeGenerate: async (config) => ({
|
|
982
|
-
...config,
|
|
983
|
-
lists: {
|
|
984
|
-
...config.lists,
|
|
985
|
-
List1: { fields: { field1: text() } },
|
|
986
|
-
},
|
|
987
|
-
}),
|
|
988
|
-
}
|
|
989
|
-
|
|
990
|
-
const plugin2: Plugin = {
|
|
991
|
-
name: 'plugin-2',
|
|
992
|
-
init: async () => {},
|
|
993
|
-
beforeGenerate: async (config) => ({
|
|
994
|
-
...config,
|
|
995
|
-
lists: {
|
|
996
|
-
...config.lists,
|
|
997
|
-
List2: { fields: { field2: text() } },
|
|
998
|
-
},
|
|
999
|
-
}),
|
|
1000
|
-
}
|
|
1001
|
-
|
|
1002
|
-
const config: OpenSaasConfig = {
|
|
1003
|
-
lists: {},
|
|
1004
|
-
plugins: [plugin1, plugin2],
|
|
1005
|
-
}
|
|
1006
|
-
|
|
1007
|
-
const result = await executeBeforeGenerateHooks(config)
|
|
1008
|
-
|
|
1009
|
-
expect(result.lists.List1).toBeDefined()
|
|
1010
|
-
expect(result.lists.List2).toBeDefined()
|
|
1011
|
-
})
|
|
1012
|
-
|
|
1013
|
-
test('executes afterGenerate hooks', async () => {
|
|
1014
|
-
const afterGenerate = vi.fn((files) => {
|
|
1015
|
-
return {
|
|
1016
|
-
...files,
|
|
1017
|
-
prismaSchema: files.prismaSchema + '\n// Modified by plugin',
|
|
1018
|
-
}
|
|
1019
|
-
})
|
|
1020
|
-
|
|
1021
|
-
const plugin: Plugin = {
|
|
1022
|
-
name: 'test-plugin',
|
|
1023
|
-
init: async () => {},
|
|
1024
|
-
afterGenerate,
|
|
1025
|
-
}
|
|
1026
|
-
|
|
1027
|
-
const config: OpenSaasConfig = {
|
|
1028
|
-
lists: {},
|
|
1029
|
-
plugins: [plugin],
|
|
1030
|
-
}
|
|
1031
|
-
|
|
1032
|
-
const files = {
|
|
1033
|
-
prismaSchema: 'schema content',
|
|
1034
|
-
types: 'types content',
|
|
1035
|
-
context: 'context content',
|
|
1036
|
-
}
|
|
1037
|
-
|
|
1038
|
-
const result = await executeAfterGenerateHooks(config, files)
|
|
1039
|
-
|
|
1040
|
-
expect(afterGenerate).toHaveBeenCalledTimes(1)
|
|
1041
|
-
expect(result.prismaSchema).toContain('// Modified by plugin')
|
|
1042
|
-
})
|
|
1043
|
-
|
|
1044
|
-
test('chains afterGenerate hooks', async () => {
|
|
1045
|
-
const plugin1: Plugin = {
|
|
1046
|
-
name: 'plugin-1',
|
|
1047
|
-
init: async () => {},
|
|
1048
|
-
afterGenerate: async (files) => ({
|
|
1049
|
-
...files,
|
|
1050
|
-
prismaSchema: files.prismaSchema + '\n// Plugin 1',
|
|
1051
|
-
}),
|
|
1052
|
-
}
|
|
1053
|
-
|
|
1054
|
-
const plugin2: Plugin = {
|
|
1055
|
-
name: 'plugin-2',
|
|
1056
|
-
init: async () => {},
|
|
1057
|
-
afterGenerate: async (files) => ({
|
|
1058
|
-
...files,
|
|
1059
|
-
prismaSchema: files.prismaSchema + '\n// Plugin 2',
|
|
1060
|
-
}),
|
|
1061
|
-
}
|
|
1062
|
-
|
|
1063
|
-
const config: OpenSaasConfig = {
|
|
1064
|
-
lists: {},
|
|
1065
|
-
plugins: [plugin1, plugin2],
|
|
1066
|
-
}
|
|
1067
|
-
|
|
1068
|
-
const files = {
|
|
1069
|
-
prismaSchema: 'schema',
|
|
1070
|
-
types: 'types',
|
|
1071
|
-
context: 'context',
|
|
1072
|
-
}
|
|
1073
|
-
|
|
1074
|
-
const result = await executeAfterGenerateHooks(config, files)
|
|
1075
|
-
|
|
1076
|
-
expect(result.prismaSchema).toBe('schema\n// Plugin 1\n// Plugin 2')
|
|
1077
|
-
})
|
|
1078
|
-
|
|
1079
|
-
test('handles no lifecycle hooks', async () => {
|
|
1080
|
-
const config: OpenSaasConfig = {
|
|
1081
|
-
lists: {},
|
|
1082
|
-
plugins: [],
|
|
1083
|
-
}
|
|
1084
|
-
|
|
1085
|
-
const configResult = await executeBeforeGenerateHooks(config)
|
|
1086
|
-
expect(configResult).toEqual(config)
|
|
1087
|
-
|
|
1088
|
-
const files = {
|
|
1089
|
-
prismaSchema: 'schema',
|
|
1090
|
-
types: 'types',
|
|
1091
|
-
context: 'context',
|
|
1092
|
-
}
|
|
1093
|
-
|
|
1094
|
-
const filesResult = await executeAfterGenerateHooks(config, files)
|
|
1095
|
-
expect(filesResult).toEqual(files)
|
|
1096
|
-
})
|
|
1097
|
-
})
|
|
1098
|
-
|
|
1099
|
-
describe('config preservation', () => {
|
|
1100
|
-
test('preserves original config properties', async () => {
|
|
1101
|
-
const plugin: Plugin = {
|
|
1102
|
-
name: 'test-plugin',
|
|
1103
|
-
init: async () => {},
|
|
1104
|
-
}
|
|
1105
|
-
|
|
1106
|
-
const config: OpenSaasConfig = {
|
|
1107
|
-
db: { provider: 'postgresql', url: 'postgresql://localhost' },
|
|
1108
|
-
storage: {
|
|
1109
|
-
provider: 's3',
|
|
1110
|
-
config: { bucket: 'my-bucket' },
|
|
1111
|
-
},
|
|
1112
|
-
lists: {
|
|
1113
|
-
Post: {
|
|
1114
|
-
fields: { title: text() },
|
|
1115
|
-
},
|
|
1116
|
-
},
|
|
1117
|
-
plugins: [plugin],
|
|
1118
|
-
}
|
|
1119
|
-
|
|
1120
|
-
const result = await executePlugins(config)
|
|
1121
|
-
|
|
1122
|
-
expect(result.db).toEqual(config.db)
|
|
1123
|
-
expect(result.storage).toEqual(config.storage)
|
|
1124
|
-
expect(result.lists.Post).toBeDefined()
|
|
1125
|
-
})
|
|
1126
|
-
|
|
1127
|
-
test('does not mutate original config', async () => {
|
|
1128
|
-
const plugin: Plugin = {
|
|
1129
|
-
name: 'test-plugin',
|
|
1130
|
-
init: async (context) => {
|
|
1131
|
-
context.addList('NewList', {
|
|
1132
|
-
fields: { title: text() },
|
|
1133
|
-
})
|
|
1134
|
-
},
|
|
1135
|
-
}
|
|
1136
|
-
|
|
1137
|
-
const config: OpenSaasConfig = {
|
|
1138
|
-
lists: {
|
|
1139
|
-
Post: {
|
|
1140
|
-
fields: { title: text() },
|
|
1141
|
-
},
|
|
1142
|
-
},
|
|
1143
|
-
plugins: [plugin],
|
|
1144
|
-
}
|
|
1145
|
-
|
|
1146
|
-
const originalListsKeys = Object.keys(config.lists)
|
|
1147
|
-
|
|
1148
|
-
await executePlugins(config)
|
|
1149
|
-
|
|
1150
|
-
// Original config should not have NewList
|
|
1151
|
-
expect(Object.keys(config.lists)).toEqual(originalListsKeys)
|
|
1152
|
-
expect(config.lists.NewList).toBeUndefined()
|
|
1153
|
-
})
|
|
1154
|
-
})
|
|
1155
|
-
})
|