ddd-ts-kit 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/README.md +9 -4
  2. package/dist/check/catalogue/architecture-rules.d.ts.map +1 -1
  3. package/dist/check/catalogue/architecture-rules.js +2 -0
  4. package/dist/check/catalogue/architecture-rules.js.map +1 -1
  5. package/dist/check/explain/rule-docs.d.ts.map +1 -1
  6. package/dist/check/explain/rule-docs.js +2 -0
  7. package/dist/check/explain/rule-docs.js.map +1 -1
  8. package/dist/check/explain/tenancy-docs.d.ts +3 -0
  9. package/dist/check/explain/tenancy-docs.d.ts.map +1 -0
  10. package/dist/check/explain/tenancy-docs.js +15 -0
  11. package/dist/check/explain/tenancy-docs.js.map +1 -0
  12. package/dist/check/fixtures/fixtures.d.ts.map +1 -1
  13. package/dist/check/fixtures/fixtures.js +2 -0
  14. package/dist/check/fixtures/fixtures.js.map +1 -1
  15. package/dist/check/fixtures/tenancy-fixtures.d.ts +3 -0
  16. package/dist/check/fixtures/tenancy-fixtures.d.ts.map +1 -0
  17. package/dist/check/fixtures/tenancy-fixtures.js +136 -0
  18. package/dist/check/fixtures/tenancy-fixtures.js.map +1 -0
  19. package/dist/check/rules/tenancy-scoped-statement.d.ts +3 -0
  20. package/dist/check/rules/tenancy-scoped-statement.d.ts.map +1 -0
  21. package/dist/check/rules/tenancy-scoped-statement.js +37 -0
  22. package/dist/check/rules/tenancy-scoped-statement.js.map +1 -0
  23. package/dist/check/tenancy/balanced-arguments.d.ts +3 -0
  24. package/dist/check/tenancy/balanced-arguments.d.ts.map +1 -0
  25. package/dist/check/tenancy/balanced-arguments.js +13 -0
  26. package/dist/check/tenancy/balanced-arguments.js.map +1 -0
  27. package/dist/check/tenancy/declared-with.d.ts +11 -0
  28. package/dist/check/tenancy/declared-with.d.ts.map +1 -0
  29. package/dist/check/tenancy/declared-with.js +13 -0
  30. package/dist/check/tenancy/declared-with.js.map +1 -0
  31. package/dist/check/tenancy/drizzle-unscoped.d.ts +7 -0
  32. package/dist/check/tenancy/drizzle-unscoped.d.ts.map +1 -0
  33. package/dist/check/tenancy/drizzle-unscoped.js +35 -0
  34. package/dist/check/tenancy/drizzle-unscoped.js.map +1 -0
  35. package/dist/check/tenancy/executor-uses.d.ts +11 -0
  36. package/dist/check/tenancy/executor-uses.d.ts.map +1 -0
  37. package/dist/check/tenancy/executor-uses.js +14 -0
  38. package/dist/check/tenancy/executor-uses.js.map +1 -0
  39. package/dist/check/tenancy/knex-unscoped.d.ts +7 -0
  40. package/dist/check/tenancy/knex-unscoped.d.ts.map +1 -0
  41. package/dist/check/tenancy/knex-unscoped.js +19 -0
  42. package/dist/check/tenancy/knex-unscoped.js.map +1 -0
  43. package/dist/check/tenancy/unscoped-read-models.d.ts +4 -0
  44. package/dist/check/tenancy/unscoped-read-models.d.ts.map +1 -0
  45. package/dist/check/tenancy/unscoped-read-models.js +15 -0
  46. package/dist/check/tenancy/unscoped-read-models.js.map +1 -0
  47. package/dist/commands/init.d.ts.map +1 -1
  48. package/dist/commands/init.js +1 -0
  49. package/dist/commands/init.js.map +1 -1
  50. package/dist/config/index.d.ts +1 -1
  51. package/dist/config/index.d.ts.map +1 -1
  52. package/dist/config/index.js +1 -1
  53. package/dist/config/index.js.map +1 -1
  54. package/dist/config/parse-stack.d.ts.map +1 -1
  55. package/dist/config/parse-stack.js +2 -1
  56. package/dist/config/parse-stack.js.map +1 -1
  57. package/dist/config/stack.d.ts +10 -0
  58. package/dist/config/stack.d.ts.map +1 -1
  59. package/dist/config/stack.js +7 -0
  60. package/dist/config/stack.js.map +1 -1
  61. package/dist/config/written-stack.d.ts.map +1 -1
  62. package/dist/config/written-stack.js +6 -2
  63. package/dist/config/written-stack.js.map +1 -1
  64. package/dist/generate/kinds/generate-repository.js +5 -4
  65. package/dist/generate/kinds/generate-repository.js.map +1 -1
  66. package/dist/help/usage.d.ts +1 -1
  67. package/dist/help/usage.d.ts.map +1 -1
  68. package/dist/help/usage.js +1 -1
  69. package/dist/init/manifest/versions.js +23 -23
  70. package/dist/init/stack/resolve-stack.d.ts.map +1 -1
  71. package/dist/init/stack/resolve-stack.js +2 -0
  72. package/dist/init/stack/resolve-stack.js.map +1 -1
  73. package/dist/init/stack/resolve-tenancy.d.ts +8 -0
  74. package/dist/init/stack/resolve-tenancy.d.ts.map +1 -0
  75. package/dist/init/stack/resolve-tenancy.js +31 -0
  76. package/dist/init/stack/resolve-tenancy.js.map +1 -0
  77. package/dist/init/stack/stack-options.d.ts +1 -0
  78. package/dist/init/stack/stack-options.d.ts.map +1 -1
  79. package/dist/stack/stack-vars.d.ts.map +1 -1
  80. package/dist/stack/stack-vars.js +2 -1
  81. package/dist/stack/stack-vars.js.map +1 -1
  82. package/dist/version.d.ts +1 -1
  83. package/dist/version.js +1 -1
  84. package/package.json +2 -2
  85. package/templates/init/platform/audit/audit.module.manual.ts.tpl +5 -0
  86. package/templates/init/platform/audit/audit.module.tsyringe.ts.tpl +5 -0
  87. package/templates/init/platform/audit/create-audit.ts.tpl +24 -0
  88. package/templates/init/platform/audit/search-audit-entries.handler.ts.tpl +13 -0
  89. package/templates/init/platform/audit/search-audit-entries.query.ts.tpl +5 -0
  90. package/templates/init/platform/auth/http-boundary.ts.tpl +38 -1
  91. package/templates/init/platform/compose-application.manual.ts.tpl +3 -0
  92. package/templates/init/platform/compose-application.tsyringe.ts.tpl +14 -0
  93. package/templates/init/platform/database/persistence-over.knex.ts.tpl +5 -0
  94. package/templates/init/platform/database/schema.drizzle.ts.tpl +8 -0
  95. package/templates/init/platform/database/schema.knex.ts.tpl +6 -0
  96. package/templates/init/rules/infrastructure.md.tpl +3 -0
  97. package/templates/pipeline/package-scripts.json +1 -1
  98. package/templates/repository/drizzle/repository.ts.tpl +7 -8
  99. package/templates/repository/knex/repository.ts.tpl +32 -12
package/README.md CHANGED
@@ -51,6 +51,7 @@ ddd-ts-kit init [--http express|fastify|nest|none]
51
51
  [--style declared|explicit] [--assembly barrel|discovery]
52
52
  [--dependencies signature|listed] [--refusals factories|classes]
53
53
  [--routes controllers|functions] [--value-objects throwing|result]
54
+ [--literals named|free] [--tenancy none|shared-table]
54
55
  [--package-manager npm|pnpm]
55
56
  [--allow-no-outbox "<reason>"] [--import-alias '$<name>/']
56
57
  [--import-extension none|js] [--sdk]
@@ -192,7 +193,8 @@ config, `docsUi`, `ci` and `logger` included.
192
193
  | tracing | wired once, by the platform (`tracing/platform-only`): no `decorate` hook, no `decorate-bindings.ts`. `tracing.ts` starts `initTracing` of `@ddd-ts-kit/tracing/node` before any other module, on what `config/read-tracing.ts` validates: `OTEL_EXPORTER_OTLP_ENDPOINT` (a URL; left out, no span leaves the process), `TRACE_SAMPLE_RATIO` (0 to 1) and `TRACE_CONSUMERS` (`continue`, the default: a consumed event stays in the trace of its publication; `link`: each delivery starts a trace linked to it). With `--di tsyringe`: `lay-foundations.ts` builds `traceApplication({ consumers })`, `compose-application.ts` hands it to `kernelModule({ instrumentation })` (one span per use case, repository call, domain event, publication, consumer and job) and gives the outbox relay `tracedPublisher(bus)`. With hand wiring: `create-platform.ts` applies the members of `traceApplication()` itself (`useCase` on both buses, `domainEvents`, `publisher`, `binding` around every adapter, `job`, `executionScope`, `errorReporter`), with `tracedSubscriber` and `tracedPublisher` around the provider. With an HTTP stack, in both families, `auth/http-boundary.ts` sets `around: tracedRoutes()`: one `SERVER` span per request, named by its route |
193
194
  | `--logger` | `src/platform/observability/create-logger.ts`, one per choice: `stdout` (the default) is the `StdoutLogger` of `@ddd-ts-kit/aspects`, JSON lines, credentials not redacted; `pino` is `createPinoLogger` of `@ddd-ts-kit/pino` (dependencies `pino` and `pino-pretty`); `winston` is `createWinstonLogger` of `@ddd-ts-kit/winston`; these two redact the credential keys of the kernel. Every entry carries `traceLogFields(scope)`: the correlation id, origin, actor and tenant of the work in progress and the ids of the active trace. `LOG_LEVEL`, `LOG_FORMAT` (`json`, the default, or `pretty`; with `stdout`, which has no pretty format, `pretty` is refused when the configuration is loaded) and `LOG_SCRUB_MESSAGES` (`[message removed]` in place of the message of a logged error that is not a `DomainError`) are validated in `config/load-config.ts`. Stopping the application flushes the error reporter, then the logger, last: `container.stop()` does it on tsyringe, `compose-application.ts` flushes explicitly with hand wiring. The tools and the tests compose the application without `log` and write nothing |
194
195
  | `src/platform/auth/` | `create-authenticator.ts` (`--authn jwt`: `JwtAuthenticator` on `AUTH_ISSUER`, `AUTH_AUDIENCE`, `AUTH_JWKS_URI`; `--authn keycloak`: `keycloakAuthenticator` on `KEYCLOAK_URL`, `KEYCLOAK_REALM`, `KEYCLOAK_AUDIENCE` and the optional `KEYCLOAK_CLIENT_ID`; `--authn none`: `development-header-authenticator.ts`, which reads `x-development-actor` and throws in production), `principal-of.ts`, `security-schemes.ts`, `offline-authenticator.ts`, `http-boundary.ts` (`resolvePrincipal` answering a `Session`, `executionScope`, `errorMapper` and `onError`, spread into the mount options: every request runs inside the execution scope, with its correlation id), `create-authorizer.ts` and the files of the model (`roles.ts`, with the role `system` every system actor holds; `attribute-policies.ts`; `relationship-schema.ts`, `create-tuple-store.ts` and its contract spec, `relation-tuples.ts`, `relate-system-actors.ts`, `permission-mapping.ts` and `permissions.ts`; `custom-authorizer.ts`, its `authorizerContract` spec and `permissions.ts`), `authorization.ts` (`authorizationModule` with tsyringe) or `use-case-protection.ts` (the guard of the hand-wired buses), `access-policies.ts`, and with `--audit off` `log-decisions.ts` (one log entry per decision, ids and codes only). Without an HTTP stack there is no authenticator and no boundary |
195
- | `--audit on` | `src/platform/audit/`: `create-audit.ts` (the trail, the `onDecision` of the authorization, the middleware before the unit of work, the integration events subscribed under the consumer name `audit`), `audited-events.ts` (the registry `generate integration-event` adds to), `audit.module.ts`, and with an HTTP stack the read side: `audit.permissions.ts` (`audit:trail.read`), `search-audit-entries.query.ts`, its handler, `search-audit-entries.route.ts` (`GET /audit/entries`: cursor pages, filters `actorId`, `action`, `outcome`, `correlationId`). It is a capability of the platform, not a bounded context: no model, one protected query over the `AuditReader` port, bounded by the tenant of the actor. A scheduled job is audited like a request: origin `schedule`, actor `system:<context>.<job>`. With knex the two tables and their append-only triggers are created by the first migration; with drizzle the tables are in `schema.ts` and `npm run db:audit-guard` prints the trigger statements for a custom migration; with prisma, typeorm, `custom` or no ORM the trail is an `InMemoryAuditTrail` behind a `TODO(platform)`. The test databases leave the audit schema out of `reset()` |
196
+ | `--audit on` | `src/platform/audit/`: `create-audit.ts` (the trail, the `onDecision` of the authorization, the refusals of the guards at the edge given to the HTTP boundary as `onGuardRefusal`, the middleware before the unit of work, the integration events subscribed under the consumer name `audit`), `audited-events.ts` (the registry `generate integration-event` adds to), `audit.module.ts`, and with an HTTP stack the read side: `audit.permissions.ts` (`audit:trail.read`), `search-audit-entries.query.ts`, its handler, `search-audit-entries.route.ts` (`GET /audit/entries`: cursor pages, filters `actorId`, `action`, `outcome`, `correlationId`). It is a capability of the platform, not a bounded context: no model, one protected query over the `AuditReader` port, bounded by the tenant of the actor (with `--tenancy shared-table`, by the tenant of the work through `TenantAuditReader`: platform staff read across tenants only inside `acrossTenants`). The refusals of a caller without a credential are not recorded. A scheduled job is audited like a request: origin `schedule`, actor `system:<context>.<job>`. With knex the two tables and their append-only triggers are created by the first migration; with drizzle the tables are in `schema.ts` and `npm run db:audit-guard` prints the trigger statements for a custom migration; with prisma, typeorm, `custom` or no ORM the trail is an `InMemoryAuditTrail` behind a `TODO(platform)`. The test databases leave the audit schema out of `reset()` |
197
+ | `--tenancy shared-table` | recorded as `stack.tenancy`; Knex or Drizzle only. Every `generate repository` is tenant-scoped (as `--tenant-scoped`), through `tenantTable` and `ownTenantTable` or `tenantCondition` and `ownTenantCondition`; the outbox keeps the tenant of each event (`createOutboxTables(knex, { tenant: true })` and `KnexOutboxStore`'s `tenant: true`, or `tenantOutboxTable`), so consumers run in it; `tenancy/scoped-statement` judges the adapters. Row-level security, schema per tenant and database per tenant are refused, with what to wire by hand ([Multitenancy](../../docs/concepts/multitenancy.md)) |
196
198
  | `--cache redis` | `src/platform/redis/open-redis.ts` (`RedisServices`: the cache bound to the kernel `Cache`, the limiter to `RateLimiter`, the lock to `Lock`, which keeps a scheduled job to one instance, the relay signal as the `wakeOn` of the outbox relay with `relayWakeUpMiddleware` on the command bus), `http/refusal-for.ts` (one sliding window per caller address, 429 `application/problem+json` with `retry-after`; `RATE_LIMIT_MAX`, `RATE_LIMIT_WINDOW_MS`), `GET /health/ready` on the HTTP server, `REDIS_URL` validated, a compose service `cache` running Dragonfly with a healthcheck. Without a server (tools, tests without `REDIS_URL`) the same ports stay in the memory of the process |
197
199
  | `--errors sentry` | unexpected failures reported to Sentry or GlitchTip (one protocol, only the DSN differs) through the kernel `ErrorReporter`, bound to `@ddd-ts-kit/sentry`. `src/platform/errors.ts` (`initSentry` on the validated configuration, then `reportProcessFailures`), the second import of `main.ts`, of `apps/<context>/main.ts` and of `apps/worker/main.ts`, right after `tracing.ts`; `errors` handed to `composeApplication`, which gives it to the kernel module on tsyringe (`errorReporter`, flushed by `container.stop()` before the logger, `errorReportingMiddleware` first on both buses, the default scheduler observing with `reportFailedRuns`) or to `createPlatform` by hand (the same middleware, `onRun: reportFailedRuns(errors)`, `platform.errors`, flushed two seconds at most when the application stops); `reportHttpErrors` in `auth/http-boundary.ts` for every request answered 5xx; `DeadLetterReports` on the `onFailure` hook of a provided broker (`createEventProvider(config, errors)`, with `observing` around each consumer) and of the outbox relay. `SENTRY_DSN`, `SENTRY_ENVIRONMENT` (default: `NODE_ENV`), `SENTRY_RELEASE` and `SENTRY_SCRUB_MESSAGES` validated in `config/load-config.ts` as `errorReporting`: without a DSN the application starts and reports nothing; a DSN that is not a URL refuses the start. Dependencies `@ddd-ts-kit/sentry` and `@sentry/node`. A compose profile `errors` running GlitchTip 6.2.6 with its own PostgreSQL and Valkey (`GLITCHTIP_PORT`, loopback only, development bootstrap), and a section of the generated README saying how to read its DSN. The tools and the tests compose the application without a reporter. It goes with every other choice of the stack; with `--errors none` nothing of this is written |
198
200
  | `--authn keycloak` | a compose service `keycloak` (Keycloak 26.8.0, `start-dev --import-realm`, profile `identity`) and `docker/keycloak/<project>-realm.json`: the API client, a public client `<project>-local` with the direct grant, its audience and `tenant_id` mappers, the realm role `admin`, and the demo users `demo-admin` and `demo-user`, for local development only |
@@ -362,9 +364,11 @@ ddd-ts-kit generate --help --json
362
364
  `ActorContext` nor a dispatcher, and stamps `created_at`, `created_by`, `updated_at`, `updated_by` with `stampCreation` and `stampUpdate`;
363
365
  the table uses `auditColumns` of the ORM package (the five fields are written out for Prisma).
364
366
  The sample fact of an aggregate is `registeredAt`, since `created_at` is the audit column.
365
- `repository --tenant-scoped` (drizzle and knex) adds `tenantColumn` and puts `tenantScopeOf(scope)`
366
- on the insert and in the condition of every read and update, with a spec that one tenant does
367
- not see another's rows. With another ORM the regular adapter is written and a note says what to add.
367
+ `repository --tenant-scoped` (drizzle and knex), and every repository of a project whose
368
+ `stack.tenancy` is `shared-table`, adds `tenantColumn`, names the tenant on the insert and reaches
369
+ the table through the helpers of the ORM package (`tenantTable` and `ownTenantTable` on Knex,
370
+ `tenantCondition` and `ownTenantCondition` on Drizzle), with a spec that one tenant does not see
371
+ another's rows. With another ORM the regular adapter is written and a note says what to add.
368
372
  - `adapter --decorators` is accepted on every stack: the aspects decorators serve the standard
369
373
  mode and the legacy one a `tsconfig.json` with `experimentalDecorators` imposes.
370
374
  - `route` of a `--search` query reads the page with `pageQuerySchema` and answers `pageSchemaOf` and
@@ -761,6 +765,7 @@ saying what to do instead. Exit code 1 when there is at least one error.
761
765
  | `authz/actor-explicit` | in `domain/` and `application/`: `ActorContext`, `ExecutionScope` (as a type or as a value: the class is the token of a dependency list), `AsyncLocalStorageExecutionScope`, `ScopedActorContext`, `AsyncLocalStorage`; `.current()` or `.require()` on an actor context or on something named `scope`, `scopes` or `...executionScope`; an import of `stampCreation`, `stampUpdate` or `tenantScopeOf` |
762
766
  | `aspects/outside-in` | an import of `@ddd-ts-kit/aspects/decorators` outside `infrastructure/` of a context and the platform directory: `presentation/`, the module file, `published-language/`, the shared kernel, `main.ts`, any other source (`domain/` and `application/` are reported by the two `layer/*` rules instead) |
763
767
  | `tracing/platform-only` | an import of `@ddd-ts-kit/tracing` or of an `@opentelemetry/*` package outside the platform directory, `main.ts` and `apps/`, tests included |
768
+ | `tenancy/scoped-statement` | with `stack.tenancy` other than `none`, in `infrastructure/` of a context, tests aside: on Knex the executor used other than as an argument (`executor()(`, `executor().from(`, `executor().raw(`, `const db = ...executor();`) and any `.raw(`; on Drizzle, statement by statement, a read, update or delete on the executor whose where has no `tenantCondition(` nor `ownTenantCondition(` (inline or in the local it is given), an insert whose row has no `tenantScopeOf(`, a relational query (`executor().query`), a raw `execute(`, or the executor held in a variable; on both, a read model store built without its `tenant` option. A where built by another function is not followed |
764
769
  | `standard/no-parallel-interface` | a class, interface or type alias declared as `ILogger`, `AppLogger`, `LoggerService`, `LoggerInterface`, `IMetrics`, `MetricsService`, `ICache`, `CacheService`, `UserContext`, `CurrentUser`, `AuthContext`, `RequestContext` (outside `presentation/` and the platform), `UserSession`, `AuthSession`, `SessionData`, `PaginatedResult`, `PageResult`, `PaginatedResponse`, `Paginated`, `PaginationParams`, `PageParams`, `AuditLog`, `AuditLogEntry`, `AuditRecord`, `IJobScheduler`, `JobSchedulerService`, `CronScheduler`, `TaskScheduler`, `IScheduledJob`, `CronJob`, `ScheduledTask`, `BackgroundJob`, `IErrorReporter`, `ErrorReporterService`, `ErrorTracker`, `ExceptionReporter`, `CrashReporter`, `I` followed by a standard name (`IClock`, `IIdGenerator`, `IUnitOfWork`, `ISession`, ...) or a name of `standardInterfaces`; a class that implements or extends the standard interface is an adapter and is not reported |
765
770
  | `events/outbox-required` | `stack.events` other than `outbox` with an ORM and no `stack.events` deviation; in `domain/` and `application/`, the import of a broker client or of a bus or relay implementation; a publisher depending on more than `IntegrationEventPublisher`; a platform module that hands out a publisher and never names `OutboxPublisher` |
766
771
  | `events/consumer-idempotent` | an integration event handler class (`application/integration/handlers/*.integration-handler.ts`) that neither carries `@IntegrationEventHandler` nor is registered in its module file under a consumer name; an `@IntegrationEventHandler` whose `consumer` is not a non-empty string literal; a free `on(` or `consume(` without `processed`; a consumer name used twice, in declarations and registrations alike |
@@ -1 +1 @@
1
- {"version":3,"file":"architecture-rules.d.ts","sourceRoot":"","sources":["../../../src/check/catalogue/architecture-rules.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAmE7C,gHAAgH;AAChH,eAAO,MAAM,kBAAkB,EAAE,SAAS,IAAI,EAkE7C,CAAC"}
1
+ {"version":3,"file":"architecture-rules.d.ts","sourceRoot":"","sources":["../../../src/check/catalogue/architecture-rules.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAoE7C,gHAAgH;AAChH,eAAO,MAAM,kBAAkB,EAAE,SAAS,IAAI,EAmE7C,CAAC"}
@@ -56,6 +56,7 @@ import { purityNoSystemClock } from '../rules/purity-no-system-clock.js';
56
56
  import { schedulingJobName } from '../rules/scheduling-job-name.js';
57
57
  import { schedulingJobTriggersUseCase } from '../rules/scheduling-job-triggers-use-case.js';
58
58
  import { standardNoParallelInterface } from '../rules/standard-no-parallel-interface.js';
59
+ import { tenancyScopedStatement } from '../rules/tenancy-scoped-statement.js';
59
60
  import { testBuilderRequired } from '../rules/test-builder-required.js';
60
61
  import { testCoverageGoverned } from '../rules/test-coverage-governed.js';
61
62
  import { testNoMocks } from '../rules/test-no-mocks.js';
@@ -111,6 +112,7 @@ export const ARCHITECTURE_RULES = [
111
112
  authzActorExplicit,
112
113
  aspectsOutsideIn,
113
114
  tracingPlatformOnly,
115
+ tenancyScopedStatement,
114
116
  standardNoParallelInterface,
115
117
  governanceRecordedDeviation,
116
118
  compositionOnlyInModule,
@@ -1 +1 @@
1
- {"version":3,"file":"architecture-rules.js","sourceRoot":"","sources":["../../../src/check/catalogue/architecture-rules.ts"],"names":[],"mappings":"AACA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gCAAgC;IAChC,WAAW;IACX,mBAAmB;IACnB,oBAAoB;IACpB,oBAAoB;IACpB,uBAAuB;IACvB,0BAA0B;IAC1B,mBAAmB;IACnB,yBAAyB;IACzB,mBAAmB;IACnB,aAAa;IACb,iBAAiB;IACjB,uBAAuB;IACvB,mBAAmB;IACnB,kBAAkB;IAClB,mBAAmB;IACnB,kBAAkB;IAClB,eAAe;IACf,WAAW;IACX,qBAAqB;IACrB,aAAa;IACb,oBAAoB;IACpB,wBAAwB;IACxB,4BAA4B;IAC5B,qCAAqC;IACrC,kBAAkB;IAClB,aAAa;IACb,kBAAkB;IAClB,kBAAkB;IAClB,gBAAgB;IAChB,mBAAmB;IACnB,2BAA2B;IAC3B,2BAA2B;IAC3B,uBAAuB;IACvB,wBAAwB;IACxB,yBAAyB;IACzB,gCAAgC;IAChC,kBAAkB;IAClB,2BAA2B;IAC3B,oBAAoB;IACpB,yBAAyB;IACzB,gBAAgB;IAChB,4BAA4B;IAC5B,iBAAiB;IACjB,gBAAgB;IAChB,gBAAgB;IAChB,oBAAoB;IACpB,gBAAgB;IAChB,eAAe;IACf,2BAA2B;CAC5B,CAAC"}
1
+ {"version":3,"file":"architecture-rules.js","sourceRoot":"","sources":["../../../src/check/catalogue/architecture-rules.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,u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B;IAClB,kBAAkB;IAClB,gBAAgB;IAChB,mBAAmB;IACnB,sBAAsB;IACtB,2BAA2B;IAC3B,2BAA2B;IAC3B,uBAAuB;IACvB,wBAAwB;IACxB,yBAAyB;IACzB,gCAAgC;IAChC,kBAAkB;IAClB,2BAA2B;IAC3B,oBAAoB;IACpB,yBAAyB;IACzB,gBAAgB;IAChB,4BAA4B;IAC5B,iBAAiB;IACjB,gBAAgB;IAChB,gBAAgB;IAChB,oBAAoB;IACpB,gBAAgB;IAChB,eAAe;IACf,2BAA2B;CAC5B,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"rule-docs.d.ts","sourceRoot":"","sources":["../../../src/check/explain/rule-docs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAiBpD,oGAAoG;AACpG,eAAO,MAAM,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAgBvD,CAAC"}
1
+ {"version":3,"file":"rule-docs.d.ts","sourceRoot":"","sources":["../../../src/check/explain/rule-docs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAkBpD,oGAAoG;AACpG,eAAO,MAAM,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAiBvD,CAAC"}
@@ -11,6 +11,7 @@ import { PERSISTENCE_DOCS } from './persistence-docs.js';
11
11
  import { PORTS_DOCS } from './ports-docs.js';
12
12
  import { SCHEDULING_DOCS } from './scheduling-docs.js';
13
13
  import { STANDARD_DOCS } from './standard-docs.js';
14
+ import { TENANCY_DOCS } from './tenancy-docs.js';
14
15
  import { TREE_DOCS } from './tree-docs.js';
15
16
  import { WIRING_DOCS } from './wiring-docs.js';
16
17
  /** Shown by `ddd-ts-kit explain <rule-id>`: the reason behind the rule and one example each way. */
@@ -28,6 +29,7 @@ export const RULE_DOCS = {
28
29
  ...PORTS_DOCS,
29
30
  ...SCHEDULING_DOCS,
30
31
  ...STANDARD_DOCS,
32
+ ...TENANCY_DOCS,
31
33
  ...TREE_DOCS,
32
34
  ...WIRING_DOCS,
33
35
  };
@@ -1 +1 @@
1
- {"version":3,"file":"rule-docs.js","sourceRoot":"","sources":["../../../src/check/explain/rule-docs.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,oGAAoG;AACpG,MAAM,CAAC,MAAM,SAAS,GAAsC;IAC1D,GAAG,UAAU;IACb,GAAG,UAAU;IACb,GAAG,YAAY;IACf,GAAG,WAAW;IACd,GAAG,WAAW;IACd,GAAG,YAAY;IACf,GAAG,aAAa;IAChB,GAAG,UAAU;IACb,GAAG,WAAW;IACd,GAAG,gBAAgB;IACnB,G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,UAAU;IACb,GAAG,eAAe;IAClB,GAAG,aAAa;IAChB,GAAG,YAAY;IACf,GAAG,SAAS;IACZ,GAAG,WAAW;CACf,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { RuleDoc } from '../model/rule-doc.js';
2
+ export declare const TENANCY_DOCS: Readonly<Record<string, RuleDoc>>;
3
+ //# sourceMappingURL=tenancy-docs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tenancy-docs.d.ts","sourceRoot":"","sources":["../../../src/check/explain/tenancy-docs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAEpD,eAAO,MAAM,YAAY,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAa1D,CAAC"}
@@ -0,0 +1,15 @@
1
+ export const TENANCY_DOCS = {
2
+ 'tenancy/scoped-statement': {
3
+ why: 'On shared tables, one statement without its tenant condition reads or overwrites the data of every tenant: the most common and the most damaging leak of a multi-tenant application. The kit puts the condition in one place, the helpers of the ORM package, which read the tenant from the execution scope, refuse work that names none, widen reads only under an audited elevation and never widen writes. A table reached straight from the executor bypasses all of it. Judged in a project whose "stack.tenancy" is not "none": the infrastructure of the contexts, tests aside. Checked by text, statement by statement: on Knex the executor used other than as the argument of a helper, and raw SQL; on Drizzle a read, update or delete whose where carries no tenant condition (inline or in the local it is given), an insert whose row names no tenant, a relational query or a raw execute; on both, a read model store built without its tenant option. A where built by another function is not followed: inline it, or record a deviation.',
4
+ bad: `// infrastructure/persistence/knex-invoice.repository.ts
5
+ const row = await this.database.executor()<InvoiceRow, InvoiceRow[]>('invoices').where({ id }).first();
6
+ const all = await this.database.executor().from('invoices').where({ status }); // the executor chained
7
+ // infrastructure/persistence/drizzle-invoice.repository.ts
8
+ await this.database.executor().select().from(invoices).where(eq(invoices.id, id));
9
+ await this.database.executor().query.invoices.findMany(); // a relational query cannot carry the condition`,
10
+ good: `const row = await tenantTable<InvoiceRow>(this.database, this.scope, INVOICES).where({ id }).first();
11
+ await ownTenantTable<InvoiceRow>(this.database, this.scope, INVOICES).where({ id, version }).update(changes);
12
+ await this.database.executor().select().from(invoices).where(and(eq(invoices.id, id), tenantCondition(invoices.tenantId, this.scope)));`,
13
+ },
14
+ };
15
+ //# sourceMappingURL=tenancy-docs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tenancy-docs.js","sourceRoot":"","sources":["../../../src/check/explain/tenancy-docs.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,YAAY,GAAsC;IAC7D,0BAA0B,EAAE;QAC1B,GAAG,EAAE,+/BAA+/B;QACpgC,GAAG,EAAE;;;;;2GAKkG;QACvG,IAAI,EAAE;;wIAE8H;KACrI;CACF,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"fixtures.d.ts","sourceRoot":"","sources":["../../../src/check/fixtures/fixtures.ts"],"names":[],"mappings":"AAgCA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C;;;;GAIG;AACH,eAAO,MAAM,QAAQ,EAAE,SAAS,OAAO,EAiCtC,CAAC"}
1
+ {"version":3,"file":"fixtures.d.ts","sourceRoot":"","sources":["../../../src/check/fixtures/fixtures.ts"],"names":[],"mappings":"AAiCA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C;;;;GAIG;AACH,eAAO,MAAM,QAAQ,EAAE,SAAS,OAAO,EAkCtC,CAAC"}
@@ -27,6 +27,7 @@ import { PORTS_FIXTURES } from './ports-fixtures.js';
27
27
  import { PURITY_FIXTURES } from './purity-fixtures.js';
28
28
  import { SCHEDULING_FIXTURES } from './scheduling-fixtures.js';
29
29
  import { STANDARD_FIXTURES } from './standard-fixtures.js';
30
+ import { TENANCY_FIXTURES } from './tenancy-fixtures.js';
30
31
  import { TEST_FIXTURES } from './test-fixtures.js';
31
32
  import { TRACING_FIXTURES } from './tracing-fixtures.js';
32
33
  import { TREE_FIXTURES } from './tree-fixtures.js';
@@ -65,6 +66,7 @@ export const FIXTURES = [
65
66
  ...PURITY_FIXTURES,
66
67
  ...SCHEDULING_FIXTURES,
67
68
  ...STANDARD_FIXTURES,
69
+ ...TENANCY_FIXTURES,
68
70
  ...TEST_FIXTURES,
69
71
  ...TRACING_FIXTURES,
70
72
  ...TREE_FIXTURES,
@@ -1 +1 @@
1
- {"version":3,"file":"fixtures.js","sourceRoot":"","sources":["../../../src/check/fixtures/fixtures.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,8BAA8B,EAAE,MAAM,qCAAqC,CAAC;AACrF,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,g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ACpB,GAAG,mBAAmB;IACtB,GAAG,cAAc;IACjB,GAAG,eAAe;IAClB,GAAG,eAAe;IAClB,GAAG,eAAe;IAClB,GAAG,oBAAoB;IACvB,GAAG,cAAc;IACjB,GAAG,eAAe;IAClB,GAAG,mBAAmB;IACtB,GAAG,iBAAiB;IACpB,GAAG,gBAAgB;IACnB,GAAG,aAAa;IAChB,GAAG,gBAAgB;IACnB,GAAG,aAAa;CACjB,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Fixture } from './fixture.js';
2
+ export declare const TENANCY_FIXTURES: readonly Fixture[];
3
+ //# sourceMappingURL=tenancy-fixtures.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tenancy-fixtures.d.ts","sourceRoot":"","sources":["../../../src/check/fixtures/tenancy-fixtures.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAsF5C,eAAO,MAAM,gBAAgB,EAAE,SAAS,OAAO,EAwF9C,CAAC"}
@@ -0,0 +1,136 @@
1
+ import { CONFIG_FILE } from '../../config/index.js';
2
+ import { config } from './config.js';
3
+ import { PATHS } from './paths.js';
4
+ import { project } from './project.js';
5
+ const RULE = 'tenancy/scoped-statement';
6
+ const KNEX_ADAPTER = `${PATHS.BILLING}/infrastructure/persistence/knex-invoice.repository.ts`;
7
+ const DRIZZLE_ADAPTER = `${PATHS.BILLING}/infrastructure/persistence/drizzle-invoice.repository.ts`;
8
+ const KNEX_SCOPED = `import { ownTenantTable, tenantTable } from '@ddd-ts-kit/knex';
9
+
10
+ export class KnexInvoiceRepository {
11
+ findById(id: string) {
12
+ return tenantTable(this.database, this.scope, INVOICES).where({ id }).first();
13
+ }
14
+
15
+ remove(id: string) {
16
+ return ownTenantTable(this.database, this.scope, INVOICES).where({ id }).delete();
17
+ }
18
+ }
19
+ `;
20
+ const KNEX_UNSCOPED = `export class KnexInvoiceRepository {
21
+ findById(id: string) {
22
+ return this.database.executor()<InvoiceRow, InvoiceRow[]>('invoices').where({ id }).first();
23
+ }
24
+ }
25
+ `;
26
+ const DRIZZLE_SCOPED = `import { ownTenantCondition, tenantCondition } from '@ddd-ts-kit/drizzle/postgres';
27
+ import { tenantScopeOf } from '@ddd-ts-kit/kernel';
28
+
29
+ export class DrizzleInvoiceRepository {
30
+ findById(id: string) {
31
+ const mine = and(eq(invoices.id, id), tenantCondition(invoices.tenantId, this.scope));
32
+
33
+ return this.database.executor().select().from(invoices).where(mine);
34
+ }
35
+
36
+ insert(state: InvoiceRow) {
37
+ const row = { ...state, ...tenantScopeOf(this.scope) };
38
+
39
+ return this.database.executor().insert(invoices).values(row);
40
+ }
41
+
42
+ remove(id: string) {
43
+ return this.database
44
+ .executor()
45
+ .delete(invoices)
46
+ .where(and(eq(invoices.id, id), ownTenantCondition(invoices.tenantId, this.scope)));
47
+ }
48
+ }
49
+ `;
50
+ const DRIZZLE_UNSCOPED = `export class DrizzleInvoiceRepository {
51
+ findById(id: string) {
52
+ return this.database.executor().select().from(invoices).where(eq(invoices.id, id));
53
+ }
54
+ }
55
+ `;
56
+ const tenancy = (orm, value = 'shared-table') => ({
57
+ [CONFIG_FILE]: config({ stack: { orm, tenancy: value } }),
58
+ });
59
+ /** A repository of a shared-table project whose one method goes around the helpers. */
60
+ const bypass = (orm, name, body) => {
61
+ const adapter = orm === 'knex' ? KNEX_ADAPTER : DRIZZLE_ADAPTER;
62
+ const owner = orm === 'knex' ? 'KnexInvoiceRepository' : 'DrizzleInvoiceRepository';
63
+ return {
64
+ ruleId: RULE,
65
+ name: `${orm}: ${name}`,
66
+ expect: { file: adapter },
67
+ files: project({ [adapter]: `export class ${owner} {\n find() {\n ${body}\n }\n}\n` }, tenancy(orm)),
68
+ };
69
+ };
70
+ const READ_MODEL = `${PATHS.BILLING}/infrastructure/persistence/knex-invoice-totals.repository.ts`;
71
+ const readModel = (name, source, expected) => ({
72
+ ruleId: RULE,
73
+ name: `read model store ${name}`,
74
+ expect: expected,
75
+ files: project({ [READ_MODEL]: source }, tenancy('knex')),
76
+ });
77
+ export const TENANCY_FIXTURES = [
78
+ {
79
+ ruleId: RULE,
80
+ name: 'a knex adapter reaching tenant data through the helpers',
81
+ expect: 'pass',
82
+ files: project({ [KNEX_ADAPTER]: KNEX_SCOPED }, tenancy('knex')),
83
+ },
84
+ {
85
+ ruleId: RULE,
86
+ name: 'a knex table reached straight from the executor on shared tables',
87
+ expect: { file: KNEX_ADAPTER },
88
+ files: project({ [KNEX_ADAPTER]: KNEX_UNSCOPED }, tenancy('knex')),
89
+ },
90
+ {
91
+ ruleId: RULE,
92
+ name: 'a knex executor handed to a helper, which confines it',
93
+ expect: 'pass',
94
+ files: project({
95
+ [KNEX_ADAPTER]: 'export class KnexInvoiceRepository {\n insert(row: Row) {\n return insertIgnoringConflict(this.database.executor(), ownTenantTable(this.database, this.scope, T), { row });\n }\n}\n',
96
+ }, tenancy('knex')),
97
+ },
98
+ bypass('knex', 'a table reached by from()', "return this.database.executor().from('invoices');"),
99
+ bypass('knex', 'a select chained on the executor', "return this.database.executor().select('id').from('invoices');"),
100
+ bypass('knex', 'a table reached by table()', "return this.database.executor().table('invoices');"),
101
+ bypass('knex', 'raw SQL', "return this.database.executor().raw('select * from invoices');"),
102
+ bypass('knex', 'the executor held in a variable', "const db = this.database.executor();\n\n return db('invoices');"),
103
+ {
104
+ ruleId: RULE,
105
+ name: 'a drizzle adapter that writes no tenant condition',
106
+ expect: { file: DRIZZLE_ADAPTER },
107
+ files: project({ [DRIZZLE_ADAPTER]: DRIZZLE_UNSCOPED }, tenancy('drizzle')),
108
+ },
109
+ {
110
+ ruleId: RULE,
111
+ name: 'a drizzle adapter with its tenant condition in every statement',
112
+ expect: 'pass',
113
+ files: project({ [DRIZZLE_ADAPTER]: DRIZZLE_SCOPED }, tenancy('drizzle')),
114
+ },
115
+ {
116
+ ruleId: RULE,
117
+ name: 'drizzle: one statement without a condition, in an adapter that writes one elsewhere',
118
+ expect: { file: DRIZZLE_ADAPTER },
119
+ files: project({
120
+ [DRIZZLE_ADAPTER]: DRIZZLE_SCOPED.replace(' remove(id: string) {', ' all() {\n return this.database.executor().select().from(invoices);\n }\n\n remove(id: string) {'),
121
+ }, tenancy('drizzle')),
122
+ },
123
+ bypass('drizzle', 'an insert that names no tenant', 'return this.database.executor().insert(invoices).values(state);'),
124
+ bypass('drizzle', 'a relational query', 'return this.database.executor().query.invoices.findMany();'),
125
+ bypass('drizzle', 'raw SQL', 'return this.database.executor().execute(sql`select * from invoices`);'),
126
+ readModel('built without its tenant', 'export class KnexInvoiceTotals extends KnexReadModelStore<Total> {\n constructor(context: KnexContext) {\n super(context, { table: TABLE });\n }\n}\n', { file: READ_MODEL }),
127
+ readModel('built with new and without its tenant', 'export class KnexInvoiceTotals {\n private readonly rows = new KnexReadModelTable<Total>(this.context, { table: TABLE });\n\n constructor(private readonly context: KnexContext) {}\n}\n', { file: READ_MODEL }),
128
+ readModel('built with its tenant', 'export class KnexInvoiceTotals extends KnexReadModelStore<Total> {\n constructor(context: KnexContext, scope: ExecutionScope) {\n super(context, { table: TABLE, tenant: scope });\n }\n}\n', 'pass'),
129
+ {
130
+ ruleId: RULE,
131
+ name: 'a project of one customer, which says nothing of tenancy',
132
+ expect: 'pass',
133
+ files: project({ [KNEX_ADAPTER]: KNEX_UNSCOPED }, { [CONFIG_FILE]: config({ stack: { orm: 'knex' } }) }),
134
+ },
135
+ ];
136
+ //# sourceMappingURL=tenancy-fixtures.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tenancy-fixtures.js","sourceRoot":"","sources":["../../../src/check/fixtures/tenancy-fixtures.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,MAAM,IAAI,GAAG,0B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AAM,CAAC,EAAE,KAAK,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC;KACzG;CACF,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Rule } from '../model/rule.js';
2
+ export declare const tenancyScopedStatement: Rule;
3
+ //# sourceMappingURL=tenancy-scoped-statement.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tenancy-scoped-statement.d.ts","sourceRoot":"","sources":["../../../src/check/rules/tenancy-scoped-statement.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAa7C,eAAO,MAAM,sBAAsB,EAAE,IAcpC,CAAC"}
@@ -0,0 +1,37 @@
1
+ import { inLayers } from '../support/in-layers.js';
2
+ import { perFile } from '../support/per-file.js';
3
+ import { drizzleUnscoped } from '../tenancy/drizzle-unscoped.js';
4
+ import { knexUnscoped } from '../tenancy/knex-unscoped.js';
5
+ import { unscopedReadModels } from '../tenancy/unscoped-read-models.js';
6
+ const FIX = 'Reach tenant data through the helpers of the ORM package: `tenantTable` to read and `ownTenantTable` to write (Knex), `tenantCondition` and `ownTenantCondition` in the where of each statement and `tenantScopeOf` in each inserted row (Drizzle), the `tenant` option of a read model store. A table that holds no tenant data is a deviation: `// ddd-ts-kit-disable-next-line tenancy/scoped-statement -- ADR-NNNN: <why>`.';
7
+ const READ_MODEL = 'A read model store is built without the `tenant` option: its rows are shared by every tenant.';
8
+ export const tenancyScopedStatement = {
9
+ id: 'tenancy/scoped-statement',
10
+ description: 'In a multi-tenant project ("stack.tenancy" other than "none"), a persistence adapter of a context confines every statement to the tenant of the work through the helpers of its ORM package: never the executor used straight, raw SQL, a relational query, or a read model store without its tenant.',
11
+ scope: 'file',
12
+ run(project) {
13
+ const { tenancy, orm } = project.config.stack;
14
+ if (tenancy === 'none') {
15
+ return [];
16
+ }
17
+ return perFile(project, this.id, (file) => (isAdapter(file) ? unscoped(file, orm) : []));
18
+ },
19
+ };
20
+ /** The persistence code of a context: its infrastructure, tests and fakes left out. */
21
+ function isAdapter(file) {
22
+ return !file.isTest && inLayers(file, ['infrastructure']) !== undefined;
23
+ }
24
+ const STATEMENTS = {
25
+ knex: knexUnscoped,
26
+ drizzle: drizzleUnscoped,
27
+ };
28
+ function unscoped(file, orm) {
29
+ const statements = STATEMENTS[orm]?.(file) ?? [];
30
+ const readModels = unscopedReadModels(file).map((offset) => ({ offset, message: READ_MODEL }));
31
+ return [...statements, ...readModels].map(({ offset, message }) => ({
32
+ line: file.scan.lineAt(offset),
33
+ message,
34
+ fix: FIX,
35
+ }));
36
+ }
37
+ //# sourceMappingURL=tenancy-scoped-statement.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tenancy-scoped-statement.js","sourceRoot":"","sources":["../../../src/check/rules/tenancy-scoped-statement.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AAExE,MAAM,GAAG,GACP,iaAAia,CAAC;AAEpa,MAAM,UAAU,GAAG,+FAA+F,CAAC;AAEnH,MAAM,CAAC,MAAM,sBAAsB,GAAS;IAC1C,EAAE,EAAE,0BAA0B;IAC9B,WAAW,EACT,uSAAuS;IACzS,KAAK,EAAE,MAAM;IACb,GAAG,CAAC,OAAO;QACT,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC;QAE9C,IAAI,OAAO,KAAK,MAAM,EAAE,CAAC;YACvB,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,OAAO,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC3F,CAAC;CACF,CAAC;AAEF,uFAAuF;AACvF,SAAS,SAAS,CAAC,IAAgB;IACjC,OAAO,CAAC,IAAI,CAAC,MAAM,IAAI,QAAQ,CAAC,IAAI,EAAE,CAAC,gBAAgB,CAAC,CAAC,KAAK,SAAS,CAAC;AAC1E,CAAC;AAED,MAAM,UAAU,GAAmG;IACjH,IAAI,EAAE,YAAY;IAClB,OAAO,EAAE,eAAe;CACzB,CAAC;AAEF,SAAS,QAAQ,CAAC,IAAgB,EAAE,GAAW;IAC7C,MAAM,UAAU,GAAG,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;IACjD,MAAM,UAAU,GAAG,kBAAkB,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC;IAE/F,OAAO,CAAC,GAAG,UAAU,EAAE,GAAG,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC;QAClE,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;QAC9B,OAAO;QACP,GAAG,EAAE,GAAG;KACT,CAAC,CAAC,CAAC;AACN,CAAC"}
@@ -0,0 +1,3 @@
1
+ /** The text between the parenthesis at `open` and the one that closes it, or the rest of the code when none does. */
2
+ export declare function balancedArguments(code: string, open: number): string;
3
+ //# sourceMappingURL=balanced-arguments.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"balanced-arguments.d.ts","sourceRoot":"","sources":["../../../src/check/tenancy/balanced-arguments.ts"],"names":[],"mappings":"AAEA,qHAAqH;AACrH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAYpE"}
@@ -0,0 +1,13 @@
1
+ const DEPTH = { '(': 1, ')': -1 };
2
+ /** The text between the parenthesis at `open` and the one that closes it, or the rest of the code when none does. */
3
+ export function balancedArguments(code, open) {
4
+ let depth = 0;
5
+ for (let index = open; index < code.length; index += 1) {
6
+ depth += DEPTH[code.charAt(index)] ?? 0;
7
+ if (depth === 0) {
8
+ return code.slice(open + 1, index);
9
+ }
10
+ }
11
+ return code.slice(open + 1);
12
+ }
13
+ //# sourceMappingURL=balanced-arguments.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"balanced-arguments.js","sourceRoot":"","sources":["../../../src/check/tenancy/balanced-arguments.ts"],"names":[],"mappings":"AAAA,MAAM,KAAK,GAAqC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC;AAEpE,qHAAqH;AACrH,MAAM,UAAU,iBAAiB,CAAC,IAAY,EAAE,IAAY;IAC1D,IAAI,KAAK,GAAG,CAAC,CAAC;IAEd,KAAK,IAAI,KAAK,GAAG,IAAI,EAAE,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;QACvD,KAAK,IAAI,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC;QAExC,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC;YAChB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC;QACrC,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC;AAC9B,CAAC"}
@@ -0,0 +1,11 @@
1
+ /** A call of a statement whose argument may be a local: `.where(mine)` in `.select().from(invoices).where(mine)`. */
2
+ export interface StatementCall {
3
+ readonly statement: string;
4
+ readonly method: string;
5
+ }
6
+ /**
7
+ * Whether the argument of `.<method>(<name>)` in a statement is a local declared with what
8
+ * `pattern` finds: `.where(mine)` after `const mine = and(eq(...), tenantCondition(...));`.
9
+ */
10
+ export declare function declaredWith(code: string, { statement, method }: StatementCall, pattern: RegExp): boolean;
11
+ //# sourceMappingURL=declared-with.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"declared-with.d.ts","sourceRoot":"","sources":["../../../src/check/tenancy/declared-with.ts"],"names":[],"mappings":"AAAA,qHAAqH;AACrH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAUzG"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Whether the argument of `.<method>(<name>)` in a statement is a local declared with what
3
+ * `pattern` finds: `.where(mine)` after `const mine = and(eq(...), tenantCondition(...));`.
4
+ */
5
+ export function declaredWith(code, { statement, method }, pattern) {
6
+ const argument = new RegExp(`\\.${method}\\s*\\(\\s*([A-Za-z_$][\\w$]*)\\s*\\)`).exec(statement)?.[1];
7
+ if (argument === undefined) {
8
+ return false;
9
+ }
10
+ const declaration = new RegExp(`(?:const|let)\\s+${argument.replaceAll('$', '\\$')}\\s*=([^;]*)`).exec(code);
11
+ return declaration?.[1] !== undefined && pattern.test(declaration[1]);
12
+ }
13
+ //# sourceMappingURL=declared-with.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"declared-with.js","sourceRoot":"","sources":["../../../src/check/tenancy/declared-with.ts"],"names":[],"mappings":"AAMA;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,IAAY,EAAE,EAAE,SAAS,EAAE,MAAM,EAAiB,EAAE,OAAe;IAC9F,MAAM,QAAQ,GAAG,IAAI,MAAM,CAAC,MAAM,MAAM,uCAAuC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAEtG,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,WAAW,GAAG,IAAI,MAAM,CAAC,oBAAoB,QAAQ,CAAC,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAE7G,OAAO,WAAW,EAAE,CAAC,CAAC,CAAC,KAAK,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;AACxE,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { SourceFile } from '../model/source-file.js';
2
+ /** What a Drizzle adapter of tenant data reaches without the helpers, judged statement by statement. */
3
+ export declare function drizzleUnscoped(file: SourceFile): readonly {
4
+ offset: number;
5
+ message: string;
6
+ }[];
7
+ //# sourceMappingURL=drizzle-unscoped.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"drizzle-unscoped.d.ts","sourceRoot":"","sources":["../../../src/check/tenancy/drizzle-unscoped.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAY1D,wGAAwG;AACxG,wBAAgB,eAAe,CAAC,IAAI,EAAE,UAAU,GAAG,SAAS;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,EAAE,CAQhG"}
@@ -0,0 +1,35 @@
1
+ import { declaredWith } from './declared-with.js';
2
+ import { executorUses } from './executor-uses.js';
3
+ /** What confines a read, an update or a delete to the tenant. */
4
+ const CONDITION = /(?<![\w$])(?:tenantCondition|ownTenantCondition)\s*\(/;
5
+ /** What names the tenant of an inserted row. */
6
+ const TENANT_OF_ROW = /(?<![\w$])tenantScopeOf\s*\(/;
7
+ const READ_OR_WRITE = /\.(?:select|selectDistinct|from|update|delete)\s*\(/;
8
+ /** What a Drizzle adapter of tenant data reaches without the helpers, judged statement by statement. */
9
+ export function drizzleUnscoped(file) {
10
+ const { code } = file.scan;
11
+ return executorUses(code).flatMap((use) => {
12
+ const message = use.handedOver ? undefined : unscopedStatement(code, use);
13
+ return message === undefined ? [] : [{ offset: use.offset, message }];
14
+ });
15
+ }
16
+ function unscopedStatement(code, { statement }) {
17
+ if (/\.query\s*\./.test(statement)) {
18
+ return 'A relational query (executor().query) cannot carry the tenant condition: write it with select().';
19
+ }
20
+ if (/\.execute\s*\(/.test(statement)) {
21
+ return 'Raw SQL (execute) reaches the tables with no tenant condition.';
22
+ }
23
+ if (/\.insert\s*\(/.test(statement)) {
24
+ return TENANT_OF_ROW.test(statement) || declaredWith(code, { statement, method: 'values' }, TENANT_OF_ROW)
25
+ ? undefined
26
+ : 'An insert names no tenant: spread tenantScopeOf(this.scope) into the row it writes.';
27
+ }
28
+ if (READ_OR_WRITE.test(statement)) {
29
+ return CONDITION.test(statement) || declaredWith(code, { statement, method: 'where' }, CONDITION)
30
+ ? undefined
31
+ : 'A statement reaches a table with no tenant condition in its where.';
32
+ }
33
+ return 'The executor is used other than through a statement this rule can judge (held in a variable, a transaction).';
34
+ }
35
+ //# sourceMappingURL=drizzle-unscoped.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"drizzle-unscoped.js","sourceRoot":"","sources":["../../../src/check/tenancy/drizzle-unscoped.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAoB,MAAM,oBAAoB,CAAC;AAEpE,iEAAiE;AACjE,MAAM,SAAS,GAAG,uDAAuD,CAAC;AAE1E,gDAAgD;AAChD,MAAM,aAAa,GAAG,8BAA8B,CAAC;AAErD,MAA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E,EAAE,SAAS,CAAC;YAC/F,CAAC,CAAC,SAAS;YACX,CAAC,CAAC,oEAAoE,CAAC;IAC3E,CAAC;IAED,OAAO,8GAA8G,CAAC;AACxH,CAAC"}
@@ -0,0 +1,11 @@
1
+ /** Where an adapter reaches its executor: `.executor()`, with what follows it up to the end of the statement. */
2
+ export interface ExecutorUse {
3
+ readonly offset: number;
4
+ /** The executor is handed to a helper (`insertIgnoringConflict(this.database.executor(), ...)`): the helper confines it. */
5
+ readonly handedOver: boolean;
6
+ /** What follows `.executor()` up to the end of its statement: `.select().from(invoices).where(mine)`. */
7
+ readonly statement: string;
8
+ }
9
+ /** Every use of the executor in a source whose literals and comments are blanked. */
10
+ export declare function executorUses(code: string): readonly ExecutorUse[];
11
+ //# sourceMappingURL=executor-uses.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executor-uses.d.ts","sourceRoot":"","sources":["../../../src/check/tenancy/executor-uses.ts"],"names":[],"mappings":"AAAA,iHAAiH;AACjH,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,4HAA4H;IAC5H,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B,yGAAyG;IACzG,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAID,qFAAqF;AACrF,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,WAAW,EAAE,CAWjE"}
@@ -0,0 +1,14 @@
1
+ const EXECUTOR = /\.executor\s*\(\s*\)/g;
2
+ /** Every use of the executor in a source whose literals and comments are blanked. */
3
+ export function executorUses(code) {
4
+ return [...code.matchAll(EXECUTOR)].map((match) => {
5
+ const after = match.index + match[0].length;
6
+ const end = code.indexOf(';', after);
7
+ return {
8
+ offset: match.index,
9
+ handedOver: /^\s*[,)]/.test(code.slice(after)),
10
+ statement: code.slice(after, end === -1 ? code.length : end),
11
+ };
12
+ });
13
+ }
14
+ //# sourceMappingURL=executor-uses.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executor-uses.js","sourceRoot":"","sources":["../../../src/check/tenancy/executor-uses.ts"],"names":[],"mappings":"AASA,MAAM,QAAQ,GAAG,uBAAuB,CAAC;AAEzC,qFAAqF;AACrF,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,OAAO,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;QAChD,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;QAC5C,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAErC,OAAO;YACL,MAAM,EAAE,KAAK,CAAC,KAAK;YACnB,UAAU,EAAE,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YAC9C,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC;SAC7D,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { SourceFile } from '../model/source-file.js';
2
+ /** What a Knex adapter of tenant data reaches without the helpers: the executor called, chained or held, and raw SQL. */
3
+ export declare function knexUnscoped(file: SourceFile): readonly {
4
+ offset: number;
5
+ message: string;
6
+ }[];
7
+ //# sourceMappingURL=knex-unscoped.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"knex-unscoped.d.ts","sourceRoot":"","sources":["../../../src/check/tenancy/knex-unscoped.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAM1D,yHAAyH;AACzH,wBAAgB,YAAY,CAAC,IAAI,EAAE,UAAU,GAAG,SAAS;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,EAAE,CAgB7F"}
@@ -0,0 +1,19 @@
1
+ import { executorUses } from './executor-uses.js';
2
+ /** Raw SQL, which no helper confines. */
3
+ const RAW = /\.raw\s*\(/g;
4
+ /** What a Knex adapter of tenant data reaches without the helpers: the executor called, chained or held, and raw SQL. */
5
+ export function knexUnscoped(file) {
6
+ const { code } = file.scan;
7
+ const straight = executorUses(code)
8
+ .filter((use) => !use.handedOver)
9
+ .map((use) => ({
10
+ offset: use.offset,
11
+ message: 'The executor is used straight (called, chained or held): no tenant condition confines it.',
12
+ }));
13
+ const raw = [...code.matchAll(RAW)].map((match) => ({
14
+ offset: match.index,
15
+ message: 'Raw SQL reaches the tables with no tenant condition.',
16
+ }));
17
+ return [...straight, ...raw];
18
+ }
19
+ //# sourceMappingURL=knex-unscoped.js.map