@c15t/backend 0.0.1-rc.10
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 +11 -0
- package/.turbo/turbo-check-types.log +5 -0
- package/.turbo/turbo-fmt.log +7 -0
- package/.turbo/turbo-lint.log +6 -0
- package/.turbo/turbo-test.log +26 -0
- package/README-next.md +223 -0
- package/README.md +164 -0
- package/dist/api/call.d.ts +176 -0
- package/dist/api/call.d.ts.map +1 -0
- package/dist/api/index.d.ts +935 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/middlewares/index.d.ts +39 -0
- package/dist/api/middlewares/index.d.ts.map +1 -0
- package/dist/api/middlewares/origin-check.d.ts +82 -0
- package/dist/api/middlewares/origin-check.d.ts.map +1 -0
- package/dist/api/middlewares/validate-context.d.ts +38 -0
- package/dist/api/middlewares/validate-context.d.ts.map +1 -0
- package/dist/api/routes/__tests__/consent.test.d.ts +2 -0
- package/dist/api/routes/__tests__/consent.test.d.ts.map +1 -0
- package/dist/api/routes/__tests__/status.test.d.ts +2 -0
- package/dist/api/routes/__tests__/status.test.d.ts.map +1 -0
- package/dist/api/routes/error.d.ts +57 -0
- package/dist/api/routes/error.d.ts.map +1 -0
- package/dist/api/routes/generate-consent-receipt.d.ts +130 -0
- package/dist/api/routes/generate-consent-receipt.d.ts.map +1 -0
- package/dist/api/routes/get-consent-history.d.ts +133 -0
- package/dist/api/routes/get-consent-history.d.ts.map +1 -0
- package/dist/api/routes/get-consent-policy.d.ts +164 -0
- package/dist/api/routes/get-consent-policy.d.ts.map +1 -0
- package/dist/api/routes/get-consent.d.ts +148 -0
- package/dist/api/routes/get-consent.d.ts.map +1 -0
- package/dist/api/routes/index.d.ts +339 -0
- package/dist/api/routes/index.d.ts.map +1 -0
- package/dist/api/routes/ok.d.ts +87 -0
- package/dist/api/routes/ok.d.ts.map +1 -0
- package/dist/api/routes/set-consent.d.ts +245 -0
- package/dist/api/routes/set-consent.d.ts.map +1 -0
- package/dist/api/routes/show-consent-banner.d.ts +127 -0
- package/dist/api/routes/show-consent-banner.d.ts.map +1 -0
- package/dist/api/routes/status.d.ts +61 -0
- package/dist/api/routes/status.d.ts.map +1 -0
- package/dist/api/routes/verify-consent.d.ts +179 -0
- package/dist/api/routes/verify-consent.d.ts.map +1 -0
- package/dist/api/routes/withdraw-consent.d.ts +194 -0
- package/dist/api/routes/withdraw-consent.d.ts.map +1 -0
- package/dist/api/to-endpoints.d.ts +35 -0
- package/dist/api/to-endpoints.d.ts.map +1 -0
- package/dist/client/index.cjs +139 -0
- package/dist/client/index.d.ts +203 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +106 -0
- package/dist/client/types.d.ts +431 -0
- package/dist/client/types.d.ts.map +1 -0
- package/dist/core.d.ts +124 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/core.test.d.ts +2 -0
- package/dist/core.test.d.ts.map +1 -0
- package/dist/db/adapters/drizzle-adapter/drizzle-adapter.d.ts +122 -0
- package/dist/db/adapters/drizzle-adapter/drizzle-adapter.d.ts.map +1 -0
- package/dist/db/adapters/drizzle-adapter/index.d.ts +2 -0
- package/dist/db/adapters/drizzle-adapter/index.d.ts.map +1 -0
- package/dist/db/adapters/drizzle.cjs +1531 -0
- package/dist/db/adapters/drizzle.js +1489 -0
- package/dist/db/adapters/kysely-adapter/dialect.d.ts +72 -0
- package/dist/db/adapters/kysely-adapter/dialect.d.ts.map +1 -0
- package/dist/db/adapters/kysely-adapter/index.d.ts +4 -0
- package/dist/db/adapters/kysely-adapter/index.d.ts.map +1 -0
- package/dist/db/adapters/kysely-adapter/kysely-adapter.d.ts +98 -0
- package/dist/db/adapters/kysely-adapter/kysely-adapter.d.ts.map +1 -0
- package/dist/db/adapters/kysely-adapter/types.d.ts +281 -0
- package/dist/db/adapters/kysely-adapter/types.d.ts.map +1 -0
- package/dist/db/adapters/kysely.cjs +1551 -0
- package/dist/db/adapters/kysely.js +1508 -0
- package/dist/db/adapters/memory-adapter/index.d.ts +2 -0
- package/dist/db/adapters/memory-adapter/index.d.ts.map +1 -0
- package/dist/db/adapters/memory-adapter/memory-adapter.d.ts +56 -0
- package/dist/db/adapters/memory-adapter/memory-adapter.d.ts.map +1 -0
- package/dist/db/adapters/memory.cjs +1391 -0
- package/dist/db/adapters/memory.js +1349 -0
- package/dist/db/adapters/prisma-adapter/index.d.ts +2 -0
- package/dist/db/adapters/prisma-adapter/index.d.ts.map +1 -0
- package/dist/db/adapters/prisma-adapter/prisma-adapter.d.ts +143 -0
- package/dist/db/adapters/prisma-adapter/prisma-adapter.d.ts.map +1 -0
- package/dist/db/adapters/prisma.cjs +1503 -0
- package/dist/db/adapters/prisma.js +1461 -0
- package/dist/db/adapters/types.d.ts +154 -0
- package/dist/db/adapters/types.d.ts.map +1 -0
- package/dist/db/adapters/utils.d.ts +36 -0
- package/dist/db/adapters/utils.d.ts.map +1 -0
- package/dist/db/core/fields/field-factory.d.ts +383 -0
- package/dist/db/core/fields/field-factory.d.ts.map +1 -0
- package/dist/db/core/fields/field-inference.d.ts +218 -0
- package/dist/db/core/fields/field-inference.d.ts.map +1 -0
- package/dist/db/core/fields/field-options-integration.d.ts +90 -0
- package/dist/db/core/fields/field-options-integration.d.ts.map +1 -0
- package/dist/db/core/fields/field-types.d.ts +182 -0
- package/dist/db/core/fields/field-types.d.ts.map +1 -0
- package/dist/db/core/fields/id-generator.d.ts +19 -0
- package/dist/db/core/fields/id-generator.d.ts.map +1 -0
- package/dist/db/core/fields/index.d.ts +8 -0
- package/dist/db/core/fields/index.d.ts.map +1 -0
- package/dist/db/core/fields/superjson-utils.d.ts +34 -0
- package/dist/db/core/fields/superjson-utils.d.ts.map +1 -0
- package/dist/db/core/fields/zod-fields.d.ts +1011 -0
- package/dist/db/core/fields/zod-fields.d.ts.map +1 -0
- package/dist/db/core/get-schema.d.ts +36 -0
- package/dist/db/core/get-schema.d.ts.map +1 -0
- package/dist/db/core/types.d.ts +41 -0
- package/dist/db/core/types.d.ts.map +1 -0
- package/dist/db/create-registry.d.ts +760 -0
- package/dist/db/create-registry.d.ts.map +1 -0
- package/dist/db/hooks/create-hooks.d.ts +32 -0
- package/dist/db/hooks/create-hooks.d.ts.map +1 -0
- package/dist/db/hooks/index.d.ts +40 -0
- package/dist/db/hooks/index.d.ts.map +1 -0
- package/dist/db/hooks/types.d.ts +133 -0
- package/dist/db/hooks/types.d.ts.map +1 -0
- package/dist/db/hooks/update-hooks.d.ts +33 -0
- package/dist/db/hooks/update-hooks.d.ts.map +1 -0
- package/dist/db/hooks/update-many-hooks.d.ts +55 -0
- package/dist/db/hooks/update-many-hooks.d.ts.map +1 -0
- package/dist/db/hooks/utils.d.ts +62 -0
- package/dist/db/hooks/utils.d.ts.map +1 -0
- package/dist/db/hooks/with-hooks-factory.d.ts +33 -0
- package/dist/db/hooks/with-hooks-factory.d.ts.map +1 -0
- package/dist/db/index.cjs +2458 -0
- package/dist/db/index.d.ts +11 -0
- package/dist/db/index.d.ts.map +1 -0
- package/dist/db/index.js +2404 -0
- package/dist/db/migration/get-migration.d.ts +32 -0
- package/dist/db/migration/get-migration.d.ts.map +1 -0
- package/dist/db/migration/get-schema/get-schema.d.ts +27 -0
- package/dist/db/migration/get-schema/get-schema.d.ts.map +1 -0
- package/dist/db/migration/get-schema/index.d.ts +21 -0
- package/dist/db/migration/get-schema/index.d.ts.map +1 -0
- package/dist/db/migration/get-schema/process-fields.d.ts +16 -0
- package/dist/db/migration/get-schema/process-fields.d.ts.map +1 -0
- package/dist/db/migration/get-schema/process-tables.d.ts +13 -0
- package/dist/db/migration/get-schema/process-tables.d.ts.map +1 -0
- package/dist/db/migration/get-schema/types.d.ts +17 -0
- package/dist/db/migration/get-schema/types.d.ts.map +1 -0
- package/dist/db/migration/index.cjs +1613 -0
- package/dist/db/migration/index.d.ts +14 -0
- package/dist/db/migration/index.d.ts.map +1 -0
- package/dist/db/migration/index.js +1571 -0
- package/dist/db/migration/migration-builders.d.ts +28 -0
- package/dist/db/migration/migration-builders.d.ts.map +1 -0
- package/dist/db/migration/migration-execution.d.ts +12 -0
- package/dist/db/migration/migration-execution.d.ts.map +1 -0
- package/dist/db/migration/schema-comparison.d.ts +54 -0
- package/dist/db/migration/schema-comparison.d.ts.map +1 -0
- package/dist/db/migration/type-mapping.d.ts +86 -0
- package/dist/db/migration/type-mapping.d.ts.map +1 -0
- package/dist/db/migration/types.d.ts +37 -0
- package/dist/db/migration/types.d.ts.map +1 -0
- package/dist/db/schema/audit-log/index.d.ts +4 -0
- package/dist/db/schema/audit-log/index.d.ts.map +1 -0
- package/dist/db/schema/audit-log/registry.d.ts +128 -0
- package/dist/db/schema/audit-log/registry.d.ts.map +1 -0
- package/dist/db/schema/audit-log/schema.d.ts +67 -0
- package/dist/db/schema/audit-log/schema.d.ts.map +1 -0
- package/dist/db/schema/audit-log/table.d.ts +175 -0
- package/dist/db/schema/audit-log/table.d.ts.map +1 -0
- package/dist/db/schema/audit-log/types.d.ts +29 -0
- package/dist/db/schema/audit-log/types.d.ts.map +1 -0
- package/dist/db/schema/consent/index.d.ts +4 -0
- package/dist/db/schema/consent/index.d.ts.map +1 -0
- package/dist/db/schema/consent/registry.d.ts +318 -0
- package/dist/db/schema/consent/registry.d.ts.map +1 -0
- package/dist/db/schema/consent/schema.d.ts +135 -0
- package/dist/db/schema/consent/schema.d.ts.map +1 -0
- package/dist/db/schema/consent/table.d.ts +245 -0
- package/dist/db/schema/consent/table.d.ts.map +1 -0
- package/dist/db/schema/consent/types.d.ts +37 -0
- package/dist/db/schema/consent/types.d.ts.map +1 -0
- package/dist/db/schema/consent-geo-location/index.d.ts +4 -0
- package/dist/db/schema/consent-geo-location/index.d.ts.map +1 -0
- package/dist/db/schema/consent-geo-location/registry.d.ts +96 -0
- package/dist/db/schema/consent-geo-location/registry.d.ts.map +1 -0
- package/dist/db/schema/consent-geo-location/schema.d.ts +71 -0
- package/dist/db/schema/consent-geo-location/schema.d.ts.map +1 -0
- package/dist/db/schema/consent-geo-location/table.d.ts +167 -0
- package/dist/db/schema/consent-geo-location/table.d.ts.map +1 -0
- package/dist/db/schema/consent-geo-location/types.d.ts +21 -0
- package/dist/db/schema/consent-geo-location/types.d.ts.map +1 -0
- package/dist/db/schema/consent-policy/index.d.ts +4 -0
- package/dist/db/schema/consent-policy/index.d.ts.map +1 -0
- package/dist/db/schema/consent-policy/registry.d.ts +186 -0
- package/dist/db/schema/consent-policy/registry.d.ts.map +1 -0
- package/dist/db/schema/consent-policy/schema.d.ts +68 -0
- package/dist/db/schema/consent-policy/schema.d.ts.map +1 -0
- package/dist/db/schema/consent-policy/table.d.ts +147 -0
- package/dist/db/schema/consent-policy/table.d.ts.map +1 -0
- package/dist/db/schema/consent-policy/types.d.ts +28 -0
- package/dist/db/schema/consent-policy/types.d.ts.map +1 -0
- package/dist/db/schema/consent-purpose/index.d.ts +4 -0
- package/dist/db/schema/consent-purpose/index.d.ts.map +1 -0
- package/dist/db/schema/consent-purpose/registry.d.ts +136 -0
- package/dist/db/schema/consent-purpose/registry.d.ts.map +1 -0
- package/dist/db/schema/consent-purpose/schema.d.ts +79 -0
- package/dist/db/schema/consent-purpose/schema.d.ts.map +1 -0
- package/dist/db/schema/consent-purpose/table.d.ts +161 -0
- package/dist/db/schema/consent-purpose/table.d.ts.map +1 -0
- package/dist/db/schema/consent-purpose/types.d.ts +16 -0
- package/dist/db/schema/consent-purpose/types.d.ts.map +1 -0
- package/dist/db/schema/consent-purpose-junction/index.d.ts +4 -0
- package/dist/db/schema/consent-purpose-junction/index.d.ts.map +1 -0
- package/dist/db/schema/consent-purpose-junction/registry.d.ts +109 -0
- package/dist/db/schema/consent-purpose-junction/registry.d.ts.map +1 -0
- package/dist/db/schema/consent-purpose-junction/schema.d.ts +57 -0
- package/dist/db/schema/consent-purpose-junction/schema.d.ts.map +1 -0
- package/dist/db/schema/consent-purpose-junction/table.d.ts +138 -0
- package/dist/db/schema/consent-purpose-junction/table.d.ts.map +1 -0
- package/dist/db/schema/consent-purpose-junction/types.d.ts +14 -0
- package/dist/db/schema/consent-purpose-junction/types.d.ts.map +1 -0
- package/dist/db/schema/consent-record/index.d.ts +4 -0
- package/dist/db/schema/consent-record/index.d.ts.map +1 -0
- package/dist/db/schema/consent-record/registry.d.ts +119 -0
- package/dist/db/schema/consent-record/registry.d.ts.map +1 -0
- package/dist/db/schema/consent-record/schema.d.ts +57 -0
- package/dist/db/schema/consent-record/schema.d.ts.map +1 -0
- package/dist/db/schema/consent-record/table.d.ts +123 -0
- package/dist/db/schema/consent-record/table.d.ts.map +1 -0
- package/dist/db/schema/consent-record/types.d.ts +21 -0
- package/dist/db/schema/consent-record/types.d.ts.map +1 -0
- package/dist/db/schema/consent-withdrawal/index.d.ts +4 -0
- package/dist/db/schema/consent-withdrawal/index.d.ts.map +1 -0
- package/dist/db/schema/consent-withdrawal/registry.d.ts +134 -0
- package/dist/db/schema/consent-withdrawal/registry.d.ts.map +1 -0
- package/dist/db/schema/consent-withdrawal/schema.d.ts +67 -0
- package/dist/db/schema/consent-withdrawal/schema.d.ts.map +1 -0
- package/dist/db/schema/consent-withdrawal/table.d.ts +170 -0
- package/dist/db/schema/consent-withdrawal/table.d.ts.map +1 -0
- package/dist/db/schema/consent-withdrawal/types.d.ts +28 -0
- package/dist/db/schema/consent-withdrawal/types.d.ts.map +1 -0
- package/dist/db/schema/definition.d.ts +1100 -0
- package/dist/db/schema/definition.d.ts.map +1 -0
- package/dist/db/schema/domain/index.d.ts +4 -0
- package/dist/db/schema/domain/index.d.ts.map +1 -0
- package/dist/db/schema/domain/registry.d.ts +169 -0
- package/dist/db/schema/domain/registry.d.ts.map +1 -0
- package/dist/db/schema/domain/schema.d.ts +60 -0
- package/dist/db/schema/domain/schema.d.ts.map +1 -0
- package/dist/db/schema/domain/table.d.ts +140 -0
- package/dist/db/schema/domain/table.d.ts.map +1 -0
- package/dist/db/schema/domain/types.d.ts +27 -0
- package/dist/db/schema/domain/types.d.ts.map +1 -0
- package/dist/db/schema/geo-location/index.d.ts +4 -0
- package/dist/db/schema/geo-location/index.d.ts.map +1 -0
- package/dist/db/schema/geo-location/registry.d.ts +114 -0
- package/dist/db/schema/geo-location/registry.d.ts.map +1 -0
- package/dist/db/schema/geo-location/schema.d.ts +58 -0
- package/dist/db/schema/geo-location/schema.d.ts.map +1 -0
- package/dist/db/schema/geo-location/table.d.ts +132 -0
- package/dist/db/schema/geo-location/table.d.ts.map +1 -0
- package/dist/db/schema/geo-location/types.d.ts +17 -0
- package/dist/db/schema/geo-location/types.d.ts.map +1 -0
- package/dist/db/schema/index.d.ts +85 -0
- package/dist/db/schema/index.d.ts.map +1 -0
- package/dist/db/schema/parser.d.ts +183 -0
- package/dist/db/schema/parser.d.ts.map +1 -0
- package/dist/db/schema/schemas.d.ts +383 -0
- package/dist/db/schema/schemas.d.ts.map +1 -0
- package/dist/db/schema/subject/index.d.ts +4 -0
- package/dist/db/schema/subject/index.d.ts.map +1 -0
- package/dist/db/schema/subject/registry.d.ts +141 -0
- package/dist/db/schema/subject/registry.d.ts.map +1 -0
- package/dist/db/schema/subject/schema.d.ts +56 -0
- package/dist/db/schema/subject/schema.d.ts.map +1 -0
- package/dist/db/schema/subject/table.d.ts +136 -0
- package/dist/db/schema/subject/table.d.ts.map +1 -0
- package/dist/db/schema/subject/types.d.ts +22 -0
- package/dist/db/schema/subject/types.d.ts.map +1 -0
- package/dist/db/schema/types.d.ts +136 -0
- package/dist/db/schema/types.d.ts.map +1 -0
- package/dist/db/utils/adapter-factory.d.ts +21 -0
- package/dist/db/utils/adapter-factory.d.ts.map +1 -0
- package/dist/db/utils/index.d.ts +10 -0
- package/dist/db/utils/index.d.ts.map +1 -0
- package/dist/db/utils.d.ts +4 -0
- package/dist/db/utils.d.ts.map +1 -0
- package/dist/error/codes.cjs +68 -0
- package/dist/error/codes.d.ts +175 -0
- package/dist/error/codes.d.ts.map +1 -0
- package/dist/error/codes.js +35 -0
- package/dist/error/error.d.ts +79 -0
- package/dist/error/error.d.ts.map +1 -0
- package/dist/error/index.cjs +172 -0
- package/dist/error/index.d.ts +9 -0
- package/dist/error/index.d.ts.map +1 -0
- package/dist/error/index.js +129 -0
- package/dist/error/logging.d.ts +25 -0
- package/dist/error/logging.d.ts.map +1 -0
- package/dist/error/pipeline.d.ts +19 -0
- package/dist/error/pipeline.d.ts.map +1 -0
- package/dist/error/recovery.d.ts +22 -0
- package/dist/error/recovery.d.ts.map +1 -0
- package/dist/error/results.d.ts +56 -0
- package/dist/error/results.d.ts.map +1 -0
- package/dist/index.cjs +4777 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4708 -0
- package/dist/init.d.ts +52 -0
- package/dist/init.d.ts.map +1 -0
- package/dist/init.test.d.ts +2 -0
- package/dist/init.test.d.ts.map +1 -0
- package/dist/integrations/index.cjs +281 -0
- package/dist/integrations/index.d.ts +7 -0
- package/dist/integrations/index.d.ts.map +1 -0
- package/dist/integrations/index.js +248 -0
- package/dist/integrations/next.cjs +131 -0
- package/dist/integrations/next.d.ts +29 -0
- package/dist/integrations/next.d.ts.map +1 -0
- package/dist/integrations/next.js +99 -0
- package/dist/integrations/react.cjs +182 -0
- package/dist/integrations/react.d.ts +257 -0
- package/dist/integrations/react.d.ts.map +1 -0
- package/dist/integrations/react.js +150 -0
- package/dist/plugins/geo/index.d.ts +2 -0
- package/dist/plugins/geo/index.d.ts.map +1 -0
- package/dist/test/utils.d.ts +65 -0
- package/dist/test/utils.d.ts.map +1 -0
- package/dist/types/api.d.ts +89 -0
- package/dist/types/api.d.ts.map +1 -0
- package/dist/types/context.d.ts +205 -0
- package/dist/types/context.d.ts.map +1 -0
- package/dist/types/helper.d.ts +78 -0
- package/dist/types/helper.d.ts.map +1 -0
- package/dist/types/index.cjs +19 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +0 -0
- package/dist/types/options.d.ts +172 -0
- package/dist/types/options.d.ts.map +1 -0
- package/dist/types/plugins.d.ts +442 -0
- package/dist/types/plugins.d.ts.map +1 -0
- package/dist/utils/env.d.ts +77 -0
- package/dist/utils/env.d.ts.map +1 -0
- package/dist/utils/hide-metadata.d.ts +22 -0
- package/dist/utils/hide-metadata.d.ts.map +1 -0
- package/dist/utils/index.cjs +268 -0
- package/dist/utils/index.d.ts +18 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +210 -0
- package/dist/utils/ip.d.ts +10 -0
- package/dist/utils/ip.d.ts.map +1 -0
- package/dist/utils/json.d.ts +14 -0
- package/dist/utils/json.d.ts.map +1 -0
- package/dist/utils/logger.d.ts +108 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/url.d.ts +87 -0
- package/dist/utils/url.d.ts.map +1 -0
- package/dist/utils/wildcard.d.ts +46 -0
- package/dist/utils/wildcard.d.ts.map +1 -0
- package/knip.json +37 -0
- package/package.json +146 -0
- package/rslib.config.ts +104 -0
- package/src/api/call.ts +177 -0
- package/src/api/index.ts +303 -0
- package/src/api/middlewares/index.ts +38 -0
- package/src/api/middlewares/origin-check.ts +260 -0
- package/src/api/middlewares/validate-context.ts +175 -0
- package/src/api/routes/__tests__/consent.test.ts +270 -0
- package/src/api/routes/__tests__/status.test.ts +36 -0
- package/src/api/routes/error.ts +130 -0
- package/src/api/routes/generate-consent-receipt.ts +244 -0
- package/src/api/routes/get-consent-history.ts +128 -0
- package/src/api/routes/get-consent-policy.ts +327 -0
- package/src/api/routes/get-consent.ts +230 -0
- package/src/api/routes/index.ts +12 -0
- package/src/api/routes/ok.ts +45 -0
- package/src/api/routes/set-consent.ts +328 -0
- package/src/api/routes/show-consent-banner.ts +149 -0
- package/src/api/routes/status.ts +62 -0
- package/src/api/routes/verify-consent.ts +272 -0
- package/src/api/routes/withdraw-consent.ts +293 -0
- package/src/api/to-endpoints.ts +371 -0
- package/src/client/index.ts +471 -0
- package/src/client/types.ts +458 -0
- package/src/core.test.ts +303 -0
- package/src/core.ts +267 -0
- package/src/db/adapters/drizzle-adapter/drizzle-adapter.ts +711 -0
- package/src/db/adapters/drizzle-adapter/index.ts +1 -0
- package/src/db/adapters/kysely-adapter/dialect.ts +192 -0
- package/src/db/adapters/kysely-adapter/index.ts +3 -0
- package/src/db/adapters/kysely-adapter/kysely-adapter.ts +1168 -0
- package/src/db/adapters/kysely-adapter/types.ts +307 -0
- package/src/db/adapters/memory-adapter/index.ts +1 -0
- package/src/db/adapters/memory-adapter/memory-adapter.ts +648 -0
- package/src/db/adapters/prisma-adapter/index.ts +1 -0
- package/src/db/adapters/prisma-adapter/prisma-adapter.ts +586 -0
- package/src/db/adapters/types.ts +203 -0
- package/src/db/adapters/utils.ts +51 -0
- package/src/db/core/fields/field-factory.ts +804 -0
- package/src/db/core/fields/field-inference.ts +298 -0
- package/src/db/core/fields/field-options-integration.ts +135 -0
- package/src/db/core/fields/field-types.ts +233 -0
- package/src/db/core/fields/id-generator.ts +57 -0
- package/src/db/core/fields/index.ts +56 -0
- package/src/db/core/fields/superjson-utils.ts +155 -0
- package/src/db/core/fields/zod-fields.ts +269 -0
- package/src/db/core/get-schema.ts +102 -0
- package/src/db/core/types.ts +52 -0
- package/src/db/create-registry.ts +31 -0
- package/src/db/hooks/create-hooks.ts +88 -0
- package/src/db/hooks/index.ts +39 -0
- package/src/db/hooks/types.ts +164 -0
- package/src/db/hooks/update-hooks.ts +91 -0
- package/src/db/hooks/update-many-hooks.ts +176 -0
- package/src/db/hooks/utils.ts +151 -0
- package/src/db/hooks/with-hooks-factory.ts +68 -0
- package/src/db/index.ts +32 -0
- package/src/db/migration/get-migration.ts +89 -0
- package/src/db/migration/get-schema/get-schema.ts +44 -0
- package/src/db/migration/get-schema/index.ts +20 -0
- package/src/db/migration/get-schema/process-fields.ts +66 -0
- package/src/db/migration/get-schema/process-tables.ts +68 -0
- package/src/db/migration/get-schema/types.ts +18 -0
- package/src/db/migration/index.ts +18 -0
- package/src/db/migration/migration-builders.ts +170 -0
- package/src/db/migration/migration-execution.ts +79 -0
- package/src/db/migration/schema-comparison.ts +216 -0
- package/src/db/migration/type-mapping.ts +255 -0
- package/src/db/migration/types.ts +46 -0
- package/src/db/schema/audit-log/index.ts +3 -0
- package/src/db/schema/audit-log/registry.ts +228 -0
- package/src/db/schema/audit-log/schema.ts +46 -0
- package/src/db/schema/audit-log/table.ts +185 -0
- package/src/db/schema/audit-log/types.ts +29 -0
- package/src/db/schema/consent/index.ts +3 -0
- package/src/db/schema/consent/registry.ts +381 -0
- package/src/db/schema/consent/schema.ts +65 -0
- package/src/db/schema/consent/table.ts +220 -0
- package/src/db/schema/consent/types.ts +39 -0
- package/src/db/schema/consent-geo-location/index.ts +3 -0
- package/src/db/schema/consent-geo-location/registry.ts +124 -0
- package/src/db/schema/consent-geo-location/schema.ts +51 -0
- package/src/db/schema/consent-geo-location/table.ts +169 -0
- package/src/db/schema/consent-geo-location/types.ts +21 -0
- package/src/db/schema/consent-policy/index.ts +3 -0
- package/src/db/schema/consent-policy/registry.ts +313 -0
- package/src/db/schema/consent-policy/schema.ts +47 -0
- package/src/db/schema/consent-policy/table.ts +141 -0
- package/src/db/schema/consent-policy/types.ts +28 -0
- package/src/db/schema/consent-purpose/index.ts +3 -0
- package/src/db/schema/consent-purpose/registry.ts +188 -0
- package/src/db/schema/consent-purpose/schema.ts +58 -0
- package/src/db/schema/consent-purpose/table.ts +154 -0
- package/src/db/schema/consent-purpose/types.ts +16 -0
- package/src/db/schema/consent-purpose-junction/index.ts +3 -0
- package/src/db/schema/consent-purpose-junction/registry.ts +189 -0
- package/src/db/schema/consent-purpose-junction/schema.ts +49 -0
- package/src/db/schema/consent-purpose-junction/table.ts +142 -0
- package/src/db/schema/consent-purpose-junction/types.ts +14 -0
- package/src/db/schema/consent-record/index.ts +3 -0
- package/src/db/schema/consent-record/registry.ts +209 -0
- package/src/db/schema/consent-record/schema.ts +42 -0
- package/src/db/schema/consent-record/table.ts +124 -0
- package/src/db/schema/consent-record/types.ts +21 -0
- package/src/db/schema/consent-withdrawal/index.ts +3 -0
- package/src/db/schema/consent-withdrawal/registry.ts +219 -0
- package/src/db/schema/consent-withdrawal/schema.ts +48 -0
- package/src/db/schema/consent-withdrawal/table.ts +181 -0
- package/src/db/schema/consent-withdrawal/types.ts +29 -0
- package/src/db/schema/definition.ts +196 -0
- package/src/db/schema/domain/index.ts +3 -0
- package/src/db/schema/domain/registry.ts +272 -0
- package/src/db/schema/domain/schema.ts +43 -0
- package/src/db/schema/domain/table.ts +137 -0
- package/src/db/schema/domain/types.ts +27 -0
- package/src/db/schema/geo-location/index.ts +3 -0
- package/src/db/schema/geo-location/registry.ts +159 -0
- package/src/db/schema/geo-location/schema.ts +45 -0
- package/src/db/schema/geo-location/table.ts +148 -0
- package/src/db/schema/geo-location/types.ts +18 -0
- package/src/db/schema/index.ts +96 -0
- package/src/db/schema/parser.ts +417 -0
- package/src/db/schema/schemas.ts +35 -0
- package/src/db/schema/subject/index.ts +3 -0
- package/src/db/schema/subject/registry.ts +371 -0
- package/src/db/schema/subject/schema.ts +41 -0
- package/src/db/schema/subject/table.ts +139 -0
- package/src/db/schema/subject/types.ts +22 -0
- package/src/db/schema/types.ts +154 -0
- package/src/db/utils/adapter-factory.ts +64 -0
- package/src/db/utils/index.ts +10 -0
- package/src/db/utils.ts +42 -0
- package/src/docs/ADVANCED_JSON_HANDLING.md +99 -0
- package/src/docs/neverthrow.md +171 -0
- package/src/error/codes.ts +201 -0
- package/src/error/error.ts +145 -0
- package/src/error/index.ts +23 -0
- package/src/error/logging.ts +52 -0
- package/src/error/pipeline.ts +57 -0
- package/src/error/recovery.ts +45 -0
- package/src/error/results.ts +100 -0
- package/src/index.ts +79 -0
- package/src/init.test.ts +235 -0
- package/src/init.ts +261 -0
- package/src/integrations/index.ts +10 -0
- package/src/integrations/next.ts +136 -0
- package/src/integrations/react.ts +567 -0
- package/src/plugins/geo/index.ts +563 -0
- package/src/test/utils.ts +244 -0
- package/src/types/api.ts +101 -0
- package/src/types/context.ts +235 -0
- package/src/types/helper.ts +87 -0
- package/src/types/index.ts +5 -0
- package/src/types/options.ts +189 -0
- package/src/types/plugins.ts +538 -0
- package/src/utils/env.ts +103 -0
- package/src/utils/hide-metadata.ts +21 -0
- package/src/utils/index.ts +17 -0
- package/src/utils/ip.ts +45 -0
- package/src/utils/json.ts +19 -0
- package/src/utils/logger.ts +252 -0
- package/src/utils/url.ts +194 -0
- package/src/utils/wildcard.ts +253 -0
- package/tsconfig.json +12 -0
- package/vitest.config.ts +14 -0
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Database Schema Type Definitions
|
|
3
|
+
*
|
|
4
|
+
* This module contains base type definitions for database schema configuration.
|
|
5
|
+
* These types define the common structure of entity configurations used throughout
|
|
6
|
+
* the c15t consent management system.
|
|
7
|
+
*/
|
|
8
|
+
import type { Field } from '~/db/core/fields';
|
|
9
|
+
|
|
10
|
+
import type { AuditLogEntityConfig } from './audit-log/types';
|
|
11
|
+
import type { ConsentGeoLocationEntityConfig } from './consent-geo-location/types';
|
|
12
|
+
import type { ConsentPolicyEntityConfig } from './consent-policy/types';
|
|
13
|
+
import type { ConsentPurposeJunctionEntityConfig } from './consent-purpose-junction/types';
|
|
14
|
+
import type { ConsentPurposeEntityConfig } from './consent-purpose/types';
|
|
15
|
+
import type { ConsentRecordEntityConfig } from './consent-record/types';
|
|
16
|
+
import type { ConsentWithdrawalEntityConfig } from './consent-withdrawal/types';
|
|
17
|
+
import type { ConsentEntityConfig } from './consent/types';
|
|
18
|
+
import type { DomainEntityConfig } from './domain/types';
|
|
19
|
+
import type { GeoLocationEntityConfig } from './geo-location/types';
|
|
20
|
+
import type { SubjectEntityConfig } from './subject/types';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Base entity configuration shared by all entities
|
|
24
|
+
* Provides common configuration options for database entities
|
|
25
|
+
*/
|
|
26
|
+
export interface BaseEntityConfig {
|
|
27
|
+
/**
|
|
28
|
+
* Custom model name for the entity table
|
|
29
|
+
*/
|
|
30
|
+
entityName?: string;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The ID prefix for the entity table
|
|
34
|
+
* Used to generate unique prefixed IDs
|
|
35
|
+
*/
|
|
36
|
+
entityPrefix?: string;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Custom field names for the entity table
|
|
40
|
+
*/
|
|
41
|
+
fields?: Record<string, string>;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Additional fields for the entity table
|
|
45
|
+
*/
|
|
46
|
+
additionalFields?: Record<string, Field>;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Entity configuration with standard timestamps
|
|
51
|
+
* Extends base configuration with created/updated timestamp fields
|
|
52
|
+
*/
|
|
53
|
+
export interface TimestampedEntityConfig extends BaseEntityConfig {
|
|
54
|
+
fields?: Record<string, string> & {
|
|
55
|
+
createdAt?: string;
|
|
56
|
+
updatedAt?: string;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Entity configuration for entities with active status
|
|
62
|
+
* Extends timestamped configuration with isActive field
|
|
63
|
+
*/
|
|
64
|
+
export interface ActiveEntityConfig extends TimestampedEntityConfig {
|
|
65
|
+
fields?: Record<string, string> & {
|
|
66
|
+
createdAt?: string;
|
|
67
|
+
updatedAt?: string;
|
|
68
|
+
isActive?: string;
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Database tables configuration
|
|
74
|
+
* Contains all entity table configurations in one unified object
|
|
75
|
+
*/
|
|
76
|
+
export interface TablesConfig {
|
|
77
|
+
/**
|
|
78
|
+
* Subject entity configuration
|
|
79
|
+
* @default entityName: "subject", entityPrefix: "sub"
|
|
80
|
+
*/
|
|
81
|
+
subject?: SubjectEntityConfig;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Domain configuration
|
|
85
|
+
* @default entityName: "domain", entityPrefix: "dom"
|
|
86
|
+
*/
|
|
87
|
+
domain?: DomainEntityConfig;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Geo location configuration
|
|
91
|
+
* @default entityName: "geoLocation", entityPrefix: "geo"
|
|
92
|
+
*/
|
|
93
|
+
geoLocation?: GeoLocationEntityConfig;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* ConsentPurpose entity configuration
|
|
97
|
+
* @default entityName: "consentPurpose", entityPrefix: "pur"
|
|
98
|
+
*/
|
|
99
|
+
consentPurpose?: ConsentPurposeEntityConfig;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Consent policy configuration
|
|
103
|
+
* @default entityName: "consentPolicy", entityPrefix: "pol"
|
|
104
|
+
*/
|
|
105
|
+
consentPolicy?: ConsentPolicyEntityConfig;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Consent configuration
|
|
109
|
+
* @default entityName: "consent", entityPrefix: "cns"
|
|
110
|
+
*/
|
|
111
|
+
consent?: ConsentEntityConfig;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* ConsentPurpose junction configuration
|
|
115
|
+
* @default entityName: "consentPurposeJunction", entityPrefix: "pjx"
|
|
116
|
+
*/
|
|
117
|
+
consentPurposeJunction?: ConsentPurposeJunctionEntityConfig;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Consent geo location configuration
|
|
121
|
+
* @default entityName: "consentGeoLocation", entityPrefix: "cgl"
|
|
122
|
+
*/
|
|
123
|
+
consentGeoLocation?: ConsentGeoLocationEntityConfig;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Record entity configuration
|
|
127
|
+
* @default entityName: "record", entityPrefix: "rec"
|
|
128
|
+
*/
|
|
129
|
+
record?: ConsentRecordEntityConfig;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Withdrawal configuration
|
|
133
|
+
* @default entityName: "consentWithdrawal", entityPrefix: "wdr"
|
|
134
|
+
*/
|
|
135
|
+
consentWithdrawal?: ConsentWithdrawalEntityConfig;
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Audit log configuration
|
|
139
|
+
* @default entityName: "auditLog", entityPrefix: "log"
|
|
140
|
+
*/
|
|
141
|
+
auditLog?: AuditLogEntityConfig;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export type { AuditLogEntityConfig } from './audit-log/types';
|
|
145
|
+
export type { ConsentEntityConfig } from './consent/types';
|
|
146
|
+
export type { ConsentGeoLocationEntityConfig } from './consent-geo-location/types';
|
|
147
|
+
export type { ConsentPolicyEntityConfig } from './consent-policy/types';
|
|
148
|
+
export type { ConsentPurposeEntityConfig } from './consent-purpose/types';
|
|
149
|
+
export type { ConsentPurposeJunctionEntityConfig } from './consent-purpose-junction/types';
|
|
150
|
+
export type { ConsentRecordEntityConfig } from './consent-record/types';
|
|
151
|
+
export type { ConsentWithdrawalEntityConfig } from './consent-withdrawal/types';
|
|
152
|
+
export type { DomainEntityConfig } from './domain/types';
|
|
153
|
+
export type { GeoLocationEntityConfig } from './geo-location/types';
|
|
154
|
+
export type { SubjectEntityConfig } from './subject/types';
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { getConsentTables } from '~/db';
|
|
2
|
+
import { kyselyAdapter } from '~/db/adapters/kysely-adapter';
|
|
3
|
+
import { createKyselyAdapter } from '~/db/adapters/kysely-adapter/dialect';
|
|
4
|
+
import { memoryAdapter } from '~/db/adapters/memory-adapter';
|
|
5
|
+
import { BASE_ERROR_CODES, C15TError } from '~/error';
|
|
6
|
+
import type { C15TOptions } from '~/types';
|
|
7
|
+
import { createLogger } from '~/utils/logger';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Creates and configures the appropriate database adapter based on C15T options
|
|
11
|
+
*
|
|
12
|
+
* This function handles several scenarios:
|
|
13
|
+
* 1. No database configuration - creates an in-memory adapter (development only)
|
|
14
|
+
* 2. Custom database function - uses the provided function to create an adapter
|
|
15
|
+
* 3. Standard database config - creates a Kysely adapter with the specified database
|
|
16
|
+
*
|
|
17
|
+
* @param options - The C15T configuration options
|
|
18
|
+
* @returns A configured database adapter instance
|
|
19
|
+
* @throws {C15TError} If the database adapter initialization fails
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const adapter = await getAdapter(config);
|
|
24
|
+
* const subjects = await adapter.findMany('subject', { where: { active: true } });
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export async function getAdapter(options: C15TOptions) {
|
|
28
|
+
const logger = createLogger();
|
|
29
|
+
|
|
30
|
+
// If no database is configured, use an in-memory adapter for development
|
|
31
|
+
if (!options.database) {
|
|
32
|
+
const tables = getConsentTables(options);
|
|
33
|
+
const memoryDB = Object.keys(tables).reduce<Record<string, []>>(
|
|
34
|
+
(acc, key) => {
|
|
35
|
+
acc[key] = [];
|
|
36
|
+
return acc;
|
|
37
|
+
},
|
|
38
|
+
{}
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
logger.warn(
|
|
42
|
+
'No database configuration provided. Using memory adapter in development'
|
|
43
|
+
);
|
|
44
|
+
return memoryAdapter(memoryDB)(options);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// If a custom database function is provided, use it directly
|
|
48
|
+
if (typeof options.database === 'function') {
|
|
49
|
+
return options.database(options);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Otherwise, create a Kysely adapter
|
|
53
|
+
const { kysely, databaseType } = await createKyselyAdapter(options);
|
|
54
|
+
if (!kysely) {
|
|
55
|
+
throw new C15TError('Failed to initialize database adapter', {
|
|
56
|
+
code: BASE_ERROR_CODES.INTERNAL_SERVER_ERROR,
|
|
57
|
+
status: 500,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return kyselyAdapter(kysely, {
|
|
62
|
+
type: databaseType || 'sqlite',
|
|
63
|
+
})(options);
|
|
64
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Database Utilities Module
|
|
3
|
+
*
|
|
4
|
+
* This module provides various utility functions for database operations,
|
|
5
|
+
* including adapter creation and data conversion between application and database formats.
|
|
6
|
+
*
|
|
7
|
+
* @module db/utils
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export { getAdapter } from './adapter-factory';
|
package/src/db/utils.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { BASE_ERROR_CODES, C15TError } from '~/error';
|
|
2
|
+
import type { C15TOptions } from '~/types';
|
|
3
|
+
import { logger } from '../utils';
|
|
4
|
+
import { kyselyAdapter } from './adapters/kysely-adapter';
|
|
5
|
+
import { createKyselyAdapter } from './adapters/kysely-adapter/dialect';
|
|
6
|
+
import { memoryAdapter } from './adapters/memory-adapter';
|
|
7
|
+
import type { Adapter } from './adapters/types';
|
|
8
|
+
import { getConsentTables } from './index';
|
|
9
|
+
|
|
10
|
+
export async function getAdapter(options: C15TOptions): Promise<Adapter> {
|
|
11
|
+
if (!options.database) {
|
|
12
|
+
const tables = getConsentTables(options);
|
|
13
|
+
const memoryDB = Object.keys(tables).reduce<Record<string, unknown[]>>(
|
|
14
|
+
(acc, key) => {
|
|
15
|
+
acc[key] = [];
|
|
16
|
+
return acc;
|
|
17
|
+
},
|
|
18
|
+
{}
|
|
19
|
+
);
|
|
20
|
+
logger.warn(
|
|
21
|
+
'No database configuration provided. Using memory adapter in development'
|
|
22
|
+
);
|
|
23
|
+
return memoryAdapter(memoryDB as Record<string, Record<string, unknown>[]>)(
|
|
24
|
+
options
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (typeof options.database === 'function') {
|
|
29
|
+
return options.database(options);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const { kysely, databaseType } = await createKyselyAdapter(options);
|
|
33
|
+
if (!kysely) {
|
|
34
|
+
throw new C15TError('Failed to initialize database adapter', {
|
|
35
|
+
code: BASE_ERROR_CODES.INTERNAL_SERVER_ERROR,
|
|
36
|
+
status: 500,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return kyselyAdapter(kysely, {
|
|
40
|
+
type: databaseType || 'sqlite',
|
|
41
|
+
})(options);
|
|
42
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# Advanced JSON and Date Handling in C15T
|
|
2
|
+
|
|
3
|
+
C15T provides intelligent, database-specific handling for JSON data and date/time values to ensure maximum compatibility and performance across different database systems. This document explains how data is stored and accessed in different database environments.
|
|
4
|
+
|
|
5
|
+
## SuperJSON Integration
|
|
6
|
+
|
|
7
|
+
C15T uses [SuperJSON](https://github.com/blitz-js/superjson) to enhance JSON serialization for complex JavaScript types that aren't natively supported by JSON, such as:
|
|
8
|
+
|
|
9
|
+
- `Date` objects with timezone information
|
|
10
|
+
- JavaScript `Map` and `Set` objects
|
|
11
|
+
- `BigInt` values
|
|
12
|
+
- `undefined` values
|
|
13
|
+
- Custom class instances
|
|
14
|
+
- And more
|
|
15
|
+
|
|
16
|
+
## Database-Specific Behavior
|
|
17
|
+
|
|
18
|
+
### PostgreSQL
|
|
19
|
+
|
|
20
|
+
PostgreSQL has excellent native support for both JSON and timestamps with timezone:
|
|
21
|
+
|
|
22
|
+
- **JSON fields**: Uses native JSONB type for most JSON data, with SuperJSON only applied when needed for complex JS types
|
|
23
|
+
- **Date fields**: Uses native TIMESTAMPTZ which properly preserves timezone information
|
|
24
|
+
- **Benefits**: Offers high performance and the ability to perform JSON path queries directly in the database
|
|
25
|
+
|
|
26
|
+
### MySQL
|
|
27
|
+
|
|
28
|
+
MySQL has native JSON support but more limited date/timezone handling:
|
|
29
|
+
|
|
30
|
+
- **JSON fields**: Uses native JSON type with SuperJSON selectively applied for complex types
|
|
31
|
+
- **Date fields**: Uses consistent timezone handling to ensure predictable behavior
|
|
32
|
+
- **Benefits**: Provides good balance between native database features and JavaScript type support
|
|
33
|
+
|
|
34
|
+
### SQLite
|
|
35
|
+
|
|
36
|
+
SQLite has no native JSON or timezone-aware date types:
|
|
37
|
+
|
|
38
|
+
- **JSON fields**: Always uses SuperJSON format stored as TEXT to preserve all JavaScript types
|
|
39
|
+
- **Date fields**: Uses special handling to maintain timezone information
|
|
40
|
+
- **Benefits**: Maintains complete JavaScript data structures even with SQLite's simpler type system
|
|
41
|
+
|
|
42
|
+
## Implications for Your Application
|
|
43
|
+
|
|
44
|
+
### Accessing Data Outside C15T
|
|
45
|
+
|
|
46
|
+
When accessing data stored by C15T from outside the library (e.g., direct database queries), be aware:
|
|
47
|
+
|
|
48
|
+
- **PostgreSQL data**: Most fields can be accessed directly without special handling
|
|
49
|
+
- **MySQL data**: Complex values might be in SuperJSON format (look for `{"json":..., "meta":...}` structure)
|
|
50
|
+
- **SQLite data**: All JSON and date fields will be in SuperJSON format and require parsing
|
|
51
|
+
|
|
52
|
+
To parse SuperJSON data outside of C15T:
|
|
53
|
+
|
|
54
|
+
```javascript
|
|
55
|
+
// If using SuperJSON
|
|
56
|
+
const data = superjson.parse(valueFromDatabase);
|
|
57
|
+
|
|
58
|
+
// Without SuperJSON, you can manually extract the data
|
|
59
|
+
const parsed = JSON.parse(valueFromDatabase);
|
|
60
|
+
const actualData = parsed.json; // The actual data is in the 'json' property
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Best Practices
|
|
64
|
+
|
|
65
|
+
1. **Use C15T's API** when possible to abstract away database differences
|
|
66
|
+
2. **Document data format** if you expect other systems to access the database directly
|
|
67
|
+
3. **Consider database requirements** when designing systems that need to use multiple database types
|
|
68
|
+
4. **Test across databases** if your application needs to support multiple database types
|
|
69
|
+
|
|
70
|
+
## Configuration
|
|
71
|
+
|
|
72
|
+
The database-specific handling is applied automatically based on your database configuration when you initialize C15T.
|
|
73
|
+
|
|
74
|
+
If needed, you can manually set the database type:
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
import { setDatabaseType } from '@c15t/backend/db/core/fields/superjson-utils';
|
|
78
|
+
|
|
79
|
+
// Must be called before using any field operations
|
|
80
|
+
setDatabaseType('sqlite'); // or 'postgresql', 'mysql'
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Extending SuperJSON
|
|
84
|
+
|
|
85
|
+
If you need to support additional custom types with SuperJSON, you can register them:
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
import superjson from 'superjson';
|
|
89
|
+
|
|
90
|
+
// Register a custom type
|
|
91
|
+
superjson.registerCustom<MyCustomType, string>(
|
|
92
|
+
// isMyType check
|
|
93
|
+
(v) => v instanceof MyCustomType,
|
|
94
|
+
// serialize
|
|
95
|
+
(v) => v.toString(),
|
|
96
|
+
// deserialize
|
|
97
|
+
(v) => new MyCustomType(v)
|
|
98
|
+
);
|
|
99
|
+
```
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
# Using neverthrow in c15t
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
The c15t library now supports a functional approach to error handling using the [neverthrow](https://github.com/supermacro/neverthrow) library. This approach provides several benefits:
|
|
6
|
+
|
|
7
|
+
- More explicit error handling with the `Result` type
|
|
8
|
+
- Better type safety and compile-time checks for error cases
|
|
9
|
+
- Ability to chain operations with proper error propagation
|
|
10
|
+
- No need for try/catch blocks or exception handling
|
|
11
|
+
- Clearer and more predictable code flow
|
|
12
|
+
|
|
13
|
+
This document explains how to use the neverthrow `Result` pattern with c15t.
|
|
14
|
+
|
|
15
|
+
## Basic Concepts
|
|
16
|
+
|
|
17
|
+
The core concept of neverthrow is the `Result` type, which represents either:
|
|
18
|
+
|
|
19
|
+
- A successful operation (`Ok` variant) containing a value, or
|
|
20
|
+
- A failed operation (`Err` variant) containing an error
|
|
21
|
+
|
|
22
|
+
Instead of throwing exceptions, functions return a `Result` that must be handled explicitly.
|
|
23
|
+
|
|
24
|
+
### Result vs Traditional Error Handling
|
|
25
|
+
|
|
26
|
+
Traditional approach:
|
|
27
|
+
```typescript
|
|
28
|
+
try {
|
|
29
|
+
const context = await init(options);
|
|
30
|
+
// Use context...
|
|
31
|
+
} catch (error) {
|
|
32
|
+
// Handle errors...
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
neverthrow approach:
|
|
37
|
+
```typescript
|
|
38
|
+
const contextResult = await init(options);
|
|
39
|
+
contextResult.match({
|
|
40
|
+
ok: (context) => {
|
|
41
|
+
// Use context...
|
|
42
|
+
},
|
|
43
|
+
err: (error) => {
|
|
44
|
+
// Handle errors...
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Using c15t with neverthrow
|
|
50
|
+
|
|
51
|
+
### Initialization
|
|
52
|
+
|
|
53
|
+
The c15t library provides two versions of most core functions:
|
|
54
|
+
|
|
55
|
+
1. Traditional functions that might throw exceptions (for backward compatibility)
|
|
56
|
+
2. New functions with the `WithResult` suffix that return `Result` objects
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
import { c15tWithResult } from '@c15t/backend';
|
|
60
|
+
import { memoryAdapter } from '@c15t/backend/db/adapters/memory';
|
|
61
|
+
|
|
62
|
+
// Create a c15t instance with Result-based error handling
|
|
63
|
+
const c15tInstance = c15tWithResult({
|
|
64
|
+
secret: 'your-secret-key',
|
|
65
|
+
storage: memoryAdapter(),
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
// The context is now a ResultAsync
|
|
69
|
+
c15tInstance.$context.match({
|
|
70
|
+
ok: (context) => {
|
|
71
|
+
console.log(`Initialized ${context.appName} successfully`);
|
|
72
|
+
},
|
|
73
|
+
err: (error) => {
|
|
74
|
+
console.error(`Initialization failed: ${error.message}`);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Request Handling
|
|
80
|
+
|
|
81
|
+
The Result-based instance provides both traditional and Result-based handlers:
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
// Traditional approach (might throw)
|
|
85
|
+
app.use('/api/c15t', async (req, res) => {
|
|
86
|
+
try {
|
|
87
|
+
const response = await c15tInstance.handler(request);
|
|
88
|
+
// Handle response...
|
|
89
|
+
} catch (error) {
|
|
90
|
+
// Handle error...
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// Result-based approach
|
|
95
|
+
app.use('/api/c15t', async (req, res) => {
|
|
96
|
+
const requestResult = await c15tInstance.handlerWithResult(request);
|
|
97
|
+
|
|
98
|
+
requestResult.match({
|
|
99
|
+
ok: (response) => {
|
|
100
|
+
// Handle successful response...
|
|
101
|
+
},
|
|
102
|
+
err: (error) => {
|
|
103
|
+
// Handle error with structured data...
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Error Types
|
|
110
|
+
|
|
111
|
+
All errors are instances of `C15TError` with properties:
|
|
112
|
+
|
|
113
|
+
- `message`: Human-readable error message
|
|
114
|
+
- `code`: Error code from `BASE_ERROR_CODES`
|
|
115
|
+
- `status`: HTTP status code when applicable
|
|
116
|
+
- `data`: Additional error data
|
|
117
|
+
|
|
118
|
+
### Chaining Operations
|
|
119
|
+
|
|
120
|
+
One of the major benefits of the neverthrow approach is the ability to chain operations with proper error handling:
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
c15tInstance.$context
|
|
124
|
+
.andThen(context => {
|
|
125
|
+
// Use context to perform another operation
|
|
126
|
+
return c15tInstance.handlerWithResult(request);
|
|
127
|
+
})
|
|
128
|
+
.map(response => {
|
|
129
|
+
// Transform successful response
|
|
130
|
+
return response.json();
|
|
131
|
+
})
|
|
132
|
+
.mapErr(error => {
|
|
133
|
+
// Transform or enrich error
|
|
134
|
+
console.error(`Error: ${error.message}`);
|
|
135
|
+
return error;
|
|
136
|
+
});
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Combining with Promises
|
|
140
|
+
|
|
141
|
+
You can convert between Results and Promises:
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
import { toPromise, fromC15TPromise } from '@c15t/backend/utils';
|
|
145
|
+
|
|
146
|
+
// Convert Result to Promise (might throw)
|
|
147
|
+
const contextPromise = toPromise(c15tInstance.$context);
|
|
148
|
+
|
|
149
|
+
// Convert Promise to Result
|
|
150
|
+
const resultFromPromise = fromC15TPromise(somePromise);
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Complete Example
|
|
154
|
+
|
|
155
|
+
See the complete example at `packages/c15t/src/examples/neverthrow-example.ts`.
|
|
156
|
+
|
|
157
|
+
## Best Practices
|
|
158
|
+
|
|
159
|
+
1. **Be explicit about errors**: Use the `match` method to handle both success and error cases explicitly.
|
|
160
|
+
|
|
161
|
+
2. **Chain operations**: Use `andThen`, `map`, and `mapErr` to chain operations and transformations.
|
|
162
|
+
|
|
163
|
+
3. **Type your errors**: Make use of error codes to handle specific error conditions.
|
|
164
|
+
|
|
165
|
+
4. **Avoid mixing patterns**: Stick to either the Result pattern or traditional try/catch within a single function.
|
|
166
|
+
|
|
167
|
+
5. **Convert at boundaries**: Use conversion utilities when interacting with code that doesn't use the Result pattern.
|
|
168
|
+
|
|
169
|
+
## Backward Compatibility
|
|
170
|
+
|
|
171
|
+
The c15t library maintains backward compatibility with the traditional error handling approach. You can continue using the existing API, or gradually migrate to the Result pattern.
|