@c15t/backend 1.0.5 → 1.2.0-canary.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.
- package/.turbo/turbo-build.log +33 -39
- package/.turbo/turbo-fmt.log +3 -3
- package/.turbo/turbo-test.log +531 -0
- package/coverage/coverage-final.json +84 -0
- package/coverage/coverage-summary.json +85 -0
- package/coverage/html/backend/index.html +116 -0
- package/coverage/html/backend/rslib.config.ts.html +415 -0
- package/coverage/html/backend/src/contracts/consent/index.html +161 -0
- package/coverage/html/backend/src/contracts/consent/index.ts.html +112 -0
- package/coverage/html/backend/src/contracts/consent/post.contract.ts.html +559 -0
- package/coverage/html/backend/src/contracts/consent/show-banner.contract.ts.html +220 -0
- package/coverage/html/backend/src/contracts/consent/verify.contract.ts.html +463 -0
- package/coverage/html/backend/src/contracts/index.html +116 -0
- package/coverage/html/backend/src/contracts/index.ts.html +139 -0
- package/coverage/html/backend/src/contracts/meta/index.html +131 -0
- package/coverage/html/backend/src/contracts/meta/index.ts.html +100 -0
- package/coverage/html/backend/src/contracts/meta/status.contract.ts.html +196 -0
- package/coverage/html/backend/src/contracts/shared/index.html +116 -0
- package/coverage/html/backend/src/contracts/shared/jurisdiction.schema.ts.html +175 -0
- package/coverage/html/backend/src/core.ts.html +1624 -0
- package/coverage/html/backend/src/handlers/consent/index.html +161 -0
- package/coverage/html/backend/src/handlers/consent/index.ts.html +112 -0
- package/coverage/html/backend/src/handlers/consent/post.handler.ts.html +889 -0
- package/coverage/html/backend/src/handlers/consent/show-banner.handler.ts.html +535 -0
- package/coverage/html/backend/src/handlers/consent/verify.handler.ts.html +1000 -0
- package/coverage/html/backend/src/handlers/meta/index.html +131 -0
- package/coverage/html/backend/src/handlers/meta/index.ts.html +100 -0
- package/coverage/html/backend/src/handlers/meta/status.handler.ts.html +226 -0
- package/coverage/html/backend/src/index.html +161 -0
- package/coverage/html/backend/src/init.ts.html +1018 -0
- package/coverage/html/backend/src/pkgs/api-router/hooks/index.html +116 -0
- package/coverage/html/backend/src/pkgs/api-router/hooks/processor.ts.html +544 -0
- package/coverage/html/backend/src/pkgs/api-router/index.html +116 -0
- package/coverage/html/backend/src/pkgs/api-router/telemetry.ts.html +334 -0
- package/coverage/html/backend/src/pkgs/api-router/utils/cors.ts.html +304 -0
- package/coverage/html/backend/src/pkgs/api-router/utils/index.html +131 -0
- package/coverage/html/backend/src/pkgs/api-router/utils/ip.ts.html +361 -0
- package/coverage/html/backend/src/pkgs/data-model/fields/field-factory.ts.html +709 -0
- package/coverage/html/backend/src/pkgs/data-model/fields/id-generator.ts.html +256 -0
- package/coverage/html/backend/src/pkgs/data-model/fields/index.html +161 -0
- package/coverage/html/backend/src/pkgs/data-model/fields/superjson-utils.ts.html +136 -0
- package/coverage/html/backend/src/pkgs/data-model/fields/zod-fields.ts.html +496 -0
- package/coverage/html/backend/src/pkgs/data-model/hooks/create-hooks.ts.html +349 -0
- package/coverage/html/backend/src/pkgs/data-model/hooks/index.html +176 -0
- package/coverage/html/backend/src/pkgs/data-model/hooks/update-hooks.ts.html +358 -0
- package/coverage/html/backend/src/pkgs/data-model/hooks/update-many-hooks.ts.html +613 -0
- package/coverage/html/backend/src/pkgs/data-model/hooks/utils.ts.html +538 -0
- package/coverage/html/backend/src/pkgs/data-model/hooks/with-hooks-factory.ts.html +289 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapter-factory.ts.html +289 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/drizzle-adapter/drizzle-adapter.ts.html +2203 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/drizzle-adapter/index.html +116 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/index.html +116 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/kysely-adapter/dialect.ts.html +670 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/kysely-adapter/index.html +131 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/kysely-adapter/kysely-adapter.ts.html +3634 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/kysely-adapter/tests/index.html +116 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/kysely-adapter/tests/test-utils.ts.html +1417 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/memory-adapter/index.html +116 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/memory-adapter/memory-adapter.ts.html +2071 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/prisma-adapter/index.html +116 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/prisma-adapter/prisma-adapter.ts.html +1834 -0
- package/coverage/html/backend/src/pkgs/db-adapters/adapters/test.ts.html +316 -0
- package/coverage/html/backend/src/pkgs/db-adapters/index.html +131 -0
- package/coverage/html/backend/src/pkgs/db-adapters/utils.ts.html +238 -0
- package/coverage/html/backend/src/pkgs/migrations/get-migration.ts.html +343 -0
- package/coverage/html/backend/src/pkgs/migrations/get-schema/get-schema.ts.html +217 -0
- package/coverage/html/backend/src/pkgs/migrations/get-schema/index.html +146 -0
- package/coverage/html/backend/src/pkgs/migrations/get-schema/process-fields.ts.html +280 -0
- package/coverage/html/backend/src/pkgs/migrations/get-schema/process-tables.ts.html +289 -0
- package/coverage/html/backend/src/pkgs/migrations/index.html +176 -0
- package/coverage/html/backend/src/pkgs/migrations/migration-builders.ts.html +595 -0
- package/coverage/html/backend/src/pkgs/migrations/migration-execution.ts.html +301 -0
- package/coverage/html/backend/src/pkgs/migrations/schema-comparison.ts.html +694 -0
- package/coverage/html/backend/src/pkgs/migrations/type-mapping.ts.html +817 -0
- package/coverage/html/backend/src/pkgs/results/core/error-class.ts.html +976 -0
- package/coverage/html/backend/src/pkgs/results/core/error-codes.ts.html +703 -0
- package/coverage/html/backend/src/pkgs/results/core/index.html +146 -0
- package/coverage/html/backend/src/pkgs/results/core/tracing.ts.html +280 -0
- package/coverage/html/backend/src/pkgs/results/create-telemetry-options.ts.html +271 -0
- package/coverage/html/backend/src/pkgs/results/index.html +131 -0
- package/coverage/html/backend/src/pkgs/results/orpc-error-handler.ts.html +496 -0
- package/coverage/html/backend/src/pkgs/results/results/index.html +131 -0
- package/coverage/html/backend/src/pkgs/results/results/recovery-utils.ts.html +628 -0
- package/coverage/html/backend/src/pkgs/results/results/result-helpers.ts.html +1234 -0
- package/coverage/html/backend/src/pkgs/utils/env.ts.html +337 -0
- package/coverage/html/backend/src/pkgs/utils/index.html +146 -0
- package/coverage/html/backend/src/pkgs/utils/logger.ts.html +199 -0
- package/coverage/html/backend/src/pkgs/utils/url.ts.html +400 -0
- package/coverage/html/backend/src/router.ts.html +109 -0
- package/coverage/html/backend/src/schema/audit-log/index.html +146 -0
- package/coverage/html/backend/src/schema/audit-log/registry.ts.html +436 -0
- package/coverage/html/backend/src/schema/audit-log/schema.ts.html +223 -0
- package/coverage/html/backend/src/schema/audit-log/table.ts.html +640 -0
- package/coverage/html/backend/src/schema/consent/index.html +146 -0
- package/coverage/html/backend/src/schema/consent/registry.ts.html +616 -0
- package/coverage/html/backend/src/schema/consent/schema.ts.html +238 -0
- package/coverage/html/backend/src/schema/consent/table.ts.html +748 -0
- package/coverage/html/backend/src/schema/consent-policy/index.html +146 -0
- package/coverage/html/backend/src/schema/consent-policy/registry.ts.html +1063 -0
- package/coverage/html/backend/src/schema/consent-policy/schema.ts.html +265 -0
- package/coverage/html/backend/src/schema/consent-policy/table.ts.html +535 -0
- package/coverage/html/backend/src/schema/consent-purpose/index.html +146 -0
- package/coverage/html/backend/src/schema/consent-purpose/registry.ts.html +589 -0
- package/coverage/html/backend/src/schema/consent-purpose/schema.ts.html +259 -0
- package/coverage/html/backend/src/schema/consent-purpose/table.ts.html +547 -0
- package/coverage/html/backend/src/schema/consent-record/index.html +131 -0
- package/coverage/html/backend/src/schema/consent-record/schema.ts.html +211 -0
- package/coverage/html/backend/src/schema/consent-record/table.ts.html +457 -0
- package/coverage/html/backend/src/schema/create-registry.ts.html +148 -0
- package/coverage/html/backend/src/schema/definition.ts.html +685 -0
- package/coverage/html/backend/src/schema/domain/index.html +146 -0
- package/coverage/html/backend/src/schema/domain/registry.ts.html +973 -0
- package/coverage/html/backend/src/schema/domain/schema.ts.html +214 -0
- package/coverage/html/backend/src/schema/domain/table.ts.html +496 -0
- package/coverage/html/backend/src/schema/index.html +146 -0
- package/coverage/html/backend/src/schema/schemas.ts.html +166 -0
- package/coverage/html/backend/src/schema/subject/index.html +146 -0
- package/coverage/html/backend/src/schema/subject/registry.ts.html +973 -0
- package/coverage/html/backend/src/schema/subject/schema.ts.html +208 -0
- package/coverage/html/backend/src/schema/subject/table.ts.html +499 -0
- package/coverage/html/backend/src/server.ts.html +475 -0
- package/coverage/html/backend/src/testing/contract-testing.ts.html +1348 -0
- package/coverage/html/backend/src/testing/index.html +116 -0
- package/coverage/html/base.css +224 -0
- package/coverage/html/block-navigation.js +87 -0
- package/coverage/html/favicon.png +0 -0
- package/coverage/html/index.html +626 -0
- package/coverage/html/prettify.css +1 -0
- package/coverage/html/prettify.js +2 -0
- package/coverage/html/sort-arrow-sprite.png +0 -0
- package/coverage/html/sorter.js +196 -0
- package/dist/contracts/consent/index.d.ts +401 -0
- package/dist/contracts/consent/index.d.ts.map +1 -0
- package/dist/contracts/consent/index.test.d.ts +2 -0
- package/dist/contracts/consent/index.test.d.ts.map +1 -0
- package/dist/contracts/consent/post.contract.d.ts +212 -0
- package/dist/contracts/consent/post.contract.d.ts.map +1 -0
- package/dist/contracts/consent/post.contract.test.d.ts +2 -0
- package/dist/contracts/consent/post.contract.test.d.ts.map +1 -0
- package/dist/contracts/consent/show-banner.contract.d.ts +45 -0
- package/dist/contracts/consent/show-banner.contract.d.ts.map +1 -0
- package/dist/contracts/consent/show-banner.contract.test.d.ts +2 -0
- package/dist/contracts/consent/show-banner.contract.test.d.ts.map +1 -0
- package/dist/contracts/consent/verify.contract.d.ts +147 -0
- package/dist/contracts/consent/verify.contract.d.ts.map +1 -0
- package/dist/contracts/consent/verify.contract.test.d.ts +2 -0
- package/dist/contracts/consent/verify.contract.test.d.ts.map +1 -0
- package/dist/contracts/index.d.ts +963 -0
- package/dist/contracts/index.d.ts.map +1 -0
- package/dist/contracts/meta/index.d.ts +78 -0
- package/dist/contracts/meta/index.d.ts.map +1 -0
- package/dist/contracts/meta/index.test.d.ts +2 -0
- package/dist/contracts/meta/index.test.d.ts.map +1 -0
- package/dist/contracts/meta/status.contract.d.ts +77 -0
- package/dist/contracts/meta/status.contract.d.ts.map +1 -0
- package/dist/contracts/meta/status.contract.test.d.ts +2 -0
- package/dist/contracts/meta/status.contract.test.d.ts.map +1 -0
- package/dist/contracts/shared/jurisdiction.schema.d.ts +24 -0
- package/dist/contracts/shared/jurisdiction.schema.d.ts.map +1 -0
- package/dist/core.cjs +3584 -0
- package/dist/core.d.ts +533 -76
- package/dist/core.d.ts.map +1 -1
- package/dist/{index.js → core.js} +1163 -1286
- package/dist/handlers/consent/index.d.ts +401 -0
- package/dist/handlers/consent/index.d.ts.map +1 -0
- package/dist/handlers/consent/post.handler.d.ts +234 -0
- package/dist/handlers/consent/post.handler.d.ts.map +1 -0
- package/dist/handlers/consent/show-banner.handler.d.ts +57 -0
- package/dist/handlers/consent/show-banner.handler.d.ts.map +1 -0
- package/dist/handlers/consent/show-banner.handler.test.d.ts +2 -0
- package/dist/handlers/consent/show-banner.handler.test.d.ts.map +1 -0
- package/dist/handlers/consent/verify.handler.d.ts +169 -0
- package/dist/handlers/consent/verify.handler.d.ts.map +1 -0
- package/dist/handlers/meta/index.d.ts +78 -0
- package/dist/handlers/meta/index.d.ts.map +1 -0
- package/dist/handlers/meta/status.handler.d.ts +76 -0
- package/dist/handlers/meta/status.handler.d.ts.map +1 -0
- package/dist/init.d.ts.map +1 -1
- package/dist/pkgs/api-router/hooks/processor.d.ts.map +1 -1
- package/dist/pkgs/api-router/types/router-props.d.ts +1 -1
- package/dist/pkgs/api-router/types/router-props.d.ts.map +1 -1
- package/dist/pkgs/api-router/utils/cors.d.ts +1 -1
- package/dist/pkgs/api-router/utils/cors.d.ts.map +1 -1
- package/dist/pkgs/data-model/fields/field-types.d.ts +1 -1
- package/dist/pkgs/data-model/fields/zod-fields.d.ts +32 -32
- package/dist/pkgs/data-model/index.cjs +1433 -1799
- package/dist/pkgs/data-model/index.js +20 -385
- package/dist/pkgs/data-model/schema/index.cjs +1402 -1768
- package/dist/pkgs/data-model/schema/index.js +20 -385
- package/dist/pkgs/db-adapters/adapter-factory.d.ts +2 -2
- package/dist/pkgs/db-adapters/adapter-factory.d.ts.map +1 -1
- package/dist/pkgs/db-adapters/adapters/drizzle-adapter/drizzle-adapter.d.ts +4 -4
- package/dist/pkgs/db-adapters/adapters/drizzle-adapter/index.cjs +19 -151
- package/dist/pkgs/db-adapters/adapters/drizzle-adapter/index.js +19 -151
- package/dist/pkgs/db-adapters/adapters/kysely-adapter/dialect.d.ts +1 -1
- package/dist/pkgs/db-adapters/adapters/kysely-adapter/index.cjs +17 -149
- package/dist/pkgs/db-adapters/adapters/kysely-adapter/index.js +17 -149
- package/dist/pkgs/db-adapters/adapters/kysely-adapter/tests/test-utils.d.ts +2 -2
- package/dist/pkgs/db-adapters/adapters/kysely-adapter/tests/test-utils.d.ts.map +1 -1
- package/dist/pkgs/db-adapters/adapters/memory-adapter/index.cjs +17 -149
- package/dist/pkgs/db-adapters/adapters/memory-adapter/index.js +17 -149
- package/dist/pkgs/db-adapters/adapters/prisma-adapter/index.cjs +19 -151
- package/dist/pkgs/db-adapters/adapters/prisma-adapter/index.js +19 -151
- package/dist/pkgs/db-adapters/index.cjs +31 -153
- package/dist/pkgs/db-adapters/index.js +31 -153
- package/dist/pkgs/migrations/get-schema/get-schema.d.ts +2 -2
- package/dist/pkgs/migrations/get-schema/index.d.ts +1 -1
- package/dist/pkgs/migrations/index.cjs +30 -153
- package/dist/pkgs/migrations/index.js +30 -153
- package/dist/pkgs/migrations/schema-comparison.d.ts.map +1 -1
- package/dist/pkgs/results/core/error-class.d.ts +23 -21
- package/dist/pkgs/results/core/error-class.d.ts.map +1 -1
- package/dist/pkgs/results/index.cjs +17 -150
- package/dist/pkgs/results/index.d.ts +0 -3
- package/dist/pkgs/results/index.d.ts.map +1 -1
- package/dist/pkgs/results/index.js +17 -138
- package/dist/pkgs/results/orpc-error-handler.d.ts +65 -0
- package/dist/pkgs/results/orpc-error-handler.d.ts.map +1 -0
- package/dist/pkgs/results/types.d.ts +7 -7
- package/dist/pkgs/results/types.d.ts.map +1 -1
- package/dist/pkgs/types/context.d.ts +15 -4
- package/dist/pkgs/types/context.d.ts.map +1 -1
- package/dist/pkgs/types/endpoints.d.ts +3 -4
- package/dist/pkgs/types/endpoints.d.ts.map +1 -1
- package/dist/pkgs/types/options.d.ts +2 -3
- package/dist/pkgs/types/options.d.ts.map +1 -1
- package/dist/pkgs/types/plugins.d.ts +2 -3
- package/dist/pkgs/types/plugins.d.ts.map +1 -1
- package/dist/pkgs/utils/index.d.ts +1 -0
- package/dist/pkgs/utils/index.d.ts.map +1 -1
- package/dist/pkgs/utils/logger.d.ts +16 -0
- package/dist/pkgs/utils/logger.d.ts.map +1 -0
- package/dist/router.cjs +1213 -0
- package/dist/router.d.ts +480 -0
- package/dist/router.d.ts.map +1 -0
- package/dist/router.js +1169 -0
- package/dist/schema/audit-log/table.d.ts +1 -1
- package/dist/schema/consent/table.d.ts +1 -1
- package/dist/schema/consent-policy/registry.d.ts +12 -12
- package/dist/schema/consent-policy/schema.d.ts +6 -6
- package/dist/schema/consent-policy/table.d.ts +7 -7
- package/dist/schema/consent-purpose/registry.d.ts +6 -6
- package/dist/schema/consent-purpose/schema.d.ts +6 -6
- package/dist/schema/consent-purpose/table.d.ts +7 -7
- package/dist/schema/consent-record/table.d.ts +1 -1
- package/dist/schema/create-registry.d.ts +32 -32
- package/dist/schema/definition.d.ts +19 -19
- package/dist/schema/domain/registry.d.ts +10 -10
- package/dist/schema/domain/schema.d.ts +5 -5
- package/dist/schema/domain/table.d.ts +6 -6
- package/dist/schema/index.cjs +1409 -1775
- package/dist/schema/index.js +20 -385
- package/dist/schema/schemas.d.ts +19 -19
- package/dist/schema/subject/registry.d.ts +4 -4
- package/dist/schema/subject/schema.d.ts +2 -2
- package/dist/schema/subject/table.d.ts +3 -3
- package/dist/server.d.ts +2 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/testing/contract-testing.d.ts +37 -0
- package/dist/testing/contract-testing.d.ts.map +1 -0
- package/dist/types/context.d.ts +1 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/options.d.ts +33 -2
- package/dist/types/options.d.ts.map +1 -1
- package/dist/types/plugins.d.ts +3 -4
- package/dist/types/plugins.d.ts.map +1 -1
- package/package.json +22 -30
- package/rslib.config.ts +2 -5
- package/src/contracts/consent/index.test.ts +5 -0
- package/src/contracts/consent/index.ts +9 -0
- package/src/contracts/consent/post.contract.test.ts +526 -0
- package/src/contracts/consent/post.contract.ts +160 -0
- package/src/contracts/consent/show-banner.contract.test.ts +214 -0
- package/src/contracts/consent/show-banner.contract.ts +45 -0
- package/src/contracts/consent/verify.contract.test.ts +185 -0
- package/src/contracts/consent/verify.contract.ts +126 -0
- package/src/contracts/index.ts +18 -0
- package/src/contracts/meta/index.test.ts +5 -0
- package/src/contracts/meta/index.ts +5 -0
- package/src/contracts/meta/status.contract.test.ts +338 -0
- package/src/contracts/meta/status.contract.ts +37 -0
- package/src/contracts/shared/jurisdiction.schema.ts +30 -0
- package/src/core.ts +451 -159
- package/src/handlers/consent/index.ts +9 -0
- package/src/handlers/consent/post.handler.ts +273 -0
- package/src/handlers/consent/show-banner.handler.test.ts +148 -0
- package/src/handlers/consent/show-banner.handler.ts +150 -0
- package/src/handlers/consent/verify.handler.ts +305 -0
- package/src/handlers/meta/index.ts +5 -0
- package/src/handlers/meta/status.handler.ts +47 -0
- package/src/init.ts +8 -5
- package/src/pkgs/api-router/hooks/__tests__/processor.test.ts +6 -0
- package/src/pkgs/api-router/hooks/processor.ts +2 -0
- package/src/pkgs/api-router/types/router-props.ts +1 -1
- package/src/pkgs/api-router/utils/cors.ts +1 -1
- package/src/pkgs/data-model/fields/field-types.ts +1 -1
- package/src/pkgs/data-model/fields/id-generator.ts +1 -1
- package/src/pkgs/db-adapters/README.md +3 -3
- package/src/pkgs/db-adapters/adapter-factory.ts +8 -4
- package/src/pkgs/db-adapters/adapters/drizzle-adapter/drizzle-adapter.ts +13 -13
- package/src/pkgs/db-adapters/adapters/kysely-adapter/dialect.ts +1 -1
- package/src/pkgs/db-adapters/adapters/kysely-adapter/tests/postgres.test.ts +1 -1
- package/src/pkgs/db-adapters/adapters/kysely-adapter/tests/sqlite.test.ts +1 -1
- package/src/pkgs/db-adapters/adapters/kysely-adapter/tests/test-utils.ts +2 -2
- package/src/pkgs/migrations/get-migration.ts +3 -3
- package/src/pkgs/migrations/get-schema/get-schema.ts +2 -2
- package/src/pkgs/migrations/get-schema/index.ts +1 -1
- package/src/pkgs/migrations/migration-builders.ts +2 -2
- package/src/pkgs/migrations/migration-execution.ts +2 -2
- package/src/pkgs/migrations/schema-comparison.ts +5 -4
- package/src/pkgs/results/__tests__/error-class.test.ts +8 -7
- package/src/pkgs/results/core/error-class.ts +31 -43
- package/src/pkgs/results/index.ts +0 -10
- package/src/pkgs/results/orpc-error-handler.ts +137 -0
- package/src/pkgs/results/types.ts +8 -7
- package/src/pkgs/types/context.ts +18 -4
- package/src/pkgs/types/endpoints.ts +3 -5
- package/src/pkgs/types/options.ts +2 -3
- package/src/pkgs/types/plugins.ts +2 -3
- package/src/pkgs/utils/index.ts +1 -0
- package/src/pkgs/utils/logger.ts +38 -0
- package/src/router.ts +8 -0
- package/src/schema/audit-log/table.ts +1 -1
- package/src/schema/consent/table.ts +1 -1
- package/src/schema/consent-policy/table.ts +1 -1
- package/src/schema/consent-purpose/table.ts +1 -1
- package/src/schema/consent-record/table.ts +1 -1
- package/src/schema/definition.ts +2 -2
- package/src/schema/domain/table.ts +1 -1
- package/src/schema/subject/table.ts +1 -1
- package/src/server.ts +130 -0
- package/src/testing/contract-testing.ts +437 -0
- package/src/types/context.ts +1 -1
- package/src/types/index.ts +2 -2
- package/src/types/options.ts +38 -2
- package/src/types/plugins.ts +3 -4
- package/dist/index.cjs +0 -3701
- package/dist/index.d.ts +0 -11
- package/dist/index.d.ts.map +0 -1
- package/dist/init.test.d.ts +0 -2
- package/dist/init.test.d.ts.map +0 -1
- package/dist/integrations/cloudflare.cjs +0 -312
- package/dist/integrations/cloudflare.d.ts +0 -32
- package/dist/integrations/cloudflare.d.ts.map +0 -1
- package/dist/integrations/cloudflare.js +0 -278
- package/dist/integrations/next.cjs +0 -276
- package/dist/integrations/next.d.ts +0 -68
- package/dist/integrations/next.d.ts.map +0 -1
- package/dist/integrations/next.js +0 -239
- package/dist/integrations/node.cjs +0 -257
- package/dist/integrations/node.d.ts +0 -29
- package/dist/integrations/node.d.ts.map +0 -1
- package/dist/integrations/node.js +0 -223
- package/dist/pkgs/api-router/index.d.ts +0 -9
- package/dist/pkgs/api-router/index.d.ts.map +0 -1
- package/dist/pkgs/api-router/utils/define-route.d.ts +0 -87
- package/dist/pkgs/api-router/utils/define-route.d.ts.map +0 -1
- package/dist/pkgs/logger/__tests__/console-formatter.test.d.ts +0 -2
- package/dist/pkgs/logger/__tests__/console-formatter.test.d.ts.map +0 -1
- package/dist/pkgs/logger/__tests__/integration.test.d.ts +0 -2
- package/dist/pkgs/logger/__tests__/integration.test.d.ts.map +0 -1
- package/dist/pkgs/logger/__tests__/log-levels.test.d.ts +0 -2
- package/dist/pkgs/logger/__tests__/log-levels.test.d.ts.map +0 -1
- package/dist/pkgs/logger/__tests__/logger-factory.test.d.ts +0 -2
- package/dist/pkgs/logger/__tests__/logger-factory.test.d.ts.map +0 -1
- package/dist/pkgs/logger/__tests__/result-logging.test.d.ts +0 -2
- package/dist/pkgs/logger/__tests__/result-logging.test.d.ts.map +0 -1
- package/dist/pkgs/logger/__tests__/types.test.d.ts +0 -2
- package/dist/pkgs/logger/__tests__/types.test.d.ts.map +0 -1
- package/dist/pkgs/logger/console-formatter.d.ts +0 -56
- package/dist/pkgs/logger/console-formatter.d.ts.map +0 -1
- package/dist/pkgs/logger/index.cjs +0 -240
- package/dist/pkgs/logger/index.d.ts +0 -35
- package/dist/pkgs/logger/index.d.ts.map +0 -1
- package/dist/pkgs/logger/index.js +0 -185
- package/dist/pkgs/logger/log-levels.d.ts +0 -29
- package/dist/pkgs/logger/log-levels.d.ts.map +0 -1
- package/dist/pkgs/logger/logger-factory.d.ts +0 -42
- package/dist/pkgs/logger/logger-factory.d.ts.map +0 -1
- package/dist/pkgs/logger/result-logging.d.ts +0 -71
- package/dist/pkgs/logger/result-logging.d.ts.map +0 -1
- package/dist/pkgs/logger/telemetry.d.ts +0 -14
- package/dist/pkgs/logger/telemetry.d.ts.map +0 -1
- package/dist/pkgs/logger/types.d.ts +0 -121
- package/dist/pkgs/logger/types.d.ts.map +0 -1
- package/dist/pkgs/results/__tests__/retrieval-pipeline.test.d.ts +0 -2
- package/dist/pkgs/results/__tests__/retrieval-pipeline.test.d.ts.map +0 -1
- package/dist/pkgs/results/__tests__/validation-pipeline.test.d.ts +0 -2
- package/dist/pkgs/results/__tests__/validation-pipeline.test.d.ts.map +0 -1
- package/dist/pkgs/results/h3-integration.d.ts +0 -52
- package/dist/pkgs/results/h3-integration.d.ts.map +0 -1
- package/dist/pkgs/results/pipeline/retrieval-pipeline.d.ts +0 -101
- package/dist/pkgs/results/pipeline/retrieval-pipeline.d.ts.map +0 -1
- package/dist/pkgs/results/pipeline/validation-pipeline.d.ts +0 -89
- package/dist/pkgs/results/pipeline/validation-pipeline.d.ts.map +0 -1
- package/dist/response-types.d.ts +0 -19
- package/dist/response-types.d.ts.map +0 -1
- package/dist/routes/__test__/index.test.d.ts +0 -17
- package/dist/routes/__test__/index.test.d.ts.map +0 -1
- package/dist/routes/__test__/set-consent.test.d.ts +0 -2
- package/dist/routes/__test__/set-consent.test.d.ts.map +0 -1
- package/dist/routes/__test__/show-consent-banner.test.d.ts +0 -2
- package/dist/routes/__test__/show-consent-banner.test.d.ts.map +0 -1
- package/dist/routes/__test__/status.test.d.ts +0 -2
- package/dist/routes/__test__/status.test.d.ts.map +0 -1
- package/dist/routes/__test__/verify-consent.test.d.ts +0 -2
- package/dist/routes/__test__/verify-consent.test.d.ts.map +0 -1
- package/dist/routes/index.d.ts +0 -3
- package/dist/routes/index.d.ts.map +0 -1
- package/dist/routes/set-consent.d.ts +0 -89
- package/dist/routes/set-consent.d.ts.map +0 -1
- package/dist/routes/show-consent-banner.d.ts +0 -15
- package/dist/routes/show-consent-banner.d.ts.map +0 -1
- package/dist/routes/status.d.ts +0 -44
- package/dist/routes/status.d.ts.map +0 -1
- package/dist/routes/types.d.ts +0 -7
- package/dist/routes/types.d.ts.map +0 -1
- package/dist/routes/verify-consent.d.ts +0 -38
- package/dist/routes/verify-consent.d.ts.map +0 -1
- package/src/docs/ADVANCED_JSON_HANDLING.md +0 -99
- package/src/docs/neverthrow.md +0 -171
- package/src/index.ts +0 -34
- package/src/init.test.ts +0 -219
- package/src/integrations/cloudflare.ts +0 -269
- package/src/integrations/next.ts +0 -204
- package/src/integrations/node.ts +0 -141
- package/src/pkgs/api-router/index.ts +0 -148
- package/src/pkgs/api-router/types/h3.d.ts +0 -42
- package/src/pkgs/api-router/utils/define-route.ts +0 -410
- package/src/pkgs/logger/README.md +0 -213
- package/src/pkgs/logger/__tests__/console-formatter.test.ts +0 -67
- package/src/pkgs/logger/__tests__/integration.test.ts +0 -184
- package/src/pkgs/logger/__tests__/log-levels.test.ts +0 -77
- package/src/pkgs/logger/__tests__/logger-factory.test.ts +0 -156
- package/src/pkgs/logger/__tests__/result-logging.test.ts +0 -209
- package/src/pkgs/logger/__tests__/types.test.ts +0 -94
- package/src/pkgs/logger/console-formatter.ts +0 -75
- package/src/pkgs/logger/doc.md +0 -569
- package/src/pkgs/logger/index.ts +0 -59
- package/src/pkgs/logger/log-levels.ts +0 -46
- package/src/pkgs/logger/logger-factory.ts +0 -121
- package/src/pkgs/logger/result-logging.ts +0 -134
- package/src/pkgs/logger/telemetry.ts +0 -96
- package/src/pkgs/logger/types.ts +0 -138
- package/src/pkgs/results/__tests__/retrieval-pipeline.test.ts +0 -157
- package/src/pkgs/results/__tests__/validation-pipeline.test.ts +0 -151
- package/src/pkgs/results/h3-integration.ts +0 -142
- package/src/pkgs/results/pipeline/retrieval-pipeline.ts +0 -188
- package/src/pkgs/results/pipeline/validation-pipeline.ts +0 -164
- package/src/plugins/.keep +0 -0
- package/src/response-types.ts +0 -29
- package/src/routes/__test__/index.test.ts +0 -112
- package/src/routes/__test__/set-consent.test.ts +0 -242
- package/src/routes/__test__/show-consent-banner.test.ts +0 -98
- package/src/routes/__test__/status.test.ts +0 -64
- package/src/routes/__test__/verify-consent.test.ts +0 -266
- package/src/routes/index.ts +0 -12
- package/src/routes/set-consent.ts +0 -249
- package/src/routes/show-consent-banner.ts +0 -131
- package/src/routes/status.ts +0 -61
- package/src/routes/types.ts +0 -7
- package/src/routes/verify-consent.ts +0 -206
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
# DoubleTie Logger
|
|
2
|
-
|
|
3
|
-
A lightweight, customizable logging utility for Node.js and TypeScript applications. It provides structured logging capabilities, Result pattern integration, and flexible configuration options.
|
|
4
|
-
|
|
5
|
-
## Features
|
|
6
|
-
|
|
7
|
-
- Configurable log levels (`info`, `success`, `warn`, `error`, `debug`)
|
|
8
|
-
- Color-coded console output for better readability
|
|
9
|
-
- Custom log handlers for integration with other logging systems
|
|
10
|
-
- Integration with Result pattern for error handling
|
|
11
|
-
- TypeScript support with comprehensive type definitions
|
|
12
|
-
- Customizable application name in log messages
|
|
13
|
-
|
|
14
|
-
## Installation
|
|
15
|
-
|
|
16
|
-
```bash
|
|
17
|
-
npm install @doubletie/logger
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
## Core Concepts
|
|
21
|
-
|
|
22
|
-
The logger provides a simple interface for outputting logs at different severity levels. The main interface is:
|
|
23
|
-
|
|
24
|
-
```typescript
|
|
25
|
-
interface Logger {
|
|
26
|
-
info(message: string, data?: object): void;
|
|
27
|
-
success(message: string, data?: object): void;
|
|
28
|
-
warn(message: string, data?: object): void;
|
|
29
|
-
error(message: string, data?: object): void;
|
|
30
|
-
debug(message: string, data?: object): void;
|
|
31
|
-
}
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
### Log Levels
|
|
35
|
-
|
|
36
|
-
Log levels are ordered by severity:
|
|
37
|
-
- `error` - Critical issues that require immediate attention
|
|
38
|
-
- `warn` - Potential problems that should be investigated
|
|
39
|
-
- `info` - General informational messages about system operation
|
|
40
|
-
- `success` - Successful operations (treated as info level in custom handlers)
|
|
41
|
-
- `debug` - Detailed information for debugging purposes
|
|
42
|
-
|
|
43
|
-
## Usage
|
|
44
|
-
|
|
45
|
-
### Creating a Logger
|
|
46
|
-
|
|
47
|
-
```typescript
|
|
48
|
-
import { createLogger } from '@doubletie/logger';
|
|
49
|
-
|
|
50
|
-
// Create a logger with default settings (only logs errors)
|
|
51
|
-
const logger = createLogger();
|
|
52
|
-
|
|
53
|
-
// Create a logger that logs all message types
|
|
54
|
-
const verboseLogger = createLogger({ level: 'debug' });
|
|
55
|
-
|
|
56
|
-
// Create a logger with a custom application name
|
|
57
|
-
const appLogger = createLogger({ appName: 'my-service' });
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
### Logging at Different Levels
|
|
61
|
-
|
|
62
|
-
```typescript
|
|
63
|
-
// Critical issues
|
|
64
|
-
logger.error('Failed to connect to database', { retryCount: 3, timeout: 5000 });
|
|
65
|
-
|
|
66
|
-
// Warnings about potential issues
|
|
67
|
-
logger.warn('Configuration missing, using defaults', { config: 'cache.json' });
|
|
68
|
-
|
|
69
|
-
// General information
|
|
70
|
-
logger.info('Application started', { environment: 'production', version: '1.2.3' });
|
|
71
|
-
|
|
72
|
-
// Success messages
|
|
73
|
-
logger.success('User registered successfully', { userId: 'user123' });
|
|
74
|
-
|
|
75
|
-
// Debug information
|
|
76
|
-
logger.debug('Processing request', { requestId: 'req-123', payload: { name: 'Test' } });
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
### Integration with Result Types
|
|
80
|
-
|
|
81
|
-
When working with Result types from libraries like [neverthrow](https://github.com/supermacro/neverthrow), you can use these utilities to log errors without disrupting the flow:
|
|
82
|
-
|
|
83
|
-
```typescript
|
|
84
|
-
import { logResult, logResultAsync } from '@doubletie/logger';
|
|
85
|
-
import { createLogger } from '@doubletie/logger';
|
|
86
|
-
import { ok, err, okAsync, errAsync } from 'neverthrow';
|
|
87
|
-
|
|
88
|
-
const logger = createLogger();
|
|
89
|
-
|
|
90
|
-
// Log errors from a Result without disrupting the Result flow
|
|
91
|
-
function processData(input: string) {
|
|
92
|
-
const result = validate(input); // Returns Result<ValidData, Error>
|
|
93
|
-
|
|
94
|
-
// Log any errors but continue with the Result
|
|
95
|
-
return logResult(result, logger, 'Validation error:');
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// Log errors from a ResultAsync
|
|
99
|
-
async function fetchData(url: string) {
|
|
100
|
-
const resultAsync = fetchAsync(url); // Returns ResultAsync<Response, Error>
|
|
101
|
-
|
|
102
|
-
// Log any errors but continue with the ResultAsync
|
|
103
|
-
return logResultAsync(resultAsync, logger, 'Fetch error:');
|
|
104
|
-
}
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
### Custom Log Handler
|
|
108
|
-
|
|
109
|
-
```typescript
|
|
110
|
-
import { createLogger } from '@doubletie/logger';
|
|
111
|
-
|
|
112
|
-
// Create a logger with a custom log handler
|
|
113
|
-
const logger = createLogger({
|
|
114
|
-
level: 'info',
|
|
115
|
-
log: (level, message, data) => {
|
|
116
|
-
// Send logs to a custom logging service
|
|
117
|
-
myLoggingService.send({
|
|
118
|
-
level,
|
|
119
|
-
message,
|
|
120
|
-
timestamp: new Date().toISOString(),
|
|
121
|
-
data: data || {},
|
|
122
|
-
});
|
|
123
|
-
},
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
logger.info('User logged in', { userId: 'user123' });
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
## API Reference
|
|
130
|
-
|
|
131
|
-
### Core Functions
|
|
132
|
-
|
|
133
|
-
#### `createLogger(options?: LoggerOptions | Logger): Logger`
|
|
134
|
-
|
|
135
|
-
Creates a configured logger instance with methods for each log level.
|
|
136
|
-
|
|
137
|
-
#### `isLogLevelEnabled(currentLogLevel: LogLevel, logLevel: LogLevel): boolean`
|
|
138
|
-
|
|
139
|
-
Determines if a log message should be published based on configured log level.
|
|
140
|
-
|
|
141
|
-
### Result Logging Functions
|
|
142
|
-
|
|
143
|
-
#### `logResult<T, E extends LoggableError>(result: Result<T, E>, logger, message?): Result<T, E>`
|
|
144
|
-
|
|
145
|
-
Logs any errors in a Result without changing the Result.
|
|
146
|
-
|
|
147
|
-
#### `logResultAsync<T, E extends LoggableError>(resultAsync: ResultAsync<T, E>, logger, message?): ResultAsync<T, E>`
|
|
148
|
-
|
|
149
|
-
Logs any errors in a ResultAsync without changing the ResultAsync.
|
|
150
|
-
|
|
151
|
-
### Types
|
|
152
|
-
|
|
153
|
-
#### `LogLevel`
|
|
154
|
-
|
|
155
|
-
```typescript
|
|
156
|
-
type LogLevel = 'info' | 'success' | 'warn' | 'error' | 'debug';
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
#### `Logger`
|
|
160
|
-
|
|
161
|
-
```typescript
|
|
162
|
-
type Logger = {
|
|
163
|
-
info(message: string, data?: object): void;
|
|
164
|
-
success(message: string, data?: object): void;
|
|
165
|
-
warn(message: string, data?: object): void;
|
|
166
|
-
error(message: string, data?: object): void;
|
|
167
|
-
debug(message: string, data?: object): void;
|
|
168
|
-
};
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
#### `LoggerOptions`
|
|
172
|
-
|
|
173
|
-
```typescript
|
|
174
|
-
interface LoggerOptions {
|
|
175
|
-
disabled?: boolean;
|
|
176
|
-
level?: Exclude<LogLevel, 'success'>;
|
|
177
|
-
log?: (level: LogLevel, message: string, data?: object) => void;
|
|
178
|
-
appName?: string;
|
|
179
|
-
}
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
#### `LoggableError`
|
|
183
|
-
|
|
184
|
-
```typescript
|
|
185
|
-
interface LoggableError {
|
|
186
|
-
message: string;
|
|
187
|
-
code?: string | number;
|
|
188
|
-
status?: number;
|
|
189
|
-
meta?: Record<string, unknown>;
|
|
190
|
-
category?: string;
|
|
191
|
-
stack?: string;
|
|
192
|
-
}
|
|
193
|
-
```
|
|
194
|
-
|
|
195
|
-
## Best Practices
|
|
196
|
-
|
|
197
|
-
1. **Use Structured Logging**
|
|
198
|
-
- Always include relevant data objects with your log messages
|
|
199
|
-
- This makes logs easier to search and analyze
|
|
200
|
-
|
|
201
|
-
2. **Choose Appropriate Log Levels**
|
|
202
|
-
- Use `error` only for actual errors that require attention
|
|
203
|
-
- Use `warn` for potentially problematic situations
|
|
204
|
-
- Use `info` for normal operation events
|
|
205
|
-
- Use `debug` only for detailed troubleshooting information
|
|
206
|
-
|
|
207
|
-
3. **Include Context**
|
|
208
|
-
- Add request IDs, user IDs, or transaction IDs to logs
|
|
209
|
-
- This helps correlate related log entries
|
|
210
|
-
|
|
211
|
-
## License
|
|
212
|
-
|
|
213
|
-
MIT
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { colors, formatMessage, levelColors } from '../console-formatter';
|
|
3
|
-
|
|
4
|
-
describe('console-formatter', () => {
|
|
5
|
-
describe('colors', () => {
|
|
6
|
-
it('should define ANSI color codes for text formatting', () => {
|
|
7
|
-
expect(colors.reset).toBe('\x1b[0m');
|
|
8
|
-
expect(colors.bright).toBe('\x1b[1m');
|
|
9
|
-
expect(colors.dim).toBe('\x1b[2m');
|
|
10
|
-
|
|
11
|
-
// Foreground colors
|
|
12
|
-
expect(colors.fg.red).toBe('\x1b[31m');
|
|
13
|
-
expect(colors.fg.green).toBe('\x1b[32m');
|
|
14
|
-
expect(colors.fg.yellow).toBe('\x1b[33m');
|
|
15
|
-
expect(colors.fg.blue).toBe('\x1b[34m');
|
|
16
|
-
expect(colors.fg.magenta).toBe('\x1b[35m');
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
describe('levelColors', () => {
|
|
21
|
-
it('should assign appropriate colors to each log level', () => {
|
|
22
|
-
expect(levelColors.info).toBe(colors.fg.blue);
|
|
23
|
-
expect(levelColors.success).toBe(colors.fg.green);
|
|
24
|
-
expect(levelColors.warn).toBe(colors.fg.yellow);
|
|
25
|
-
expect(levelColors.error).toBe(colors.fg.red);
|
|
26
|
-
expect(levelColors.debug).toBe(colors.fg.magenta);
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
describe('formatMessage', () => {
|
|
31
|
-
it('should format a message with timestamp, level, and app name', () => {
|
|
32
|
-
const formattedMessage = formatMessage('error', 'Test message');
|
|
33
|
-
|
|
34
|
-
// Verify the message contains the main components
|
|
35
|
-
expect(formattedMessage).toContain('ERROR');
|
|
36
|
-
expect(formattedMessage).toContain('[c15t]');
|
|
37
|
-
expect(formattedMessage).toContain('Test message');
|
|
38
|
-
|
|
39
|
-
// Verify formatting includes timestamp (ISO format)
|
|
40
|
-
// biome-ignore lint/performance/useTopLevelRegex: its okay its a test
|
|
41
|
-
expect(formattedMessage).toMatch(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('should use custom app name when provided', () => {
|
|
45
|
-
const formattedMessage = formatMessage(
|
|
46
|
-
'info',
|
|
47
|
-
'Custom app',
|
|
48
|
-
'custom-app'
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
expect(formattedMessage).toContain('[custom-app]');
|
|
52
|
-
expect(formattedMessage).toContain('INFO');
|
|
53
|
-
expect(formattedMessage).toContain('Custom app');
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('should use appropriate color for each log level', () => {
|
|
57
|
-
const errorMessage = formatMessage('error', 'Error message');
|
|
58
|
-
const warnMessage = formatMessage('warn', 'Warning message');
|
|
59
|
-
const infoMessage = formatMessage('info', 'Info message');
|
|
60
|
-
|
|
61
|
-
// Check that each message contains the color code for its level
|
|
62
|
-
expect(errorMessage).toContain(colors.fg.red);
|
|
63
|
-
expect(warnMessage).toContain(colors.fg.yellow);
|
|
64
|
-
expect(infoMessage).toContain(colors.fg.blue);
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
});
|
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
import { err, errAsync } from 'neverthrow';
|
|
2
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
3
|
-
import { createLogger } from '../logger-factory';
|
|
4
|
-
import { logResult, logResultAsync } from '../result-logging';
|
|
5
|
-
import type { LoggableError } from '../types';
|
|
6
|
-
|
|
7
|
-
describe('logger integration', () => {
|
|
8
|
-
beforeEach(() => {
|
|
9
|
-
// biome-ignore lint/suspicious/noEmptyBlockStatements: its okay its a test
|
|
10
|
-
vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
11
|
-
// biome-ignore lint/suspicious/noEmptyBlockStatements: its okay its a test
|
|
12
|
-
vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
13
|
-
// biome-ignore lint/suspicious/noEmptyBlockStatements: its okay its a test
|
|
14
|
-
vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
15
|
-
// biome-ignore lint/suspicious/noEmptyBlockStatements: its okay its a test
|
|
16
|
-
vi.spyOn(console, 'debug').mockImplementation(() => {});
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
afterEach(() => {
|
|
20
|
-
vi.restoreAllMocks();
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
describe('full logger pipeline', () => {
|
|
24
|
-
it('should work with default logger and result logging together', () => {
|
|
25
|
-
// Create a default logger
|
|
26
|
-
const logger = createLogger();
|
|
27
|
-
|
|
28
|
-
// Create an error result
|
|
29
|
-
const testError: LoggableError = {
|
|
30
|
-
message: 'Integration test error',
|
|
31
|
-
code: 'INTEGRATION_TEST',
|
|
32
|
-
};
|
|
33
|
-
const errorResult = err(testError);
|
|
34
|
-
|
|
35
|
-
// Log the error using the result logging utility
|
|
36
|
-
logResult(errorResult, logger);
|
|
37
|
-
|
|
38
|
-
// Verify that console.error was called with a formatted message
|
|
39
|
-
expect(console.error).toHaveBeenCalledTimes(1);
|
|
40
|
-
const mockedConsoleError = vi.mocked(console.error);
|
|
41
|
-
expect(mockedConsoleError.mock.calls[0]?.[0]).toContain('ERROR');
|
|
42
|
-
expect(mockedConsoleError.mock.calls[0]?.[0]).toContain(
|
|
43
|
-
'Integration test error'
|
|
44
|
-
);
|
|
45
|
-
expect(mockedConsoleError.mock.calls[0]?.[1]).toEqual({
|
|
46
|
-
code: 'INTEGRATION_TEST',
|
|
47
|
-
status: undefined,
|
|
48
|
-
meta: undefined,
|
|
49
|
-
category: undefined,
|
|
50
|
-
stack: undefined,
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('should work with custom log level and error logging together', () => {
|
|
55
|
-
// Create a logger with custom configuration
|
|
56
|
-
const logger = createLogger({
|
|
57
|
-
level: 'info', // Change from 'debug' to 'info' to allow info, warn, and error logs
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
// Test standard logging
|
|
61
|
-
logger.info('Info message');
|
|
62
|
-
logger.debug('Debug message');
|
|
63
|
-
logger.warn('Warning message');
|
|
64
|
-
|
|
65
|
-
expect(console.log).toHaveBeenCalledTimes(1);
|
|
66
|
-
expect(console.debug).toHaveBeenCalledTimes(0); // Debug won't be logged with info level
|
|
67
|
-
expect(console.warn).toHaveBeenCalledTimes(1);
|
|
68
|
-
|
|
69
|
-
// Create an error for result logging
|
|
70
|
-
const testError: LoggableError = {
|
|
71
|
-
message: 'Integration error',
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
// Log using the result logging utility
|
|
75
|
-
logResult(err(testError), logger);
|
|
76
|
-
|
|
77
|
-
expect(console.error).toHaveBeenCalledTimes(1);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it('should work with custom log handler and result logging', () => {
|
|
81
|
-
// Create a mock log handler
|
|
82
|
-
const customLogHandler = vi.fn();
|
|
83
|
-
|
|
84
|
-
// Create a logger with the custom handler
|
|
85
|
-
const logger = createLogger({
|
|
86
|
-
level: 'info', // Change from 'debug' to 'info' to allow info, warn, and error logs
|
|
87
|
-
log: customLogHandler,
|
|
88
|
-
appName: 'c15t',
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
// Use direct logging
|
|
92
|
-
logger.info('Direct info');
|
|
93
|
-
logger.error('Direct error');
|
|
94
|
-
|
|
95
|
-
expect(customLogHandler).toHaveBeenCalledTimes(2);
|
|
96
|
-
|
|
97
|
-
// Use result logging
|
|
98
|
-
const testError: LoggableError = {
|
|
99
|
-
message: 'Result error',
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
logResult(err(testError), logger);
|
|
103
|
-
|
|
104
|
-
// Check that the custom handler was called again
|
|
105
|
-
expect(customLogHandler).toHaveBeenCalledTimes(3);
|
|
106
|
-
const mockedCustomLogHandler = vi.mocked(customLogHandler);
|
|
107
|
-
expect(mockedCustomLogHandler.mock.calls[2]?.[0]).toBe('error');
|
|
108
|
-
expect(mockedCustomLogHandler.mock.calls[2]?.[1]).toBe(
|
|
109
|
-
'Error occurred: Result error'
|
|
110
|
-
);
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it('should support async result logging with the logger', async () => {
|
|
114
|
-
const logger = createLogger();
|
|
115
|
-
|
|
116
|
-
const testError: LoggableError = {
|
|
117
|
-
message: 'Async integration error',
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
const errorResultAsync = errAsync(testError);
|
|
121
|
-
|
|
122
|
-
await logResultAsync(errorResultAsync, logger).match(
|
|
123
|
-
// biome-ignore lint/suspicious/noEmptyBlockStatements: its okay its a test
|
|
124
|
-
() => {},
|
|
125
|
-
// biome-ignore lint/suspicious/noEmptyBlockStatements: its okay its a test
|
|
126
|
-
() => {}
|
|
127
|
-
);
|
|
128
|
-
|
|
129
|
-
expect(console.error).toHaveBeenCalledTimes(1);
|
|
130
|
-
const mockedConsoleError = vi.mocked(console.error);
|
|
131
|
-
expect(mockedConsoleError.mock.calls[0]?.[0]).toContain(
|
|
132
|
-
'Async integration error'
|
|
133
|
-
);
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
it('should use custom application name in logs', () => {
|
|
137
|
-
// Create a logger with a custom application name
|
|
138
|
-
const customAppName = 'c15t-api';
|
|
139
|
-
const logger = createLogger({
|
|
140
|
-
level: 'info',
|
|
141
|
-
appName: customAppName,
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
// Log messages at different levels
|
|
145
|
-
logger.info('Application started');
|
|
146
|
-
logger.warn('Configuration incomplete');
|
|
147
|
-
logger.error('Failed to connect to database');
|
|
148
|
-
|
|
149
|
-
// Verify logs contain the custom app name
|
|
150
|
-
const mockedConsoleLog = vi.mocked(console.log);
|
|
151
|
-
const mockedConsoleWarn = vi.mocked(console.warn);
|
|
152
|
-
const mockedConsoleError = vi.mocked(console.error);
|
|
153
|
-
|
|
154
|
-
expect(mockedConsoleLog.mock.calls[0]?.[0]).toContain(
|
|
155
|
-
`[${customAppName}]`
|
|
156
|
-
);
|
|
157
|
-
expect(mockedConsoleWarn.mock.calls[0]?.[0]).toContain(
|
|
158
|
-
`[${customAppName}]`
|
|
159
|
-
);
|
|
160
|
-
expect(mockedConsoleError.mock.calls[0]?.[0]).toContain(
|
|
161
|
-
`[${customAppName}]`
|
|
162
|
-
);
|
|
163
|
-
|
|
164
|
-
// Verify logs don't contain the default app name
|
|
165
|
-
expect(mockedConsoleLog.mock.calls[0]?.[0]).not.toContain(
|
|
166
|
-
'[🪢 doubletie]'
|
|
167
|
-
);
|
|
168
|
-
|
|
169
|
-
// Check that the custom app name works with result logging too
|
|
170
|
-
const testError: LoggableError = {
|
|
171
|
-
message: 'Integration error with custom app name',
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
logResult(err(testError), logger);
|
|
175
|
-
|
|
176
|
-
expect(mockedConsoleError.mock.calls[1]?.[0]).toContain(
|
|
177
|
-
`[${customAppName}]`
|
|
178
|
-
);
|
|
179
|
-
expect(mockedConsoleError.mock.calls[1]?.[0]).toContain(
|
|
180
|
-
'Integration error with custom app name'
|
|
181
|
-
);
|
|
182
|
-
});
|
|
183
|
-
});
|
|
184
|
-
});
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { levels, shouldPublishLog } from '../log-levels';
|
|
3
|
-
import type { LogLevel } from '../types';
|
|
4
|
-
|
|
5
|
-
describe('log-levels', () => {
|
|
6
|
-
describe('levels', () => {
|
|
7
|
-
it('should contain all expected log levels', () => {
|
|
8
|
-
expect(levels).toContain('error');
|
|
9
|
-
expect(levels).toContain('warn');
|
|
10
|
-
expect(levels).toContain('info');
|
|
11
|
-
expect(levels).toContain('success');
|
|
12
|
-
expect(levels).toContain('debug');
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('should be defined in correct order for log level comparison', () => {
|
|
16
|
-
// Lower index = more important (error should be first)
|
|
17
|
-
expect(levels.indexOf('error')).toBeLessThan(levels.indexOf('warn'));
|
|
18
|
-
expect(levels.indexOf('warn')).toBeLessThan(levels.indexOf('info'));
|
|
19
|
-
expect(levels.indexOf('info')).toBeLessThan(levels.indexOf('success'));
|
|
20
|
-
expect(levels.indexOf('success')).toBeLessThan(levels.indexOf('debug'));
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
describe('shouldPublishLog', () => {
|
|
25
|
-
// Define the expected behavior for our tests
|
|
26
|
-
it('should allow messages with level equal to or more important than the current level', () => {
|
|
27
|
-
// Test 'info' level
|
|
28
|
-
expect(shouldPublishLog('info', 'info')).toBe(true);
|
|
29
|
-
|
|
30
|
-
// Test 'warn' level
|
|
31
|
-
expect(shouldPublishLog('warn', 'warn')).toBe(true);
|
|
32
|
-
expect(shouldPublishLog('warn', 'error')).toBe(true);
|
|
33
|
-
expect(shouldPublishLog('warn', 'info')).toBe(false);
|
|
34
|
-
|
|
35
|
-
// Test 'error' level
|
|
36
|
-
expect(shouldPublishLog('error', 'error')).toBe(true);
|
|
37
|
-
expect(shouldPublishLog('error', 'warn')).toBe(false);
|
|
38
|
-
expect(shouldPublishLog('error', 'info')).toBe(false);
|
|
39
|
-
|
|
40
|
-
// Test 'debug' level (special case)
|
|
41
|
-
expect(shouldPublishLog('debug', 'debug')).toBe(true);
|
|
42
|
-
expect(shouldPublishLog('debug', 'error')).toBe(false);
|
|
43
|
-
expect(shouldPublishLog('debug', 'warn')).toBe(false);
|
|
44
|
-
expect(shouldPublishLog('debug', 'info')).toBe(false);
|
|
45
|
-
expect(shouldPublishLog('debug', 'success')).toBe(false);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('should use array comparison for determining log level priority', () => {
|
|
49
|
-
const testFn = (
|
|
50
|
-
currentLevel: LogLevel,
|
|
51
|
-
messageLevel: LogLevel
|
|
52
|
-
): boolean => {
|
|
53
|
-
// Simulate the logic from shouldPublishLog
|
|
54
|
-
const currentLevelIndex = levels.indexOf(currentLevel);
|
|
55
|
-
const messageLevelIndex = levels.indexOf(messageLevel);
|
|
56
|
-
|
|
57
|
-
if (currentLevel === 'debug') {
|
|
58
|
-
return messageLevel === 'debug';
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return messageLevelIndex <= currentLevelIndex;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
// Test various combinations
|
|
65
|
-
expect(testFn('info', 'error')).toBe(true);
|
|
66
|
-
expect(testFn('warn', 'error')).toBe(true);
|
|
67
|
-
expect(testFn('error', 'error')).toBe(true);
|
|
68
|
-
expect(testFn('error', 'warn')).toBe(false);
|
|
69
|
-
|
|
70
|
-
// Compare with the actual function
|
|
71
|
-
expect(testFn('info', 'error')).toBe(shouldPublishLog('info', 'error'));
|
|
72
|
-
expect(testFn('warn', 'error')).toBe(shouldPublishLog('warn', 'error'));
|
|
73
|
-
expect(testFn('error', 'error')).toBe(shouldPublishLog('error', 'error'));
|
|
74
|
-
expect(testFn('error', 'warn')).toBe(shouldPublishLog('error', 'warn'));
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
});
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
-
import { levels } from '../log-levels';
|
|
3
|
-
import * as logLevels from '../log-levels';
|
|
4
|
-
import { createLogger } from '../logger-factory';
|
|
5
|
-
|
|
6
|
-
describe('logger-factory', () => {
|
|
7
|
-
// Mock console methods
|
|
8
|
-
beforeEach(() => {
|
|
9
|
-
// biome-ignore lint/suspicious/noEmptyBlockStatements: its okay its a test
|
|
10
|
-
vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
11
|
-
// biome-ignore lint/suspicious/noEmptyBlockStatements: its okay its a test
|
|
12
|
-
vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
13
|
-
// biome-ignore lint/suspicious/noEmptyBlockStatements: its okay its a test
|
|
14
|
-
vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
15
|
-
// biome-ignore lint/suspicious/noEmptyBlockStatements: its okay its a test
|
|
16
|
-
vi.spyOn(console, 'debug').mockImplementation(() => {});
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
afterEach(() => {
|
|
20
|
-
vi.restoreAllMocks();
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
describe('createLogger', () => {
|
|
24
|
-
it('should create a logger with all log level methods', () => {
|
|
25
|
-
const logger = createLogger();
|
|
26
|
-
for (const level of levels) {
|
|
27
|
-
expect(typeof logger[level]).toBe('function');
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('should respect disabled option', () => {
|
|
32
|
-
const logger = createLogger({ disabled: true });
|
|
33
|
-
logger.error('This should not be logged');
|
|
34
|
-
expect(console.error).not.toHaveBeenCalled();
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('should respect log level option', () => {
|
|
38
|
-
// Mock the shouldPublishLog function to return expected values for our test
|
|
39
|
-
vi.spyOn(logLevels, 'shouldPublishLog').mockImplementation(
|
|
40
|
-
(currentLevel, messageLevel) => {
|
|
41
|
-
if (currentLevel === 'warn') {
|
|
42
|
-
return messageLevel === 'warn' || messageLevel === 'error';
|
|
43
|
-
}
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
const logger = createLogger({ level: 'warn' });
|
|
49
|
-
|
|
50
|
-
logger.error('This should be logged'); // Should be logged
|
|
51
|
-
logger.warn('This should be logged'); // Should be logged
|
|
52
|
-
logger.info('This should not be logged'); // Should not be logged
|
|
53
|
-
logger.debug('This should not be logged'); // Should not be logged
|
|
54
|
-
|
|
55
|
-
// Verify calls
|
|
56
|
-
expect(console.error).toHaveBeenCalled();
|
|
57
|
-
expect(console.warn).toHaveBeenCalled();
|
|
58
|
-
expect(console.log).not.toHaveBeenCalled();
|
|
59
|
-
expect(console.debug).not.toHaveBeenCalled();
|
|
60
|
-
|
|
61
|
-
// Restore the original function
|
|
62
|
-
vi.mocked(logLevels.shouldPublishLog).mockRestore();
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('should use custom log handler when provided', () => {
|
|
66
|
-
const customLog = vi.fn();
|
|
67
|
-
const logger = createLogger({
|
|
68
|
-
log: customLog,
|
|
69
|
-
level: 'debug',
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
// Mock shouldPublishLog to always return true for this test
|
|
73
|
-
vi.spyOn(logLevels, 'shouldPublishLog').mockReturnValue(true);
|
|
74
|
-
|
|
75
|
-
logger.info('Info message');
|
|
76
|
-
logger.error('Error message');
|
|
77
|
-
logger.success('Success message');
|
|
78
|
-
|
|
79
|
-
expect(customLog).toHaveBeenCalledTimes(3);
|
|
80
|
-
expect(customLog).toHaveBeenCalledWith('info', 'Info message');
|
|
81
|
-
expect(customLog).toHaveBeenCalledWith('error', 'Error message');
|
|
82
|
-
// 'success' should be treated as 'info' when using custom log handler
|
|
83
|
-
expect(customLog).toHaveBeenCalledWith('info', 'Success message');
|
|
84
|
-
|
|
85
|
-
vi.mocked(logLevels.shouldPublishLog).mockRestore();
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it('should format messages with timestamp and level', () => {
|
|
89
|
-
// Mock shouldPublishLog to return true for this test
|
|
90
|
-
vi.spyOn(logLevels, 'shouldPublishLog').mockReturnValue(true);
|
|
91
|
-
|
|
92
|
-
const logger = createLogger();
|
|
93
|
-
logger.error('Test message');
|
|
94
|
-
|
|
95
|
-
// Check that console.error was called with a formatted message
|
|
96
|
-
expect(console.error).toHaveBeenCalled();
|
|
97
|
-
|
|
98
|
-
// Extract the first argument from the first call
|
|
99
|
-
const mockedConsoleError = vi.mocked(console.error);
|
|
100
|
-
const firstCallArg = mockedConsoleError.mock.calls[0]?.[0];
|
|
101
|
-
|
|
102
|
-
// Check that the message contains the expected parts
|
|
103
|
-
expect(firstCallArg).toContain('ERROR');
|
|
104
|
-
expect(firstCallArg).toContain('[c15t]');
|
|
105
|
-
expect(firstCallArg).toContain('Test message');
|
|
106
|
-
|
|
107
|
-
// Check that timestamp matches ISO format
|
|
108
|
-
// biome-ignore lint/performance/useTopLevelRegex: its okay its a test
|
|
109
|
-
expect(firstCallArg).toMatch(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/);
|
|
110
|
-
|
|
111
|
-
vi.mocked(logLevels.shouldPublishLog).mockRestore();
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it('should pass additional arguments to console methods', () => {
|
|
115
|
-
// Mock shouldPublishLog to return true for this test
|
|
116
|
-
vi.spyOn(logLevels, 'shouldPublishLog').mockReturnValue(true);
|
|
117
|
-
|
|
118
|
-
const logger = createLogger();
|
|
119
|
-
const meta = { userId: 'user123' };
|
|
120
|
-
|
|
121
|
-
logger.error('Error with meta', meta);
|
|
122
|
-
|
|
123
|
-
expect(console.error).toHaveBeenCalled();
|
|
124
|
-
const mockedConsoleError = vi.mocked(console.error);
|
|
125
|
-
expect(mockedConsoleError.mock.calls[0]?.[1]).toBe(meta);
|
|
126
|
-
|
|
127
|
-
vi.mocked(logLevels.shouldPublishLog).mockRestore();
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it('should use custom app name when provided', () => {
|
|
131
|
-
// Mock shouldPublishLog to return true for this test
|
|
132
|
-
vi.spyOn(logLevels, 'shouldPublishLog').mockReturnValue(true);
|
|
133
|
-
|
|
134
|
-
// Create a logger with a custom app name
|
|
135
|
-
const customAppName = 'test-app';
|
|
136
|
-
const logger = createLogger({ appName: customAppName });
|
|
137
|
-
|
|
138
|
-
// Log a test message
|
|
139
|
-
logger.info('Test message with custom app name');
|
|
140
|
-
|
|
141
|
-
// Check that console.log was called with a formatted message
|
|
142
|
-
expect(console.log).toHaveBeenCalled();
|
|
143
|
-
|
|
144
|
-
// Extract the first argument from the first call
|
|
145
|
-
const mockedConsoleLog = vi.mocked(console.log);
|
|
146
|
-
const logMessage = mockedConsoleLog.mock.calls[0]?.[0];
|
|
147
|
-
|
|
148
|
-
// Verify the message contains the custom app name
|
|
149
|
-
expect(logMessage).toContain(`[${customAppName}]`);
|
|
150
|
-
// And doesn't contain the default app name
|
|
151
|
-
expect(logMessage).not.toContain('[🪢 doubletie]');
|
|
152
|
-
|
|
153
|
-
vi.mocked(logLevels.shouldPublishLog).mockRestore();
|
|
154
|
-
});
|
|
155
|
-
});
|
|
156
|
-
});
|