neoorm 0.7.4 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -5
- package/dist/bin/neoorm.js +60 -52
- package/dist/bin/neoorm.js.map +1 -1
- package/dist/codegen/diff-manifest.d.ts.map +1 -1
- package/dist/codegen/diff-manifest.js +55 -30
- package/dist/codegen/diff-manifest.js.map +1 -1
- package/dist/codegen/emit-includes.d.ts.map +1 -1
- package/dist/codegen/emit-includes.js +6 -6
- package/dist/codegen/emit-includes.js.map +1 -1
- package/dist/codegen/emit-models.d.ts.map +1 -1
- package/dist/codegen/emit-models.js +14 -14
- package/dist/codegen/emit-models.js.map +1 -1
- package/dist/codegen/generate-summary.d.ts +4 -1
- package/dist/codegen/generate-summary.d.ts.map +1 -1
- package/dist/codegen/generate-summary.js +7 -1
- package/dist/codegen/generate-summary.js.map +1 -1
- package/dist/codegen/generate.d.ts +28 -4
- package/dist/codegen/generate.d.ts.map +1 -1
- package/dist/codegen/generate.js +142 -19
- package/dist/codegen/generate.js.map +1 -1
- package/dist/codegen/manifest-relations.d.ts +4 -1
- package/dist/codegen/manifest-relations.d.ts.map +1 -1
- package/dist/codegen/manifest-relations.js +6 -28
- package/dist/codegen/manifest-relations.js.map +1 -1
- package/dist/codegen/schema-to-manifest.d.ts +4 -3
- package/dist/codegen/schema-to-manifest.d.ts.map +1 -1
- package/dist/codegen/schema-to-manifest.js +57 -46
- package/dist/codegen/schema-to-manifest.js.map +1 -1
- package/dist/codegen/validation/emit-typebox.d.ts +4 -0
- package/dist/codegen/validation/emit-typebox.d.ts.map +1 -0
- package/dist/codegen/validation/emit-typebox.js +360 -0
- package/dist/codegen/validation/emit-typebox.js.map +1 -0
- package/dist/codegen/validation/emit-zod.d.ts +4 -0
- package/dist/codegen/validation/emit-zod.d.ts.map +1 -0
- package/dist/codegen/validation/emit-zod.js +288 -0
- package/dist/codegen/validation/emit-zod.js.map +1 -0
- package/dist/codegen/validation/from-manifest.d.ts +5 -0
- package/dist/codegen/validation/from-manifest.d.ts.map +1 -0
- package/dist/codegen/validation/from-manifest.js +284 -0
- package/dist/codegen/validation/from-manifest.js.map +1 -0
- package/dist/codegen/validation/infer.d.ts +47 -0
- package/dist/codegen/validation/infer.d.ts.map +1 -0
- package/dist/codegen/validation/infer.js +2 -0
- package/dist/codegen/validation/infer.js.map +1 -0
- package/dist/codegen/validation/json-generic-types.d.ts +7 -0
- package/dist/codegen/validation/json-generic-types.d.ts.map +1 -0
- package/dist/codegen/validation/json-generic-types.js +295 -0
- package/dist/codegen/validation/json-generic-types.js.map +1 -0
- package/dist/codegen/validation/types.d.ts +84 -0
- package/dist/codegen/validation/types.d.ts.map +1 -0
- package/dist/codegen/validation/types.js +6 -0
- package/dist/codegen/validation/types.js.map +1 -0
- package/dist/config.d.ts +12 -2
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +49 -13
- package/dist/config.js.map +1 -1
- package/dist/datasource-provider.d.ts +7 -0
- package/dist/datasource-provider.d.ts.map +1 -0
- package/dist/datasource-provider.js +11 -0
- package/dist/datasource-provider.js.map +1 -0
- package/dist/dialect/fk.d.ts.map +1 -1
- package/dist/dialect/fk.js +4 -2
- package/dist/dialect/fk.js.map +1 -1
- package/dist/dialect/index.d.ts +1 -0
- package/dist/dialect/index.d.ts.map +1 -1
- package/dist/dialect/index.js +1 -0
- package/dist/dialect/index.js.map +1 -1
- package/dist/dialect/postgres.d.ts +2 -1
- package/dist/dialect/postgres.d.ts.map +1 -1
- package/dist/dialect/postgres.js +49 -18
- package/dist/dialect/postgres.js.map +1 -1
- package/dist/dialect/shared.d.ts +3 -1
- package/dist/dialect/shared.d.ts.map +1 -1
- package/dist/dialect/shared.js +4 -0
- package/dist/dialect/shared.js.map +1 -1
- package/dist/dialect/sqlite.d.ts.map +1 -1
- package/dist/dialect/sqlite.js +15 -18
- package/dist/dialect/sqlite.js.map +1 -1
- package/dist/dialect/sqlite.test.d.ts +2 -0
- package/dist/dialect/sqlite.test.d.ts.map +1 -0
- package/dist/dialect/sqlite.test.js +122 -0
- package/dist/dialect/sqlite.test.js.map +1 -0
- package/dist/dialect/types.d.ts +16 -1
- package/dist/dialect/types.d.ts.map +1 -1
- package/dist/docs/pages.d.ts.map +1 -1
- package/dist/docs/pages.js +2 -0
- package/dist/docs/pages.js.map +1 -1
- package/dist/docs/render.d.ts.map +1 -1
- package/dist/docs/render.js.map +1 -1
- package/dist/docs/search.d.ts.map +1 -1
- package/dist/docs/search.js +4 -4
- package/dist/docs/search.js.map +1 -1
- package/dist/docs/server.d.ts.map +1 -1
- package/dist/docs/server.js +3 -3
- package/dist/docs/server.js.map +1 -1
- package/dist/index.d.ts +13 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -4
- package/dist/index.js.map +1 -1
- package/dist/init/scaffold.d.ts.map +1 -1
- package/dist/init/scaffold.js +3 -1
- package/dist/init/scaffold.js.map +1 -1
- package/dist/init/templates.d.ts.map +1 -1
- package/dist/init/templates.js +1 -0
- package/dist/init/templates.js.map +1 -1
- package/dist/introspect/pull.d.ts.map +1 -1
- package/dist/introspect/pull.js +217 -158
- package/dist/introspect/pull.js.map +1 -1
- package/dist/introspect/queries.d.ts +7 -0
- package/dist/introspect/queries.d.ts.map +1 -1
- package/dist/introspect/queries.js +21 -1
- package/dist/introspect/queries.js.map +1 -1
- package/dist/introspect/sqlite/to-manifest.d.ts.map +1 -1
- package/dist/introspect/sqlite/to-manifest.js +6 -9
- package/dist/introspect/sqlite/to-manifest.js.map +1 -1
- package/dist/introspect/to-manifest.d.ts +8 -1
- package/dist/introspect/to-manifest.d.ts.map +1 -1
- package/dist/introspect/to-manifest.js +105 -23
- package/dist/introspect/to-manifest.js.map +1 -1
- package/dist/migrate/runner.d.ts +16 -0
- package/dist/migrate/runner.d.ts.map +1 -1
- package/dist/migrate/runner.js +147 -24
- package/dist/migrate/runner.js.map +1 -1
- package/dist/plugins/builtin.d.ts +20 -12
- package/dist/plugins/builtin.d.ts.map +1 -1
- package/dist/plugins/builtin.js +117 -38
- package/dist/plugins/builtin.js.map +1 -1
- package/dist/plugins/index.d.ts +1 -0
- package/dist/plugins/index.d.ts.map +1 -1
- package/dist/plugins/index.js.map +1 -1
- package/dist/plugins/json/operators.d.ts.map +1 -1
- package/dist/plugins/json/operators.js +100 -27
- package/dist/plugins/json/operators.js.map +1 -1
- package/dist/plugins/postgis/columns.d.ts +18 -4
- package/dist/plugins/postgis/columns.d.ts.map +1 -1
- package/dist/plugins/postgis/columns.js +121 -10
- package/dist/plugins/postgis/columns.js.map +1 -1
- package/dist/plugins/postgis/columns.test.d.ts +2 -0
- package/dist/plugins/postgis/columns.test.d.ts.map +1 -0
- package/dist/plugins/postgis/columns.test.js +80 -0
- package/dist/plugins/postgis/columns.test.js.map +1 -0
- package/dist/plugins/postgis/index.d.ts +4 -2
- package/dist/plugins/postgis/index.d.ts.map +1 -1
- package/dist/plugins/postgis/index.js +2 -1
- package/dist/plugins/postgis/index.js.map +1 -1
- package/dist/plugins/postgis/where-types.d.ts +18 -0
- package/dist/plugins/postgis/where-types.d.ts.map +1 -0
- package/dist/plugins/postgis/where-types.js +2 -0
- package/dist/plugins/postgis/where-types.js.map +1 -0
- package/dist/plugins/registry.d.ts.map +1 -1
- package/dist/plugins/registry.js +20 -5
- package/dist/plugins/registry.js.map +1 -1
- package/dist/plugins/types.d.ts +4 -1
- package/dist/plugins/types.d.ts.map +1 -1
- package/dist/runtime/client.d.ts +60 -11
- package/dist/runtime/client.d.ts.map +1 -1
- package/dist/runtime/client.js +87 -41
- package/dist/runtime/client.js.map +1 -1
- package/dist/runtime/client.test.d.ts +2 -0
- package/dist/runtime/client.test.d.ts.map +1 -0
- package/dist/runtime/client.test.js +170 -0
- package/dist/runtime/client.test.js.map +1 -0
- package/dist/runtime/compile-error.d.ts +14 -0
- package/dist/runtime/compile-error.d.ts.map +1 -0
- package/dist/runtime/compile-error.js +14 -0
- package/dist/runtime/compile-error.js.map +1 -0
- package/dist/runtime/driver-sqlite.test.d.ts +2 -0
- package/dist/runtime/driver-sqlite.test.d.ts.map +1 -0
- package/dist/runtime/driver-sqlite.test.js +195 -0
- package/dist/runtime/driver-sqlite.test.js.map +1 -0
- package/dist/runtime/driver.d.ts +16 -1
- package/dist/runtime/driver.d.ts.map +1 -1
- package/dist/runtime/driver.js +118 -96
- package/dist/runtime/driver.js.map +1 -1
- package/dist/runtime/error-builders.d.ts +7 -6
- package/dist/runtime/error-builders.d.ts.map +1 -1
- package/dist/runtime/error-builders.js +2 -2
- package/dist/runtime/error-builders.js.map +1 -1
- package/dist/runtime/error-codes.d.ts +50 -0
- package/dist/runtime/error-codes.d.ts.map +1 -0
- package/dist/runtime/error-codes.js +54 -0
- package/dist/runtime/error-codes.js.map +1 -0
- package/dist/runtime/error-hints.d.ts +1 -0
- package/dist/runtime/error-hints.d.ts.map +1 -1
- package/dist/runtime/error-hints.js +50 -11
- package/dist/runtime/error-hints.js.map +1 -1
- package/dist/runtime/errors.d.ts +55 -8
- package/dist/runtime/errors.d.ts.map +1 -1
- package/dist/runtime/errors.js +143 -12
- package/dist/runtime/errors.js.map +1 -1
- package/dist/runtime/errors.test.d.ts +2 -0
- package/dist/runtime/errors.test.d.ts.map +1 -0
- package/dist/runtime/errors.test.js +115 -0
- package/dist/runtime/errors.test.js.map +1 -0
- package/dist/runtime/executor.d.ts +22 -3
- package/dist/runtime/executor.d.ts.map +1 -1
- package/dist/runtime/executor.js +93 -39
- package/dist/runtime/executor.js.map +1 -1
- package/dist/runtime/parse-db-json.d.ts +8 -0
- package/dist/runtime/parse-db-json.d.ts.map +1 -0
- package/dist/runtime/parse-db-json.js +33 -0
- package/dist/runtime/parse-db-json.js.map +1 -0
- package/dist/runtime/pg-error.d.ts.map +1 -1
- package/dist/runtime/pg-error.js +16 -16
- package/dist/runtime/pg-error.js.map +1 -1
- package/dist/runtime/pg-rollback.test.d.ts +2 -0
- package/dist/runtime/pg-rollback.test.d.ts.map +1 -0
- package/dist/runtime/pg-rollback.test.js +39 -0
- package/dist/runtime/pg-rollback.test.js.map +1 -0
- package/dist/runtime/query/aggregate.d.ts.map +1 -1
- package/dist/runtime/query/aggregate.js +18 -7
- package/dist/runtime/query/aggregate.js.map +1 -1
- package/dist/runtime/query/compile-aggregate.d.ts +39 -0
- package/dist/runtime/query/compile-aggregate.d.ts.map +1 -0
- package/dist/runtime/query/compile-aggregate.js +458 -0
- package/dist/runtime/query/compile-aggregate.js.map +1 -0
- package/dist/runtime/query/compile-where.d.ts +32 -0
- package/dist/runtime/query/compile-where.d.ts.map +1 -0
- package/dist/runtime/query/compile-where.js +719 -0
- package/dist/runtime/query/compile-where.js.map +1 -0
- package/dist/runtime/query/compile-write.d.ts +53 -0
- package/dist/runtime/query/compile-write.d.ts.map +1 -0
- package/dist/runtime/query/compile-write.js +467 -0
- package/dist/runtime/query/compile-write.js.map +1 -0
- package/dist/runtime/query/compile.d.ts +3 -114
- package/dist/runtime/query/compile.d.ts.map +1 -1
- package/dist/runtime/query/compile.js +3 -1536
- package/dist/runtime/query/compile.js.map +1 -1
- package/dist/runtime/query/count.d.ts +1 -0
- package/dist/runtime/query/count.d.ts.map +1 -1
- package/dist/runtime/query/count.js +12 -14
- package/dist/runtime/query/count.js.map +1 -1
- package/dist/runtime/query/create.d.ts.map +1 -1
- package/dist/runtime/query/create.js +20 -49
- package/dist/runtime/query/create.js.map +1 -1
- package/dist/runtime/query/cursor-codec.d.ts.map +1 -1
- package/dist/runtime/query/cursor-codec.js +8 -2
- package/dist/runtime/query/cursor-codec.js.map +1 -1
- package/dist/runtime/query/cursor.d.ts.map +1 -1
- package/dist/runtime/query/cursor.js +31 -7
- package/dist/runtime/query/cursor.js.map +1 -1
- package/dist/runtime/query/delete.d.ts.map +1 -1
- package/dist/runtime/query/delete.js +17 -17
- package/dist/runtime/query/delete.js.map +1 -1
- package/dist/runtime/query/execute.d.ts.map +1 -1
- package/dist/runtime/query/execute.js +11 -12
- package/dist/runtime/query/execute.js.map +1 -1
- package/dist/runtime/query/find-or-create.d.ts +4 -2
- package/dist/runtime/query/find-or-create.d.ts.map +1 -1
- package/dist/runtime/query/find-or-create.js +53 -43
- package/dist/runtime/query/find-or-create.js.map +1 -1
- package/dist/runtime/query/find-or-create.test.d.ts +2 -0
- package/dist/runtime/query/find-or-create.test.d.ts.map +1 -0
- package/dist/runtime/query/find-or-create.test.js +189 -0
- package/dist/runtime/query/find-or-create.test.js.map +1 -0
- package/dist/runtime/query/find.d.ts.map +1 -1
- package/dist/runtime/query/find.js +95 -65
- package/dist/runtime/query/find.js.map +1 -1
- package/dist/runtime/query/group-by.d.ts.map +1 -1
- package/dist/runtime/query/group-by.js +3 -2
- package/dist/runtime/query/group-by.js.map +1 -1
- package/dist/runtime/query/manifest-lookup.d.ts.map +1 -1
- package/dist/runtime/query/manifest-lookup.js +1 -1
- package/dist/runtime/query/manifest-lookup.js.map +1 -1
- package/dist/runtime/query/map-row.d.ts.map +1 -1
- package/dist/runtime/query/map-row.js +1 -1
- package/dist/runtime/query/map-row.js.map +1 -1
- package/dist/runtime/query/paginate.d.ts +3 -0
- package/dist/runtime/query/paginate.d.ts.map +1 -1
- package/dist/runtime/query/paginate.js +49 -11
- package/dist/runtime/query/paginate.js.map +1 -1
- package/dist/runtime/query/primary-key.d.ts +1 -1
- package/dist/runtime/query/primary-key.d.ts.map +1 -1
- package/dist/runtime/query/primary-key.js +45 -8
- package/dist/runtime/query/primary-key.js.map +1 -1
- package/dist/runtime/query/projection.d.ts +1 -0
- package/dist/runtime/query/projection.d.ts.map +1 -1
- package/dist/runtime/query/projection.js +22 -6
- package/dist/runtime/query/projection.js.map +1 -1
- package/dist/runtime/query/relation-planner.d.ts.map +1 -1
- package/dist/runtime/query/relation-planner.js +86 -57
- package/dist/runtime/query/relation-planner.js.map +1 -1
- package/dist/runtime/query/relation-writes.d.ts +3 -1
- package/dist/runtime/query/relation-writes.d.ts.map +1 -1
- package/dist/runtime/query/relation-writes.js +157 -69
- package/dist/runtime/query/relation-writes.js.map +1 -1
- package/dist/runtime/query/serialize-dialect.test.d.ts +2 -0
- package/dist/runtime/query/serialize-dialect.test.d.ts.map +1 -0
- package/dist/runtime/query/serialize-dialect.test.js +79 -0
- package/dist/runtime/query/serialize-dialect.test.js.map +1 -0
- package/dist/runtime/query/sqlite-constraint-errors.test.d.ts +2 -0
- package/dist/runtime/query/sqlite-constraint-errors.test.d.ts.map +1 -0
- package/dist/runtime/query/sqlite-constraint-errors.test.js +60 -0
- package/dist/runtime/query/sqlite-constraint-errors.test.js.map +1 -0
- package/dist/runtime/query/strip.d.ts.map +1 -1
- package/dist/runtime/query/strip.js.map +1 -1
- package/dist/runtime/query/table-index.d.ts +1 -1
- package/dist/runtime/query/table-index.d.ts.map +1 -1
- package/dist/runtime/query/table-index.js +5 -4
- package/dist/runtime/query/table-index.js.map +1 -1
- package/dist/runtime/query/unique.d.ts +8 -1
- package/dist/runtime/query/unique.d.ts.map +1 -1
- package/dist/runtime/query/unique.js +89 -4
- package/dist/runtime/query/unique.js.map +1 -1
- package/dist/runtime/query/unique.test.d.ts +2 -0
- package/dist/runtime/query/unique.test.d.ts.map +1 -0
- package/dist/runtime/query/unique.test.js +231 -0
- package/dist/runtime/query/unique.test.js.map +1 -0
- package/dist/runtime/query/update.d.ts.map +1 -1
- package/dist/runtime/query/update.js +30 -35
- package/dist/runtime/query/update.js.map +1 -1
- package/dist/runtime/query/update.test.d.ts +2 -0
- package/dist/runtime/query/update.test.d.ts.map +1 -0
- package/dist/runtime/query/update.test.js +186 -0
- package/dist/runtime/query/update.test.js.map +1 -0
- package/dist/runtime/query/updated-at.d.ts.map +1 -1
- package/dist/runtime/query/updated-at.js.map +1 -1
- package/dist/runtime/query/upsert.d.ts.map +1 -1
- package/dist/runtime/query/upsert.js +5 -7
- package/dist/runtime/query/upsert.js.map +1 -1
- package/dist/runtime/schema-error.d.ts.map +1 -1
- package/dist/runtime/schema-error.js +6 -2
- package/dist/runtime/schema-error.js.map +1 -1
- package/dist/runtime/sqlite-error.d.ts.map +1 -1
- package/dist/runtime/sqlite-error.js +11 -12
- package/dist/runtime/sqlite-error.js.map +1 -1
- package/dist/runtime/sqlite-open.d.ts +2 -0
- package/dist/runtime/sqlite-open.d.ts.map +1 -1
- package/dist/runtime/sqlite-open.js +18 -1
- package/dist/runtime/sqlite-open.js.map +1 -1
- package/dist/runtime/transaction.d.ts +4 -0
- package/dist/runtime/transaction.d.ts.map +1 -1
- package/dist/runtime/transaction.js +31 -1
- package/dist/runtime/transaction.js.map +1 -1
- package/dist/runtime/transaction.test.d.ts +2 -0
- package/dist/runtime/transaction.test.d.ts.map +1 -0
- package/dist/runtime/transaction.test.js +43 -0
- package/dist/runtime/transaction.test.js.map +1 -0
- package/dist/runtime/types.d.ts +50 -17
- package/dist/runtime/types.d.ts.map +1 -1
- package/dist/schema/column-constraints.d.ts +26 -0
- package/dist/schema/column-constraints.d.ts.map +1 -0
- package/dist/schema/column-constraints.js +140 -0
- package/dist/schema/column-constraints.js.map +1 -0
- package/dist/schema/column-where.d.ts +11 -1
- package/dist/schema/column-where.d.ts.map +1 -1
- package/dist/schema/column.d.ts +91 -2
- package/dist/schema/column.d.ts.map +1 -1
- package/dist/schema/column.js +17 -11
- package/dist/schema/column.js.map +1 -1
- package/dist/schema/define-schema.d.ts +1 -1
- package/dist/schema/define-schema.d.ts.map +1 -1
- package/dist/schema/define-schema.js +5 -23
- package/dist/schema/define-schema.js.map +1 -1
- package/dist/schema/index.d.ts +7 -4
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema/index.js +7 -1
- package/dist/schema/index.js.map +1 -1
- package/dist/schema/json-column.d.ts +9 -0
- package/dist/schema/json-column.d.ts.map +1 -0
- package/dist/schema/json-column.js +11 -0
- package/dist/schema/json-column.js.map +1 -0
- package/dist/schema/many-to-many.d.ts +1 -1
- package/dist/schema/many-to-many.d.ts.map +1 -1
- package/dist/schema/nested-relation-types.d.ts.map +1 -1
- package/dist/schema/relation-types.d.ts +20 -24
- package/dist/schema/relation-types.d.ts.map +1 -1
- package/dist/schema/relation.d.ts.map +1 -1
- package/dist/schema/relation.js +6 -4
- package/dist/schema/relation.js.map +1 -1
- package/dist/schema/table-registry.d.ts.map +1 -1
- package/dist/schema/table-registry.js +8 -2
- package/dist/schema/table-registry.js.map +1 -1
- package/dist/schema/table.d.ts +6 -3
- package/dist/schema/table.d.ts.map +1 -1
- package/dist/schema/table.js +30 -31
- package/dist/schema/table.js.map +1 -1
- package/dist/schema/types.d.ts +39 -30
- package/dist/schema/types.d.ts.map +1 -1
- package/dist/sql/builder.d.ts +5 -1
- package/dist/sql/builder.d.ts.map +1 -1
- package/dist/sql/builder.js +23 -3
- package/dist/sql/builder.js.map +1 -1
- package/dist/sql/index.d.ts +5 -2
- package/dist/sql/index.d.ts.map +1 -1
- package/dist/sql/index.js +5 -2
- package/dist/sql/index.js.map +1 -1
- package/dist/utils/case.d.ts +4 -0
- package/dist/utils/case.d.ts.map +1 -1
- package/dist/utils/case.js +11 -0
- package/dist/utils/case.js.map +1 -1
- package/dist/utils/dotenv.d.ts +8 -0
- package/dist/utils/dotenv.d.ts.map +1 -0
- package/dist/utils/dotenv.js +70 -0
- package/dist/utils/dotenv.js.map +1 -0
- package/dist/utils/dotenv.test.d.ts +2 -0
- package/dist/utils/dotenv.test.d.ts.map +1 -0
- package/dist/utils/dotenv.test.js +32 -0
- package/dist/utils/dotenv.test.js.map +1 -0
- package/dist/utils/inflect.d.ts +6 -0
- package/dist/utils/inflect.d.ts.map +1 -0
- package/dist/utils/inflect.js +80 -0
- package/dist/utils/inflect.js.map +1 -0
- package/dist/utils/load-ts.d.ts +2 -1
- package/dist/utils/load-ts.d.ts.map +1 -1
- package/dist/utils/load-ts.js +13 -1
- package/dist/utils/load-ts.js.map +1 -1
- package/docs/cli.md +7 -3
- package/docs/configuration.md +9 -1
- package/docs/errors.md +61 -6
- package/docs/examples.md +63 -13
- package/docs/getting-started.md +48 -1
- package/docs/migrations.md +15 -2
- package/docs/plugins.md +15 -1
- package/docs/queries.md +109 -10
- package/docs/relations.md +5 -1
- package/docs/schema.md +42 -7
- package/docs/sqlite.md +32 -10
- package/docs/transactions.md +13 -2
- package/docs/typebox.md +139 -0
- package/docs/zod.md +128 -0
- package/package.json +19 -3
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
function emitLiteral(value) {
|
|
2
|
+
return `Type.Literal(${JSON.stringify(value)})`;
|
|
3
|
+
}
|
|
4
|
+
function emitOptions(fields) {
|
|
5
|
+
const entries = Object.entries(fields).filter((entry) => entry[1] !== undefined);
|
|
6
|
+
if (entries.length === 0) {
|
|
7
|
+
return undefined;
|
|
8
|
+
}
|
|
9
|
+
return `{ ${entries.map(([key, value]) => `${key}: ${value}`).join(", ")} }`;
|
|
10
|
+
}
|
|
11
|
+
function callType(name, options) {
|
|
12
|
+
return options !== undefined
|
|
13
|
+
? `Type.${name}(${options})`
|
|
14
|
+
: `Type.${name}()`;
|
|
15
|
+
}
|
|
16
|
+
function bigintLiteral(value) {
|
|
17
|
+
return `BigInt(${JSON.stringify(String(value))})`;
|
|
18
|
+
}
|
|
19
|
+
function numberLiteral(value) {
|
|
20
|
+
if (typeof value === "number") {
|
|
21
|
+
return String(value);
|
|
22
|
+
}
|
|
23
|
+
return String(Number(value));
|
|
24
|
+
}
|
|
25
|
+
function emitDecimalRefine(expr, constraints) {
|
|
26
|
+
const checks = [];
|
|
27
|
+
if (constraints.min !== undefined) {
|
|
28
|
+
checks.push(`Number(value) >= ${numberLiteral(constraints.min)}`);
|
|
29
|
+
}
|
|
30
|
+
if (constraints.max !== undefined) {
|
|
31
|
+
checks.push(`Number(value) <= ${numberLiteral(constraints.max)}`);
|
|
32
|
+
}
|
|
33
|
+
if (constraints.positive === true) {
|
|
34
|
+
checks.push("Number(value) > 0");
|
|
35
|
+
}
|
|
36
|
+
if (checks.length === 0) {
|
|
37
|
+
return expr;
|
|
38
|
+
}
|
|
39
|
+
return `Type.Refine(${expr}, (value) => ${checks.join(" && ")})`;
|
|
40
|
+
}
|
|
41
|
+
function emitString(type, constraints) {
|
|
42
|
+
const options = emitOptions({
|
|
43
|
+
format: type.format !== undefined ? JSON.stringify(type.format) : undefined,
|
|
44
|
+
minLength: constraints?.minLength !== undefined
|
|
45
|
+
? String(constraints.minLength)
|
|
46
|
+
: undefined,
|
|
47
|
+
maxLength: constraints?.maxLength !== undefined
|
|
48
|
+
? String(constraints.maxLength)
|
|
49
|
+
: undefined,
|
|
50
|
+
});
|
|
51
|
+
const expr = callType("String", options);
|
|
52
|
+
if (constraints !== undefined &&
|
|
53
|
+
(constraints.min !== undefined ||
|
|
54
|
+
constraints.max !== undefined ||
|
|
55
|
+
constraints.positive === true)) {
|
|
56
|
+
return emitDecimalRefine(expr, constraints);
|
|
57
|
+
}
|
|
58
|
+
return expr;
|
|
59
|
+
}
|
|
60
|
+
function emitNumber(type, constraints) {
|
|
61
|
+
const options = emitOptions({
|
|
62
|
+
minimum: constraints?.min !== undefined
|
|
63
|
+
? numberLiteral(constraints.min)
|
|
64
|
+
: undefined,
|
|
65
|
+
maximum: constraints?.max !== undefined
|
|
66
|
+
? numberLiteral(constraints.max)
|
|
67
|
+
: undefined,
|
|
68
|
+
exclusiveMinimum: constraints?.positive === true ? "0" : undefined,
|
|
69
|
+
});
|
|
70
|
+
return callType(type.int === true ? "Integer" : "Number", options);
|
|
71
|
+
}
|
|
72
|
+
function emitBigInt(constraints) {
|
|
73
|
+
const options = emitOptions({
|
|
74
|
+
minimum: constraints?.min !== undefined
|
|
75
|
+
? bigintLiteral(constraints.min)
|
|
76
|
+
: undefined,
|
|
77
|
+
maximum: constraints?.max !== undefined
|
|
78
|
+
? bigintLiteral(constraints.max)
|
|
79
|
+
: undefined,
|
|
80
|
+
exclusiveMinimum: constraints?.positive === true ? "0n" : undefined,
|
|
81
|
+
});
|
|
82
|
+
return callType("BigInt", options);
|
|
83
|
+
}
|
|
84
|
+
function emitType(type, constraints) {
|
|
85
|
+
switch (type.kind) {
|
|
86
|
+
case "string":
|
|
87
|
+
return emitString(type, constraints);
|
|
88
|
+
case "number":
|
|
89
|
+
return emitNumber(type, constraints);
|
|
90
|
+
case "bigint":
|
|
91
|
+
return emitBigInt(constraints);
|
|
92
|
+
case "boolean":
|
|
93
|
+
return "Type.Boolean()";
|
|
94
|
+
case "date":
|
|
95
|
+
return "dateValue";
|
|
96
|
+
case "enum":
|
|
97
|
+
return type.name !== undefined
|
|
98
|
+
? `${type.name}Schema`
|
|
99
|
+
: `Type.Enum(${JSON.stringify(type.values)})`;
|
|
100
|
+
case "unknown":
|
|
101
|
+
return "Type.Unknown()";
|
|
102
|
+
case "record": {
|
|
103
|
+
const keyExpr = type.key !== undefined ? emitType(type.key) : "Type.String()";
|
|
104
|
+
return `Type.Record(${keyExpr}, ${emitType(type.value)})`;
|
|
105
|
+
}
|
|
106
|
+
case "array":
|
|
107
|
+
return `Type.Array(${emitType(type.element)})`;
|
|
108
|
+
case "object":
|
|
109
|
+
return `Type.Object({ ${type.fields.map(emitFieldInline).join(", ")} })`;
|
|
110
|
+
case "union":
|
|
111
|
+
return `Type.Union([${type.variants.map((variant) => emitType(variant)).join(", ")}])`;
|
|
112
|
+
case "literal":
|
|
113
|
+
return emitLiteral(type.value);
|
|
114
|
+
case "tuple":
|
|
115
|
+
return `Type.Tuple([${type.elements.map((element) => emitType(element)).join(", ")}])`;
|
|
116
|
+
case "instance":
|
|
117
|
+
switch (type.tsName) {
|
|
118
|
+
case "Buffer":
|
|
119
|
+
return "bufferValue";
|
|
120
|
+
default: {
|
|
121
|
+
const _exhaustive = type.tsName;
|
|
122
|
+
return _exhaustive;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
default: {
|
|
126
|
+
const _exhaustive = type;
|
|
127
|
+
throw _exhaustive;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function emitFieldExpr(field) {
|
|
132
|
+
let expr = emitType(field.type, field.constraints);
|
|
133
|
+
if (field.nullable) {
|
|
134
|
+
expr = `Type.Union([${expr}, Type.Null()])`;
|
|
135
|
+
}
|
|
136
|
+
if (field.optional) {
|
|
137
|
+
expr = `Type.Optional(${expr})`;
|
|
138
|
+
}
|
|
139
|
+
return expr;
|
|
140
|
+
}
|
|
141
|
+
function emitFieldInline(field) {
|
|
142
|
+
return `${field.name}: ${emitFieldExpr(field)}`;
|
|
143
|
+
}
|
|
144
|
+
function emitObjectFields(fields) {
|
|
145
|
+
if (fields.length === 0) {
|
|
146
|
+
return "Type.Object({})";
|
|
147
|
+
}
|
|
148
|
+
const body = fields
|
|
149
|
+
.map((field) => ` ${field.name}: ${emitFieldExpr(field)},`)
|
|
150
|
+
.join("\n");
|
|
151
|
+
return `Type.Object({\n${body}\n})`;
|
|
152
|
+
}
|
|
153
|
+
function walkType(type, visit) {
|
|
154
|
+
visit(type);
|
|
155
|
+
switch (type.kind) {
|
|
156
|
+
case "record":
|
|
157
|
+
if (type.key !== undefined) {
|
|
158
|
+
walkType(type.key, visit);
|
|
159
|
+
}
|
|
160
|
+
walkType(type.value, visit);
|
|
161
|
+
return;
|
|
162
|
+
case "array":
|
|
163
|
+
walkType(type.element, visit);
|
|
164
|
+
return;
|
|
165
|
+
case "object":
|
|
166
|
+
for (const field of type.fields) {
|
|
167
|
+
walkType(field.type, visit);
|
|
168
|
+
}
|
|
169
|
+
return;
|
|
170
|
+
case "union":
|
|
171
|
+
for (const variant of type.variants) {
|
|
172
|
+
walkType(variant, visit);
|
|
173
|
+
}
|
|
174
|
+
return;
|
|
175
|
+
case "tuple":
|
|
176
|
+
for (const element of type.elements) {
|
|
177
|
+
walkType(element, visit);
|
|
178
|
+
}
|
|
179
|
+
return;
|
|
180
|
+
case "string":
|
|
181
|
+
case "number":
|
|
182
|
+
case "bigint":
|
|
183
|
+
case "boolean":
|
|
184
|
+
case "date":
|
|
185
|
+
case "enum":
|
|
186
|
+
case "unknown":
|
|
187
|
+
case "literal":
|
|
188
|
+
case "instance":
|
|
189
|
+
return;
|
|
190
|
+
default: {
|
|
191
|
+
const _exhaustive = type;
|
|
192
|
+
throw _exhaustive;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
function collectPrinterNeeds(ir) {
|
|
197
|
+
const formats = new Set();
|
|
198
|
+
let date = false;
|
|
199
|
+
let buffer = false;
|
|
200
|
+
const visit = (type) => {
|
|
201
|
+
switch (type.kind) {
|
|
202
|
+
case "date":
|
|
203
|
+
date = true;
|
|
204
|
+
formats.add("date-time");
|
|
205
|
+
return;
|
|
206
|
+
case "instance":
|
|
207
|
+
if (type.tsName === "Buffer") {
|
|
208
|
+
buffer = true;
|
|
209
|
+
}
|
|
210
|
+
return;
|
|
211
|
+
case "string":
|
|
212
|
+
if (type.format !== undefined) {
|
|
213
|
+
formats.add(type.format);
|
|
214
|
+
}
|
|
215
|
+
return;
|
|
216
|
+
case "number":
|
|
217
|
+
case "bigint":
|
|
218
|
+
case "boolean":
|
|
219
|
+
case "enum":
|
|
220
|
+
case "unknown":
|
|
221
|
+
case "record":
|
|
222
|
+
case "array":
|
|
223
|
+
case "object":
|
|
224
|
+
case "union":
|
|
225
|
+
case "literal":
|
|
226
|
+
case "tuple":
|
|
227
|
+
return;
|
|
228
|
+
default: {
|
|
229
|
+
const _exhaustive = type;
|
|
230
|
+
throw _exhaustive;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
for (const table of ir.tables) {
|
|
235
|
+
for (const field of [
|
|
236
|
+
...table.select,
|
|
237
|
+
...table.create,
|
|
238
|
+
...table.update,
|
|
239
|
+
]) {
|
|
240
|
+
walkType(field.type, visit);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return { date, buffer, formats };
|
|
244
|
+
}
|
|
245
|
+
const FORMAT_CHECKERS = {
|
|
246
|
+
uuid: "Format.IsUuid",
|
|
247
|
+
email: "Format.IsEmail",
|
|
248
|
+
url: "Format.IsUrl",
|
|
249
|
+
"date-time": "Format.IsDateTime",
|
|
250
|
+
};
|
|
251
|
+
const DATE_VALUE_HELPER = `const dateValue = Type.Codec(
|
|
252
|
+
Type.Union([
|
|
253
|
+
Type.Refine(Type.Unsafe({}), (value) => value instanceof Date),
|
|
254
|
+
Type.String({ format: "date-time" }),
|
|
255
|
+
]),
|
|
256
|
+
)
|
|
257
|
+
.Decode((value) => (value instanceof Date ? value : new Date(value)))
|
|
258
|
+
.Encode((value) => value);
|
|
259
|
+
`;
|
|
260
|
+
const BUFFER_VALUE_HELPER = `const bufferValue = Type.Refine(Type.Unsafe({}), (value) => Buffer.isBuffer(value));
|
|
261
|
+
`;
|
|
262
|
+
function emitFormatRegistrations(formats) {
|
|
263
|
+
const order = ["uuid", "email", "url", "date-time"];
|
|
264
|
+
const lines = [];
|
|
265
|
+
for (const format of order) {
|
|
266
|
+
if (!formats.has(format)) {
|
|
267
|
+
continue;
|
|
268
|
+
}
|
|
269
|
+
const checker = FORMAT_CHECKERS[format];
|
|
270
|
+
lines.push(`if (!Format.Has(${JSON.stringify(format)})) Format.Set(${JSON.stringify(format)}, ${checker});`);
|
|
271
|
+
}
|
|
272
|
+
return lines;
|
|
273
|
+
}
|
|
274
|
+
function emitJunctionComment(table) {
|
|
275
|
+
const junction = table.junction;
|
|
276
|
+
if (!junction) {
|
|
277
|
+
return [];
|
|
278
|
+
}
|
|
279
|
+
return [
|
|
280
|
+
`// Many-to-many junction for ${junction.leftAccessor}.${junction.relationAs} ↔ ${junction.rightAccessor}.${junction.inverseAs}.`,
|
|
281
|
+
`// Prefer nested writes: db.${junction.leftAccessor}.update({ data: { ${junction.relationAs}: { connect: [{ id }] } } })`,
|
|
282
|
+
`// Direct inserts use ${table.modelName}LinkCreateSchema (both FK ids).`,
|
|
283
|
+
];
|
|
284
|
+
}
|
|
285
|
+
function emitTableTypebox(table, lines) {
|
|
286
|
+
const isJunction = table.junction !== undefined;
|
|
287
|
+
if (isJunction) {
|
|
288
|
+
lines.push(...emitJunctionComment(table));
|
|
289
|
+
}
|
|
290
|
+
lines.push(`export const ${table.modelName}Schema = ${emitObjectFields(table.select)};`);
|
|
291
|
+
lines.push("");
|
|
292
|
+
if (isJunction) {
|
|
293
|
+
lines.push(`export const ${table.modelName}LinkCreateSchema = ${emitObjectFields(table.create)};`);
|
|
294
|
+
lines.push(`export const ${table.modelName}CreateSchema = ${table.modelName}LinkCreateSchema;`);
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
lines.push(`export const ${table.modelName}CreateSchema = ${emitObjectFields(table.create)};`);
|
|
298
|
+
}
|
|
299
|
+
lines.push("");
|
|
300
|
+
const emitUpdate = !isJunction || table.update.length > 0;
|
|
301
|
+
if (emitUpdate) {
|
|
302
|
+
lines.push(`export const ${table.modelName}UpdateSchema = ${emitObjectFields(table.update)};`);
|
|
303
|
+
lines.push("");
|
|
304
|
+
}
|
|
305
|
+
else if (table.junction) {
|
|
306
|
+
lines.push(`// No scalar updates on junction rows — use nested relation writes on ${table.junction.leftAccessor}.${table.junction.relationAs}`);
|
|
307
|
+
lines.push("");
|
|
308
|
+
}
|
|
309
|
+
lines.push(`export type ${table.modelName}Select = Type.StaticDecode<typeof ${table.modelName}Schema>;`);
|
|
310
|
+
if (isJunction) {
|
|
311
|
+
lines.push(`export type ${table.modelName}LinkCreate = Type.StaticDecode<typeof ${table.modelName}LinkCreateSchema>;`);
|
|
312
|
+
}
|
|
313
|
+
lines.push(`export type ${table.modelName}Create = Type.StaticDecode<typeof ${table.modelName}CreateSchema>;`);
|
|
314
|
+
if (emitUpdate) {
|
|
315
|
+
lines.push(`export type ${table.modelName}Update = Type.StaticDecode<typeof ${table.modelName}UpdateSchema>;`);
|
|
316
|
+
}
|
|
317
|
+
lines.push("");
|
|
318
|
+
if (emitUpdate) {
|
|
319
|
+
return ` ${table.accessor}: { select: ${table.modelName}Schema, create: ${table.modelName}CreateSchema, update: ${table.modelName}UpdateSchema },`;
|
|
320
|
+
}
|
|
321
|
+
return ` ${table.accessor}: { select: ${table.modelName}Schema, create: ${table.modelName}CreateSchema },`;
|
|
322
|
+
}
|
|
323
|
+
/** Print validation IR as a TypeBox 1.x module. Does not read ManifestColumn kinds. */
|
|
324
|
+
export function emitTypeboxTs(ir) {
|
|
325
|
+
const needs = collectPrinterNeeds(ir);
|
|
326
|
+
const lines = [
|
|
327
|
+
"// Auto-generated by neoorm generate — do not edit",
|
|
328
|
+
'import Type from "typebox";',
|
|
329
|
+
];
|
|
330
|
+
if (needs.formats.size > 0) {
|
|
331
|
+
lines.push('import Format from "typebox/format";');
|
|
332
|
+
}
|
|
333
|
+
lines.push("");
|
|
334
|
+
const formatLines = emitFormatRegistrations(needs.formats);
|
|
335
|
+
if (formatLines.length > 0) {
|
|
336
|
+
lines.push(...formatLines);
|
|
337
|
+
lines.push("");
|
|
338
|
+
}
|
|
339
|
+
if (needs.date) {
|
|
340
|
+
lines.push(DATE_VALUE_HELPER);
|
|
341
|
+
}
|
|
342
|
+
if (needs.buffer) {
|
|
343
|
+
lines.push(BUFFER_VALUE_HELPER);
|
|
344
|
+
}
|
|
345
|
+
for (const enumType of ir.enums) {
|
|
346
|
+
lines.push(`export const ${enumType.name}Schema = Type.Enum(${JSON.stringify(enumType.values)});`);
|
|
347
|
+
lines.push(`export type ${enumType.name} = Type.StaticDecode<typeof ${enumType.name}Schema>;`);
|
|
348
|
+
lines.push("");
|
|
349
|
+
}
|
|
350
|
+
const schemaEntries = [];
|
|
351
|
+
for (const table of ir.tables) {
|
|
352
|
+
schemaEntries.push(emitTableTypebox(table, lines));
|
|
353
|
+
}
|
|
354
|
+
lines.push("export const schemas = {");
|
|
355
|
+
lines.push(...schemaEntries);
|
|
356
|
+
lines.push("} as const;");
|
|
357
|
+
lines.push("");
|
|
358
|
+
return lines.join("\n");
|
|
359
|
+
}
|
|
360
|
+
//# sourceMappingURL=emit-typebox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emit-typebox.js","sourceRoot":"","sources":["../../../src/codegen/validation/emit-typebox.ts"],"names":[],"mappings":"AAUA,SA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C,KAAK,MAAM,KAAK,IAAI,EAAE,CAAC,MAAM,EAAE,CAAC;QAC/B,aAAa,CAAC,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;IACpD,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;IACvC,KAAK,CAAC,IAAI,CAAC,GAAG,aAAa,CAAC,CAAC;IAC7B,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IAC1B,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAEf,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACzB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emit-zod.d.ts","sourceRoot":"","sources":["../../../src/codegen/validation/emit-zod.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAIX,YAAY,EAEZ,MAAM,YAAY,CAAC;AA6TpB,iFAAiF;AACjF,wBAAgB,SAAS,CAAC,EAAE,EAAE,YAAY,GAAG,MAAM,CAiClD"}
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
function emitLiteral(value) {
|
|
2
|
+
return `z.literal(${JSON.stringify(value)})`;
|
|
3
|
+
}
|
|
4
|
+
function emitInstance(tsName) {
|
|
5
|
+
switch (tsName) {
|
|
6
|
+
case "Buffer":
|
|
7
|
+
return "z.custom<Buffer>((v) => Buffer.isBuffer(v))";
|
|
8
|
+
default: {
|
|
9
|
+
const _exhaustive = tsName;
|
|
10
|
+
return _exhaustive;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function emitType(type) {
|
|
15
|
+
switch (type.kind) {
|
|
16
|
+
case "string":
|
|
17
|
+
switch (type.format) {
|
|
18
|
+
case "uuid":
|
|
19
|
+
return "z.uuid()";
|
|
20
|
+
case "email":
|
|
21
|
+
return "z.email()";
|
|
22
|
+
case "url":
|
|
23
|
+
return "z.url()";
|
|
24
|
+
case undefined:
|
|
25
|
+
return "z.string()";
|
|
26
|
+
default: {
|
|
27
|
+
const _exhaustive = type.format;
|
|
28
|
+
return _exhaustive;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
case "number":
|
|
32
|
+
return type.int === true ? "z.number().int()" : "z.number()";
|
|
33
|
+
case "bigint":
|
|
34
|
+
return "z.bigint()";
|
|
35
|
+
case "boolean":
|
|
36
|
+
return "z.boolean()";
|
|
37
|
+
case "date":
|
|
38
|
+
return "dateValue";
|
|
39
|
+
case "enum":
|
|
40
|
+
return type.name !== undefined
|
|
41
|
+
? `${type.name}Schema`
|
|
42
|
+
: `z.enum(${JSON.stringify(type.values)})`;
|
|
43
|
+
case "unknown":
|
|
44
|
+
return "z.unknown()";
|
|
45
|
+
case "record": {
|
|
46
|
+
const keyExpr = type.key !== undefined ? emitType(type.key) : "z.string()";
|
|
47
|
+
return `z.record(${keyExpr}, ${emitType(type.value)})`;
|
|
48
|
+
}
|
|
49
|
+
case "array":
|
|
50
|
+
return `z.array(${emitType(type.element)})`;
|
|
51
|
+
case "object":
|
|
52
|
+
return `z.object({ ${type.fields.map(emitFieldInline).join(", ")} })`;
|
|
53
|
+
case "union":
|
|
54
|
+
return `z.union([${type.variants.map(emitType).join(", ")}])`;
|
|
55
|
+
case "literal":
|
|
56
|
+
return emitLiteral(type.value);
|
|
57
|
+
case "tuple":
|
|
58
|
+
return `z.tuple([${type.elements.map(emitType).join(", ")}])`;
|
|
59
|
+
case "instance":
|
|
60
|
+
return emitInstance(type.tsName);
|
|
61
|
+
default: {
|
|
62
|
+
const _exhaustive = type;
|
|
63
|
+
return _exhaustive;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function bigintLiteral(value) {
|
|
68
|
+
return `BigInt(${JSON.stringify(String(value))})`;
|
|
69
|
+
}
|
|
70
|
+
function numberLiteral(value) {
|
|
71
|
+
if (typeof value === "number") {
|
|
72
|
+
return String(value);
|
|
73
|
+
}
|
|
74
|
+
return String(Number(value));
|
|
75
|
+
}
|
|
76
|
+
function applyDecimalRefine(expr, constraints) {
|
|
77
|
+
const checks = [];
|
|
78
|
+
if (constraints.min !== undefined) {
|
|
79
|
+
checks.push(`Number(value) >= ${numberLiteral(constraints.min)}`);
|
|
80
|
+
}
|
|
81
|
+
if (constraints.max !== undefined) {
|
|
82
|
+
checks.push(`Number(value) <= ${numberLiteral(constraints.max)}`);
|
|
83
|
+
}
|
|
84
|
+
if (constraints.positive === true) {
|
|
85
|
+
checks.push("Number(value) > 0");
|
|
86
|
+
}
|
|
87
|
+
if (checks.length === 0) {
|
|
88
|
+
return expr;
|
|
89
|
+
}
|
|
90
|
+
return `${expr}.refine((value) => ${checks.join(" && ")})`;
|
|
91
|
+
}
|
|
92
|
+
function applyConstraints(expr, type, constraints) {
|
|
93
|
+
if (!constraints) {
|
|
94
|
+
return expr;
|
|
95
|
+
}
|
|
96
|
+
switch (type.kind) {
|
|
97
|
+
case "string": {
|
|
98
|
+
let next = expr;
|
|
99
|
+
if (constraints.minLength !== undefined) {
|
|
100
|
+
next = `${next}.min(${constraints.minLength})`;
|
|
101
|
+
}
|
|
102
|
+
if (constraints.maxLength !== undefined) {
|
|
103
|
+
next = `${next}.max(${constraints.maxLength})`;
|
|
104
|
+
}
|
|
105
|
+
if (constraints.min !== undefined ||
|
|
106
|
+
constraints.max !== undefined ||
|
|
107
|
+
constraints.positive === true) {
|
|
108
|
+
next = applyDecimalRefine(next, constraints);
|
|
109
|
+
}
|
|
110
|
+
return next;
|
|
111
|
+
}
|
|
112
|
+
case "number": {
|
|
113
|
+
let next = expr;
|
|
114
|
+
if (constraints.min !== undefined) {
|
|
115
|
+
next = `${next}.min(${numberLiteral(constraints.min)})`;
|
|
116
|
+
}
|
|
117
|
+
if (constraints.max !== undefined) {
|
|
118
|
+
next = `${next}.max(${numberLiteral(constraints.max)})`;
|
|
119
|
+
}
|
|
120
|
+
if (constraints.positive === true) {
|
|
121
|
+
next = `${next}.positive()`;
|
|
122
|
+
}
|
|
123
|
+
return next;
|
|
124
|
+
}
|
|
125
|
+
case "bigint": {
|
|
126
|
+
let next = expr;
|
|
127
|
+
if (constraints.min !== undefined) {
|
|
128
|
+
next = `${next}.min(${bigintLiteral(constraints.min)})`;
|
|
129
|
+
}
|
|
130
|
+
if (constraints.max !== undefined) {
|
|
131
|
+
next = `${next}.max(${bigintLiteral(constraints.max)})`;
|
|
132
|
+
}
|
|
133
|
+
if (constraints.positive === true) {
|
|
134
|
+
next = `${next}.positive()`;
|
|
135
|
+
}
|
|
136
|
+
return next;
|
|
137
|
+
}
|
|
138
|
+
case "boolean":
|
|
139
|
+
case "date":
|
|
140
|
+
case "enum":
|
|
141
|
+
case "unknown":
|
|
142
|
+
case "record":
|
|
143
|
+
case "array":
|
|
144
|
+
case "object":
|
|
145
|
+
case "union":
|
|
146
|
+
case "literal":
|
|
147
|
+
case "tuple":
|
|
148
|
+
case "instance":
|
|
149
|
+
return expr;
|
|
150
|
+
default: {
|
|
151
|
+
const _exhaustive = type;
|
|
152
|
+
return _exhaustive;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function emitFieldExpr(field) {
|
|
157
|
+
let expr = emitType(field.type);
|
|
158
|
+
expr = applyConstraints(expr, field.type, field.constraints);
|
|
159
|
+
if (field.nullable) {
|
|
160
|
+
expr = `${expr}.nullable()`;
|
|
161
|
+
}
|
|
162
|
+
if (field.optional) {
|
|
163
|
+
expr = `${expr}.optional()`;
|
|
164
|
+
}
|
|
165
|
+
return expr;
|
|
166
|
+
}
|
|
167
|
+
function emitFieldInline(field) {
|
|
168
|
+
return `${field.name}: ${emitFieldExpr(field)}`;
|
|
169
|
+
}
|
|
170
|
+
function emitObjectFields(fields) {
|
|
171
|
+
if (fields.length === 0) {
|
|
172
|
+
return "z.object({})";
|
|
173
|
+
}
|
|
174
|
+
const body = fields
|
|
175
|
+
.map((field) => ` ${field.name}: ${emitFieldExpr(field)},`)
|
|
176
|
+
.join("\n");
|
|
177
|
+
return `z.object({\n${body}\n})`;
|
|
178
|
+
}
|
|
179
|
+
function typeHasDate(type) {
|
|
180
|
+
switch (type.kind) {
|
|
181
|
+
case "date":
|
|
182
|
+
return true;
|
|
183
|
+
case "array":
|
|
184
|
+
return typeHasDate(type.element);
|
|
185
|
+
case "union":
|
|
186
|
+
return type.variants.some(typeHasDate);
|
|
187
|
+
case "tuple":
|
|
188
|
+
return type.elements.some(typeHasDate);
|
|
189
|
+
case "object":
|
|
190
|
+
return type.fields.some((field) => typeHasDate(field.type));
|
|
191
|
+
case "string":
|
|
192
|
+
case "number":
|
|
193
|
+
case "bigint":
|
|
194
|
+
case "boolean":
|
|
195
|
+
case "enum":
|
|
196
|
+
case "unknown":
|
|
197
|
+
case "record":
|
|
198
|
+
case "literal":
|
|
199
|
+
case "instance":
|
|
200
|
+
return false;
|
|
201
|
+
default: {
|
|
202
|
+
const _exhaustive = type;
|
|
203
|
+
return _exhaustive;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
function irHasDate(ir) {
|
|
208
|
+
return ir.tables.some((table) => [...table.select, ...table.create, ...table.update].some((field) => typeHasDate(field.type)));
|
|
209
|
+
}
|
|
210
|
+
const DATE_VALUE_HELPER = `const dateValue = z
|
|
211
|
+
.union([z.date(), z.iso.datetime({ offset: true })])
|
|
212
|
+
.transform((value) => (value instanceof Date ? value : new Date(value)));
|
|
213
|
+
`;
|
|
214
|
+
function emitJunctionComment(table) {
|
|
215
|
+
const junction = table.junction;
|
|
216
|
+
if (!junction) {
|
|
217
|
+
return [];
|
|
218
|
+
}
|
|
219
|
+
return [
|
|
220
|
+
`// Many-to-many junction for ${junction.leftAccessor}.${junction.relationAs} ↔ ${junction.rightAccessor}.${junction.inverseAs}.`,
|
|
221
|
+
`// Prefer nested writes: db.${junction.leftAccessor}.update({ data: { ${junction.relationAs}: { connect: [{ id }] } } })`,
|
|
222
|
+
`// Direct inserts use ${table.modelName}LinkCreateSchema (both FK ids).`,
|
|
223
|
+
];
|
|
224
|
+
}
|
|
225
|
+
function emitTableZod(table, lines) {
|
|
226
|
+
const isJunction = table.junction !== undefined;
|
|
227
|
+
if (isJunction) {
|
|
228
|
+
lines.push(...emitJunctionComment(table));
|
|
229
|
+
}
|
|
230
|
+
lines.push(`export const ${table.modelName}Schema = ${emitObjectFields(table.select)};`);
|
|
231
|
+
lines.push("");
|
|
232
|
+
if (isJunction) {
|
|
233
|
+
lines.push(`export const ${table.modelName}LinkCreateSchema = ${emitObjectFields(table.create)};`);
|
|
234
|
+
lines.push(`export const ${table.modelName}CreateSchema = ${table.modelName}LinkCreateSchema;`);
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
lines.push(`export const ${table.modelName}CreateSchema = ${emitObjectFields(table.create)};`);
|
|
238
|
+
}
|
|
239
|
+
lines.push("");
|
|
240
|
+
const emitUpdate = !isJunction || table.update.length > 0;
|
|
241
|
+
if (emitUpdate) {
|
|
242
|
+
lines.push(`export const ${table.modelName}UpdateSchema = ${emitObjectFields(table.update)};`);
|
|
243
|
+
lines.push("");
|
|
244
|
+
}
|
|
245
|
+
else if (table.junction) {
|
|
246
|
+
lines.push(`// No scalar updates on junction rows — use nested relation writes on ${table.junction.leftAccessor}.${table.junction.relationAs}`);
|
|
247
|
+
lines.push("");
|
|
248
|
+
}
|
|
249
|
+
lines.push(`export type ${table.modelName}Select = z.infer<typeof ${table.modelName}Schema>;`);
|
|
250
|
+
if (isJunction) {
|
|
251
|
+
lines.push(`export type ${table.modelName}LinkCreate = z.infer<typeof ${table.modelName}LinkCreateSchema>;`);
|
|
252
|
+
}
|
|
253
|
+
lines.push(`export type ${table.modelName}Create = z.infer<typeof ${table.modelName}CreateSchema>;`);
|
|
254
|
+
if (emitUpdate) {
|
|
255
|
+
lines.push(`export type ${table.modelName}Update = z.infer<typeof ${table.modelName}UpdateSchema>;`);
|
|
256
|
+
}
|
|
257
|
+
lines.push("");
|
|
258
|
+
if (emitUpdate) {
|
|
259
|
+
return ` ${table.accessor}: { select: ${table.modelName}Schema, create: ${table.modelName}CreateSchema, update: ${table.modelName}UpdateSchema },`;
|
|
260
|
+
}
|
|
261
|
+
return ` ${table.accessor}: { select: ${table.modelName}Schema, create: ${table.modelName}CreateSchema },`;
|
|
262
|
+
}
|
|
263
|
+
/** Print validation IR as a Zod 4 module. Does not read ManifestColumn kinds. */
|
|
264
|
+
export function emitZodTs(ir) {
|
|
265
|
+
const lines = [
|
|
266
|
+
"// Auto-generated by neoorm generate — do not edit",
|
|
267
|
+
'import { z } from "zod";',
|
|
268
|
+
"",
|
|
269
|
+
];
|
|
270
|
+
if (irHasDate(ir)) {
|
|
271
|
+
lines.push(DATE_VALUE_HELPER);
|
|
272
|
+
}
|
|
273
|
+
for (const enumType of ir.enums) {
|
|
274
|
+
lines.push(`export const ${enumType.name}Schema = z.enum(${JSON.stringify(enumType.values)});`);
|
|
275
|
+
lines.push(`export type ${enumType.name} = z.infer<typeof ${enumType.name}Schema>;`);
|
|
276
|
+
lines.push("");
|
|
277
|
+
}
|
|
278
|
+
const schemaEntries = [];
|
|
279
|
+
for (const table of ir.tables) {
|
|
280
|
+
schemaEntries.push(emitTableZod(table, lines));
|
|
281
|
+
}
|
|
282
|
+
lines.push("export const schemas = {");
|
|
283
|
+
lines.push(...schemaEntries);
|
|
284
|
+
lines.push("} as const;");
|
|
285
|
+
lines.push("");
|
|
286
|
+
return lines.join("\n");
|
|
287
|
+
}
|
|
288
|
+
//# sourceMappingURL=emit-zod.js.map
|