funkscript 0.0.0-stage → 0.2.3
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/LICENSE +21 -0
- package/README.md +204 -2
- package/dist/Widget.tsx +9 -0
- package/dist/ast/types.d.ts +513 -0
- package/dist/ast/types.d.ts.map +1 -0
- package/dist/ast/types.js +5 -0
- package/dist/ast/types.js.map +1 -0
- package/dist/ast/walk.d.ts +8 -0
- package/dist/ast/walk.d.ts.map +1 -0
- package/dist/ast/walk.js +23 -0
- package/dist/ast/walk.js.map +1 -0
- package/dist/cli/build-bun.d.ts +24 -0
- package/dist/cli/build-bun.d.ts.map +1 -0
- package/dist/cli/build-bun.js +190 -0
- package/dist/cli/build-bun.js.map +1 -0
- package/dist/cli/build-watch.d.ts +21 -0
- package/dist/cli/build-watch.d.ts.map +1 -0
- package/dist/cli/build-watch.js +244 -0
- package/dist/cli/build-watch.js.map +1 -0
- package/dist/cli/build.d.ts +4 -0
- package/dist/cli/build.d.ts.map +1 -0
- package/dist/cli/build.js +338 -0
- package/dist/cli/build.js.map +1 -0
- package/dist/cli/check.d.ts +4 -0
- package/dist/cli/check.d.ts.map +1 -0
- package/dist/cli/check.js +278 -0
- package/dist/cli/check.js.map +1 -0
- package/dist/cli/commands.d.ts +13 -0
- package/dist/cli/commands.d.ts.map +1 -0
- package/dist/cli/commands.js +262 -0
- package/dist/cli/commands.js.map +1 -0
- package/dist/cli/doc.d.ts +3 -0
- package/dist/cli/doc.d.ts.map +1 -0
- package/dist/cli/doc.js +71 -0
- package/dist/cli/doc.js.map +1 -0
- package/dist/cli/doctor.d.ts +3 -0
- package/dist/cli/doctor.d.ts.map +1 -0
- package/dist/cli/doctor.js +121 -0
- package/dist/cli/doctor.js.map +1 -0
- package/dist/cli/emit.d.ts +4 -0
- package/dist/cli/emit.d.ts.map +1 -0
- package/dist/cli/emit.js +87 -0
- package/dist/cli/emit.js.map +1 -0
- package/dist/cli/explain.d.ts +3 -0
- package/dist/cli/explain.d.ts.map +1 -0
- package/dist/cli/explain.js +103 -0
- package/dist/cli/explain.js.map +1 -0
- package/dist/cli/fmt.d.ts +3 -0
- package/dist/cli/fmt.d.ts.map +1 -0
- package/dist/cli/fmt.js +146 -0
- package/dist/cli/fmt.js.map +1 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +186 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/init.d.ts +10 -0
- package/dist/cli/init.d.ts.map +1 -0
- package/dist/cli/init.js +412 -0
- package/dist/cli/init.js.map +1 -0
- package/dist/cli/io.d.ts +9 -0
- package/dist/cli/io.d.ts.map +1 -0
- package/dist/cli/io.js +113 -0
- package/dist/cli/io.js.map +1 -0
- package/dist/cli/output-collisions.d.ts +2 -0
- package/dist/cli/output-collisions.d.ts.map +1 -0
- package/dist/cli/output-collisions.js +39 -0
- package/dist/cli/output-collisions.js.map +1 -0
- package/dist/cli/pipeline-style.d.ts +3 -0
- package/dist/cli/pipeline-style.d.ts.map +1 -0
- package/dist/cli/pipeline-style.js +45 -0
- package/dist/cli/pipeline-style.js.map +1 -0
- package/dist/cli/repl.d.ts +37 -0
- package/dist/cli/repl.d.ts.map +1 -0
- package/dist/cli/repl.js +334 -0
- package/dist/cli/repl.js.map +1 -0
- package/dist/cli/run.d.ts +4 -0
- package/dist/cli/run.d.ts.map +1 -0
- package/dist/cli/run.js +185 -0
- package/dist/cli/run.js.map +1 -0
- package/dist/cli/test.d.ts +3 -0
- package/dist/cli/test.d.ts.map +1 -0
- package/dist/cli/test.js +124 -0
- package/dist/cli/test.js.map +1 -0
- package/dist/cli/tsc.d.ts +3 -0
- package/dist/cli/tsc.d.ts.map +1 -0
- package/dist/cli/tsc.js +143 -0
- package/dist/cli/tsc.js.map +1 -0
- package/dist/cli/typecheck.d.ts +23 -0
- package/dist/cli/typecheck.d.ts.map +1 -0
- package/dist/cli/typecheck.js +65 -0
- package/dist/cli/typecheck.js.map +1 -0
- package/dist/compiler/ast-inspection.d.ts +18 -0
- package/dist/compiler/ast-inspection.d.ts.map +1 -0
- package/dist/compiler/ast-inspection.js +96 -0
- package/dist/compiler/ast-inspection.js.map +1 -0
- package/dist/compiler/boolean-operators.d.ts +8 -0
- package/dist/compiler/boolean-operators.d.ts.map +1 -0
- package/dist/compiler/boolean-operators.js +84 -0
- package/dist/compiler/boolean-operators.js.map +1 -0
- package/dist/compiler/check.d.ts +87 -0
- package/dist/compiler/check.d.ts.map +1 -0
- package/dist/compiler/check.js +1830 -0
- package/dist/compiler/check.js.map +1 -0
- package/dist/compiler/diagnostics.d.ts +6 -0
- package/dist/compiler/diagnostics.d.ts.map +1 -0
- package/dist/compiler/diagnostics.js +136 -0
- package/dist/compiler/diagnostics.js.map +1 -0
- package/dist/compiler/effect-mutation-rule.d.ts +4 -0
- package/dist/compiler/effect-mutation-rule.d.ts.map +1 -0
- package/dist/compiler/effect-mutation-rule.js +348 -0
- package/dist/compiler/effect-mutation-rule.js.map +1 -0
- package/dist/compiler/entry-rules.d.ts +5 -0
- package/dist/compiler/entry-rules.d.ts.map +1 -0
- package/dist/compiler/entry-rules.js +89 -0
- package/dist/compiler/entry-rules.js.map +1 -0
- package/dist/compiler/imported-record-functions.d.ts +4 -0
- package/dist/compiler/imported-record-functions.d.ts.map +1 -0
- package/dist/compiler/imported-record-functions.js +706 -0
- package/dist/compiler/imported-record-functions.js.map +1 -0
- package/dist/compiler/imported-schemas.d.ts +21 -0
- package/dist/compiler/imported-schemas.d.ts.map +1 -0
- package/dist/compiler/imported-schemas.js +461 -0
- package/dist/compiler/imported-schemas.js.map +1 -0
- package/dist/compiler/incremental-build.d.ts +23 -0
- package/dist/compiler/incremental-build.d.ts.map +1 -0
- package/dist/compiler/incremental-build.js +90 -0
- package/dist/compiler/incremental-build.js.map +1 -0
- package/dist/compiler/incremental-dependencies.d.ts +7 -0
- package/dist/compiler/incremental-dependencies.d.ts.map +1 -0
- package/dist/compiler/incremental-dependencies.js +190 -0
- package/dist/compiler/incremental-dependencies.js.map +1 -0
- package/dist/compiler/js-interop-nullability.d.ts +9 -0
- package/dist/compiler/js-interop-nullability.d.ts.map +1 -0
- package/dist/compiler/js-interop-nullability.js +57 -0
- package/dist/compiler/js-interop-nullability.js.map +1 -0
- package/dist/compiler/module-resolution.d.ts +6 -0
- package/dist/compiler/module-resolution.d.ts.map +1 -0
- package/dist/compiler/module-resolution.js +44 -0
- package/dist/compiler/module-resolution.js.map +1 -0
- package/dist/compiler/modules/output-collisions.d.ts +2 -0
- package/dist/compiler/modules/output-collisions.d.ts.map +1 -0
- package/dist/compiler/modules/output-collisions.js +39 -0
- package/dist/compiler/modules/output-collisions.js.map +1 -0
- package/dist/compiler/modules/output-plan.d.ts +7 -0
- package/dist/compiler/modules/output-plan.d.ts.map +1 -0
- package/dist/compiler/modules/output-plan.js +37 -0
- package/dist/compiler/modules/output-plan.js.map +1 -0
- package/dist/compiler/modules/resolution.d.ts +8 -0
- package/dist/compiler/modules/resolution.d.ts.map +1 -0
- package/dist/compiler/modules/resolution.js +48 -0
- package/dist/compiler/modules/resolution.js.map +1 -0
- package/dist/compiler/numeric-comparisons.d.ts +9 -0
- package/dist/compiler/numeric-comparisons.d.ts.map +1 -0
- package/dist/compiler/numeric-comparisons.js +153 -0
- package/dist/compiler/numeric-comparisons.js.map +1 -0
- package/dist/compiler/optional-arguments.d.ts +11 -0
- package/dist/compiler/optional-arguments.d.ts.map +1 -0
- package/dist/compiler/optional-arguments.js +246 -0
- package/dist/compiler/optional-arguments.js.map +1 -0
- package/dist/compiler/package-fingerprint.d.ts +7 -0
- package/dist/compiler/package-fingerprint.d.ts.map +1 -0
- package/dist/compiler/package-fingerprint.js +178 -0
- package/dist/compiler/package-fingerprint.js.map +1 -0
- package/dist/compiler/package-record-contracts.d.ts +5 -0
- package/dist/compiler/package-record-contracts.d.ts.map +1 -0
- package/dist/compiler/package-record-contracts.js +126 -0
- package/dist/compiler/package-record-contracts.js.map +1 -0
- package/dist/compiler/pipeline-companions.d.ts +18 -0
- package/dist/compiler/pipeline-companions.d.ts.map +1 -0
- package/dist/compiler/pipeline-companions.js +1042 -0
- package/dist/compiler/pipeline-companions.js.map +1 -0
- package/dist/compiler/pipelines/catalog.d.ts +15 -0
- package/dist/compiler/pipelines/catalog.d.ts.map +1 -0
- package/dist/compiler/pipelines/catalog.js +55 -0
- package/dist/compiler/pipelines/catalog.js.map +1 -0
- package/dist/compiler/pipelines/companions.d.ts +18 -0
- package/dist/compiler/pipelines/companions.d.ts.map +1 -0
- package/dist/compiler/pipelines/companions.js +1042 -0
- package/dist/compiler/pipelines/companions.js.map +1 -0
- package/dist/compiler/pipelines/resolution.d.ts +38 -0
- package/dist/compiler/pipelines/resolution.d.ts.map +1 -0
- package/dist/compiler/pipelines/resolution.js +571 -0
- package/dist/compiler/pipelines/resolution.js.map +1 -0
- package/dist/compiler/project-config.d.ts +28 -0
- package/dist/compiler/project-config.d.ts.map +1 -0
- package/dist/compiler/project-config.js +155 -0
- package/dist/compiler/project-config.js.map +1 -0
- package/dist/compiler/providers.d.ts +4 -0
- package/dist/compiler/providers.d.ts.map +1 -0
- package/dist/compiler/providers.js +101 -0
- package/dist/compiler/providers.js.map +1 -0
- package/dist/compiler/record-contracts.d.ts +6 -0
- package/dist/compiler/record-contracts.d.ts.map +1 -0
- package/dist/compiler/record-contracts.js +41 -0
- package/dist/compiler/record-contracts.js.map +1 -0
- package/dist/compiler/rules/control-flow.d.ts +10 -0
- package/dist/compiler/rules/control-flow.d.ts.map +1 -0
- package/dist/compiler/rules/control-flow.js +19 -0
- package/dist/compiler/rules/control-flow.js.map +1 -0
- package/dist/compiler/rules/diagnostic.d.ts +4 -0
- package/dist/compiler/rules/diagnostic.d.ts.map +1 -0
- package/dist/compiler/rules/diagnostic.js +2 -0
- package/dist/compiler/rules/diagnostic.js.map +1 -0
- package/dist/compiler/rules/module-scope-refs.d.ts +5 -0
- package/dist/compiler/rules/module-scope-refs.d.ts.map +1 -0
- package/dist/compiler/rules/module-scope-refs.js +47 -0
- package/dist/compiler/rules/module-scope-refs.js.map +1 -0
- package/dist/compiler/schemas/analysis.d.ts +13 -0
- package/dist/compiler/schemas/analysis.d.ts.map +1 -0
- package/dist/compiler/schemas/analysis.js +24 -0
- package/dist/compiler/schemas/analysis.js.map +1 -0
- package/dist/compiler/schemas/imported-record-functions.d.ts +4 -0
- package/dist/compiler/schemas/imported-record-functions.d.ts.map +1 -0
- package/dist/compiler/schemas/imported-record-functions.js +706 -0
- package/dist/compiler/schemas/imported-record-functions.js.map +1 -0
- package/dist/compiler/schemas/imported-schemas.d.ts +21 -0
- package/dist/compiler/schemas/imported-schemas.d.ts.map +1 -0
- package/dist/compiler/schemas/imported-schemas.js +461 -0
- package/dist/compiler/schemas/imported-schemas.js.map +1 -0
- package/dist/compiler/source-map.d.ts +6 -0
- package/dist/compiler/source-map.d.ts.map +1 -0
- package/dist/compiler/source-map.js +127 -0
- package/dist/compiler/source-map.js.map +1 -0
- package/dist/compiler/typescript-context.d.ts +33 -0
- package/dist/compiler/typescript-context.d.ts.map +1 -0
- package/dist/compiler/typescript-context.js +200 -0
- package/dist/compiler/typescript-context.js.map +1 -0
- package/dist/compiler.d.ts +77 -0
- package/dist/compiler.d.ts.map +1 -0
- package/dist/compiler.js +497 -0
- package/dist/compiler.js.map +1 -0
- package/dist/emitter/assemblyscript.d.ts +5 -0
- package/dist/emitter/assemblyscript.d.ts.map +1 -0
- package/dist/emitter/assemblyscript.js +979 -0
- package/dist/emitter/assemblyscript.js.map +1 -0
- package/dist/emitter/declarations.d.ts +46 -0
- package/dist/emitter/declarations.d.ts.map +1 -0
- package/dist/emitter/declarations.js +739 -0
- package/dist/emitter/declarations.js.map +1 -0
- package/dist/emitter/emitter.d.ts +165 -0
- package/dist/emitter/emitter.d.ts.map +1 -0
- package/dist/emitter/emitter.js +2448 -0
- package/dist/emitter/emitter.js.map +1 -0
- package/dist/emitter/imports.d.ts +6 -0
- package/dist/emitter/imports.d.ts.map +1 -0
- package/dist/emitter/imports.js +73 -0
- package/dist/emitter/imports.js.map +1 -0
- package/dist/emitter/indent.d.ts +3 -0
- package/dist/emitter/indent.d.ts.map +1 -0
- package/dist/emitter/indent.js +31 -0
- package/dist/emitter/indent.js.map +1 -0
- package/dist/emitter/jsx.d.ts +20 -0
- package/dist/emitter/jsx.d.ts.map +1 -0
- package/dist/emitter/jsx.js +82 -0
- package/dist/emitter/jsx.js.map +1 -0
- package/dist/emitter/local-bindings.d.ts +6 -0
- package/dist/emitter/local-bindings.d.ts.map +1 -0
- package/dist/emitter/local-bindings.js +32 -0
- package/dist/emitter/local-bindings.js.map +1 -0
- package/dist/emitter/match.d.ts +56 -0
- package/dist/emitter/match.d.ts.map +1 -0
- package/dist/emitter/match.js +1287 -0
- package/dist/emitter/match.js.map +1 -0
- package/dist/emitter/pipeline-catalog.d.ts +15 -0
- package/dist/emitter/pipeline-catalog.d.ts.map +1 -0
- package/dist/emitter/pipeline-catalog.js +55 -0
- package/dist/emitter/pipeline-catalog.js.map +1 -0
- package/dist/emitter/pipeline-resolution.d.ts +38 -0
- package/dist/emitter/pipeline-resolution.d.ts.map +1 -0
- package/dist/emitter/pipeline-resolution.js +571 -0
- package/dist/emitter/pipeline-resolution.js.map +1 -0
- package/dist/emitter/runtime-helpers.d.ts +10 -0
- package/dist/emitter/runtime-helpers.d.ts.map +1 -0
- package/dist/emitter/runtime-helpers.js +22 -0
- package/dist/emitter/runtime-helpers.js.map +1 -0
- package/dist/emitter/schemas.d.ts +36 -0
- package/dist/emitter/schemas.d.ts.map +1 -0
- package/dist/emitter/schemas.js +766 -0
- package/dist/emitter/schemas.js.map +1 -0
- package/dist/emitter/statements.d.ts +23 -0
- package/dist/emitter/statements.d.ts.map +1 -0
- package/dist/emitter/statements.js +216 -0
- package/dist/emitter/statements.js.map +1 -0
- package/dist/emitter/tagged-match.d.ts +23 -0
- package/dist/emitter/tagged-match.d.ts.map +1 -0
- package/dist/emitter/tagged-match.js +109 -0
- package/dist/emitter/tagged-match.js.map +1 -0
- package/dist/emitter/types.d.ts +22 -0
- package/dist/emitter/types.d.ts.map +1 -0
- package/dist/emitter/types.js +231 -0
- package/dist/emitter/types.js.map +1 -0
- package/dist/errors.d.ts +39 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +98 -0
- package/dist/errors.js.map +1 -0
- package/dist/formatter/comments.d.ts +25 -0
- package/dist/formatter/comments.d.ts.map +1 -0
- package/dist/formatter/comments.js +283 -0
- package/dist/formatter/comments.js.map +1 -0
- package/dist/formatter/index.d.ts +71 -0
- package/dist/formatter/index.d.ts.map +1 -0
- package/dist/formatter/index.js +1113 -0
- package/dist/formatter/index.js.map +1 -0
- package/dist/formatter/operator-precedence.d.ts +3 -0
- package/dist/formatter/operator-precedence.d.ts.map +1 -0
- package/dist/formatter/operator-precedence.js +27 -0
- package/dist/formatter/operator-precedence.js.map +1 -0
- package/dist/formatter/prettier.d.ts +7 -0
- package/dist/formatter/prettier.d.ts.map +1 -0
- package/dist/formatter/prettier.js +51 -0
- package/dist/formatter/prettier.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/interop/callback.d.ts +38 -0
- package/dist/interop/callback.d.ts.map +1 -0
- package/dist/interop/callback.js +130 -0
- package/dist/interop/callback.js.map +1 -0
- package/dist/interop/index.d.ts +6 -0
- package/dist/interop/index.d.ts.map +1 -0
- package/dist/interop/index.js +6 -0
- package/dist/interop/index.js.map +1 -0
- package/dist/interop/js.d.ts +16 -0
- package/dist/interop/js.d.ts.map +1 -0
- package/dist/interop/js.js +35 -0
- package/dist/interop/js.js.map +1 -0
- package/dist/interop/record.d.ts +9 -0
- package/dist/interop/record.d.ts.map +1 -0
- package/dist/interop/record.js +18 -0
- package/dist/interop/record.js.map +1 -0
- package/dist/interop/valibot.d.ts +9 -0
- package/dist/interop/valibot.d.ts.map +1 -0
- package/dist/interop/valibot.js +94 -0
- package/dist/interop/valibot.js.map +1 -0
- package/dist/interop/zod.d.ts +45 -0
- package/dist/interop/zod.d.ts.map +1 -0
- package/dist/interop/zod.js +143 -0
- package/dist/interop/zod.js.map +1 -0
- package/dist/lexer/lexer.d.ts +65 -0
- package/dist/lexer/lexer.d.ts.map +1 -0
- package/dist/lexer/lexer.js +1335 -0
- package/dist/lexer/lexer.js.map +1 -0
- package/dist/lexer/tokens.d.ts +96 -0
- package/dist/lexer/tokens.d.ts.map +1 -0
- package/dist/lexer/tokens.js +150 -0
- package/dist/lexer/tokens.js.map +1 -0
- package/dist/lsp/code-action-worker.d.ts +2 -0
- package/dist/lsp/code-action-worker.d.ts.map +1 -0
- package/dist/lsp/code-action-worker.js +17 -0
- package/dist/lsp/code-action-worker.js.map +1 -0
- package/dist/lsp/completion.d.ts +11 -0
- package/dist/lsp/completion.d.ts.map +1 -0
- package/dist/lsp/completion.js +260 -0
- package/dist/lsp/completion.js.map +1 -0
- package/dist/lsp/definition.d.ts +42 -0
- package/dist/lsp/definition.d.ts.map +1 -0
- package/dist/lsp/definition.js +1074 -0
- package/dist/lsp/definition.js.map +1 -0
- package/dist/lsp/diagnostics-worker.d.ts +2 -0
- package/dist/lsp/diagnostics-worker.d.ts.map +1 -0
- package/dist/lsp/diagnostics-worker.js +169 -0
- package/dist/lsp/diagnostics-worker.js.map +1 -0
- package/dist/lsp/docs.d.ts +37 -0
- package/dist/lsp/docs.d.ts.map +1 -0
- package/dist/lsp/docs.js +830 -0
- package/dist/lsp/docs.js.map +1 -0
- package/dist/lsp/error-channel.d.ts +3 -0
- package/dist/lsp/error-channel.d.ts.map +1 -0
- package/dist/lsp/error-channel.js +48 -0
- package/dist/lsp/error-channel.js.map +1 -0
- package/dist/lsp/hover.d.ts +5 -0
- package/dist/lsp/hover.d.ts.map +1 -0
- package/dist/lsp/hover.js +651 -0
- package/dist/lsp/hover.js.map +1 -0
- package/dist/lsp/imports.d.ts +5 -0
- package/dist/lsp/imports.d.ts.map +1 -0
- package/dist/lsp/imports.js +317 -0
- package/dist/lsp/imports.js.map +1 -0
- package/dist/lsp/index.d.ts +16 -0
- package/dist/lsp/index.d.ts.map +1 -0
- package/dist/lsp/index.js +17 -0
- package/dist/lsp/index.js.map +1 -0
- package/dist/lsp/inlay-hints.d.ts +3 -0
- package/dist/lsp/inlay-hints.d.ts.map +1 -0
- package/dist/lsp/inlay-hints.js +236 -0
- package/dist/lsp/inlay-hints.js.map +1 -0
- package/dist/lsp/interop-rename.d.ts +26 -0
- package/dist/lsp/interop-rename.d.ts.map +1 -0
- package/dist/lsp/interop-rename.js +346 -0
- package/dist/lsp/interop-rename.js.map +1 -0
- package/dist/lsp/match-arms.d.ts +3 -0
- package/dist/lsp/match-arms.d.ts.map +1 -0
- package/dist/lsp/match-arms.js +341 -0
- package/dist/lsp/match-arms.js.map +1 -0
- package/dist/lsp/navigation.d.ts +23 -0
- package/dist/lsp/navigation.d.ts.map +1 -0
- package/dist/lsp/navigation.js +430 -0
- package/dist/lsp/navigation.js.map +1 -0
- package/dist/lsp/parsed-documents.d.ts +25 -0
- package/dist/lsp/parsed-documents.d.ts.map +1 -0
- package/dist/lsp/parsed-documents.js +47 -0
- package/dist/lsp/parsed-documents.js.map +1 -0
- package/dist/lsp/rename-worker.d.ts +2 -0
- package/dist/lsp/rename-worker.d.ts.map +1 -0
- package/dist/lsp/rename-worker.js +27 -0
- package/dist/lsp/rename-worker.js.map +1 -0
- package/dist/lsp/server.d.ts +78 -0
- package/dist/lsp/server.d.ts.map +1 -0
- package/dist/lsp/server.js +1098 -0
- package/dist/lsp/server.js.map +1 -0
- package/dist/lsp/thunk-pipeline.d.ts +4 -0
- package/dist/lsp/thunk-pipeline.d.ts.map +1 -0
- package/dist/lsp/thunk-pipeline.js +95 -0
- package/dist/lsp/thunk-pipeline.js.map +1 -0
- package/dist/lsp/validation.d.ts +8 -0
- package/dist/lsp/validation.d.ts.map +1 -0
- package/dist/lsp/validation.js +124 -0
- package/dist/lsp/validation.js.map +1 -0
- package/dist/lsp/workspace.d.ts +8 -0
- package/dist/lsp/workspace.d.ts.map +1 -0
- package/dist/lsp/workspace.js +70 -0
- package/dist/lsp/workspace.js.map +1 -0
- package/dist/math.ts +1 -0
- package/dist/parser/declarations.d.ts +21 -0
- package/dist/parser/declarations.d.ts.map +1 -0
- package/dist/parser/declarations.js +626 -0
- package/dist/parser/declarations.js.map +1 -0
- package/dist/parser/errors.d.ts +9 -0
- package/dist/parser/errors.d.ts.map +1 -0
- package/dist/parser/errors.js +11 -0
- package/dist/parser/errors.js.map +1 -0
- package/dist/parser/index.d.ts +9 -0
- package/dist/parser/index.d.ts.map +1 -0
- package/dist/parser/index.js +9 -0
- package/dist/parser/index.js.map +1 -0
- package/dist/parser/jsx.d.ts +5 -0
- package/dist/parser/jsx.d.ts.map +1 -0
- package/dist/parser/jsx.js +188 -0
- package/dist/parser/jsx.js.map +1 -0
- package/dist/parser/operator-expressions.d.ts +16 -0
- package/dist/parser/operator-expressions.d.ts.map +1 -0
- package/dist/parser/operator-expressions.js +146 -0
- package/dist/parser/operator-expressions.js.map +1 -0
- package/dist/parser/parser.d.ts +104 -0
- package/dist/parser/parser.d.ts.map +1 -0
- package/dist/parser/parser.js +1216 -0
- package/dist/parser/parser.js.map +1 -0
- package/dist/parser/patterns.d.ts +9 -0
- package/dist/parser/patterns.d.ts.map +1 -0
- package/dist/parser/patterns.js +292 -0
- package/dist/parser/patterns.js.map +1 -0
- package/dist/parser/pipeline-expressions.d.ts +10 -0
- package/dist/parser/pipeline-expressions.d.ts.map +1 -0
- package/dist/parser/pipeline-expressions.js +57 -0
- package/dist/parser/pipeline-expressions.js.map +1 -0
- package/dist/parser/scope.d.ts +17 -0
- package/dist/parser/scope.d.ts.map +1 -0
- package/dist/parser/scope.js +56 -0
- package/dist/parser/scope.js.map +1 -0
- package/dist/parser/statements.d.ts +13 -0
- package/dist/parser/statements.d.ts.map +1 -0
- package/dist/parser/statements.js +737 -0
- package/dist/parser/statements.js.map +1 -0
- package/dist/parser/types.d.ts +13 -0
- package/dist/parser/types.d.ts.map +1 -0
- package/dist/parser/types.js +371 -0
- package/dist/parser/types.js.map +1 -0
- package/dist/plugins/bun-preload.d.ts +4 -0
- package/dist/plugins/bun-preload.d.ts.map +1 -0
- package/dist/plugins/bun-preload.js +18 -0
- package/dist/plugins/bun-preload.js.map +1 -0
- package/dist/plugins/bun.d.ts +115 -0
- package/dist/plugins/bun.d.ts.map +1 -0
- package/dist/plugins/bun.js +240 -0
- package/dist/plugins/bun.js.map +1 -0
- package/dist/plugins/esbuild.d.ts +45 -0
- package/dist/plugins/esbuild.d.ts.map +1 -0
- package/dist/plugins/esbuild.js +184 -0
- package/dist/plugins/esbuild.js.map +1 -0
- package/dist/plugins/type-view.d.ts +30 -0
- package/dist/plugins/type-view.d.ts.map +1 -0
- package/dist/plugins/type-view.js +245 -0
- package/dist/plugins/type-view.js.map +1 -0
- package/dist/plugins/vite.d.ts +56 -0
- package/dist/plugins/vite.d.ts.map +1 -0
- package/dist/plugins/vite.js +182 -0
- package/dist/plugins/vite.js.map +1 -0
- package/dist/service.ts +3 -0
- package/dist/service.ts.map +1 -0
- package/dist/testing/index.d.ts +24 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +56 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/tooling/doc.d.ts +82 -0
- package/dist/tooling/doc.d.ts.map +1 -0
- package/dist/tooling/doc.js +624 -0
- package/dist/tooling/doc.js.map +1 -0
- package/dist/tooling/idiomatic.d.ts +20 -0
- package/dist/tooling/idiomatic.d.ts.map +1 -0
- package/dist/tooling/idiomatic.js +154 -0
- package/dist/tooling/idiomatic.js.map +1 -0
- package/dist/tooling/migrate.d.ts +62 -0
- package/dist/tooling/migrate.d.ts.map +1 -0
- package/dist/tooling/migrate.js +608 -0
- package/dist/tooling/migrate.js.map +1 -0
- package/dist/tooling/pipeline-style.d.ts +12 -0
- package/dist/tooling/pipeline-style.d.ts.map +1 -0
- package/dist/tooling/pipeline-style.js +208 -0
- package/dist/tooling/pipeline-style.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +25 -0
- package/dist/version.js.map +1 -0
- package/package.json +128 -4
- package/src/ast/types.ts +753 -0
- package/src/ast/walk.ts +35 -0
- package/src/cli/build-bun.ts +249 -0
- package/src/cli/build-watch.ts +299 -0
- package/src/cli/build.ts +450 -0
- package/src/cli/check.ts +342 -0
- package/src/cli/commands.ts +301 -0
- package/src/cli/doc.ts +81 -0
- package/src/cli/doctor.ts +173 -0
- package/src/cli/emit.ts +138 -0
- package/src/cli/explain.ts +127 -0
- package/src/cli/fmt.ts +170 -0
- package/src/cli/index.ts +227 -0
- package/src/cli/init.ts +491 -0
- package/src/cli/io.ts +150 -0
- package/src/cli/pipeline-style.ts +55 -0
- package/src/cli/repl.ts +443 -0
- package/src/cli/run.ts +238 -0
- package/src/cli/test.ts +148 -0
- package/src/cli/tsc.ts +207 -0
- package/src/cli/typecheck.ts +100 -0
- package/src/compiler/ast-inspection.ts +121 -0
- package/src/compiler/boolean-operators.ts +108 -0
- package/src/compiler/check.ts +2763 -0
- package/src/compiler/diagnostics.ts +179 -0
- package/src/compiler/effect-mutation-rule.ts +407 -0
- package/src/compiler/entry-rules.ts +116 -0
- package/src/compiler/incremental-build.ts +131 -0
- package/src/compiler/incremental-dependencies.ts +200 -0
- package/src/compiler/js-interop-nullability.ts +67 -0
- package/src/compiler/modules/output-collisions.ts +48 -0
- package/src/compiler/modules/output-plan.ts +46 -0
- package/src/compiler/modules/resolution.ts +56 -0
- package/src/compiler/numeric-comparisons.ts +213 -0
- package/src/compiler/optional-arguments.ts +335 -0
- package/src/compiler/package-fingerprint.ts +216 -0
- package/src/compiler/package-record-contracts.ts +156 -0
- package/src/compiler/pipelines/catalog.ts +1128 -0
- package/src/compiler/pipelines/companions.ts +1279 -0
- package/src/compiler/pipelines/resolution.ts +684 -0
- package/src/compiler/project-config.ts +221 -0
- package/src/compiler/record-contracts.ts +46 -0
- package/src/compiler/rules/control-flow.ts +57 -0
- package/src/compiler/rules/diagnostic.ts +11 -0
- package/src/compiler/rules/module-scope-refs.ts +63 -0
- package/src/compiler/schemas/analysis.ts +45 -0
- package/src/compiler/schemas/imported-record-functions.ts +984 -0
- package/src/compiler/schemas/imported-schemas.ts +761 -0
- package/src/compiler/source-map.ts +165 -0
- package/src/compiler/typescript-context.ts +250 -0
- package/src/compiler.ts +865 -0
- package/src/emitter/assemblyscript.ts +1220 -0
- package/src/emitter/declarations.ts +916 -0
- package/src/emitter/emitter.ts +3128 -0
- package/src/emitter/imports.ts +89 -0
- package/src/emitter/indent.ts +39 -0
- package/src/emitter/jsx.ts +122 -0
- package/src/emitter/local-bindings.ts +40 -0
- package/src/emitter/match.ts +1631 -0
- package/src/emitter/runtime-helpers.ts +31 -0
- package/src/emitter/schemas.ts +969 -0
- package/src/emitter/statements.ts +310 -0
- package/src/emitter/tagged-match.ts +171 -0
- package/src/emitter/types.ts +289 -0
- package/src/errors.ts +115 -0
- package/src/formatter/comments.ts +350 -0
- package/src/formatter/index.ts +1457 -0
- package/src/formatter/operator-precedence.ts +36 -0
- package/src/formatter/prettier.ts +61 -0
- package/src/index.ts +16 -0
- package/src/interop/callback.ts +188 -0
- package/src/interop/js.ts +66 -0
- package/src/interop/record.ts +36 -0
- package/src/interop/valibot.ts +141 -0
- package/src/interop/zod.ts +219 -0
- package/src/lexer/lexer.ts +1521 -0
- package/src/lexer/tokens.ts +174 -0
- package/src/lsp/code-action-worker.ts +31 -0
- package/src/lsp/completion.ts +343 -0
- package/src/lsp/definition.ts +1165 -0
- package/src/lsp/diagnostics-worker.ts +198 -0
- package/src/lsp/docs.ts +864 -0
- package/src/lsp/error-channel.ts +63 -0
- package/src/lsp/hover.ts +803 -0
- package/src/lsp/imports.ts +380 -0
- package/src/lsp/index.ts +55 -0
- package/src/lsp/inlay-hints.ts +308 -0
- package/src/lsp/interop-rename.ts +454 -0
- package/src/lsp/match-arms.ts +400 -0
- package/src/lsp/navigation.ts +553 -0
- package/src/lsp/parsed-documents.ts +64 -0
- package/src/lsp/rename-worker.ts +40 -0
- package/src/lsp/server.ts +1437 -0
- package/src/lsp/thunk-pipeline.ts +117 -0
- package/src/lsp/validation.ts +147 -0
- package/src/lsp/workspace.ts +74 -0
- package/src/parser/declarations.ts +808 -0
- package/src/parser/errors.ts +18 -0
- package/src/parser/jsx.ts +253 -0
- package/src/parser/operator-expressions.ts +170 -0
- package/src/parser/parser.ts +1565 -0
- package/src/parser/patterns.ts +342 -0
- package/src/parser/pipeline-expressions.ts +77 -0
- package/src/parser/scope.ts +69 -0
- package/src/parser/statements.ts +831 -0
- package/src/parser/types.ts +453 -0
- package/src/plugins/bun-preload.ts +25 -0
- package/src/plugins/bun.ts +448 -0
- package/src/plugins/esbuild.ts +308 -0
- package/src/plugins/type-view.ts +326 -0
- package/src/plugins/vite.ts +294 -0
- package/src/testing/index.ts +72 -0
- package/src/tooling/doc.ts +786 -0
- package/src/tooling/idiomatic.ts +202 -0
- package/src/tooling/pipeline-style.ts +248 -0
- package/src/version.ts +27 -0
|
@@ -0,0 +1,766 @@
|
|
|
1
|
+
import { RECORD_CONTRACT_BRAND, recordContractType, } from "../compiler/record-contracts.js";
|
|
2
|
+
import { FunScriptError } from "../errors.js";
|
|
3
|
+
import { PRIMITIVE_TYPES, emitPropertyKey } from "./types.js";
|
|
4
|
+
function flattenPipelineStages(expr) {
|
|
5
|
+
if (expr.kind === "PipelineExpression") {
|
|
6
|
+
return [
|
|
7
|
+
...flattenPipelineStages(expr.left),
|
|
8
|
+
...flattenPipelineStages(expr.right),
|
|
9
|
+
];
|
|
10
|
+
}
|
|
11
|
+
return [expr];
|
|
12
|
+
}
|
|
13
|
+
function extractBrandNames(stages) {
|
|
14
|
+
const brands = [];
|
|
15
|
+
for (const stage of stages) {
|
|
16
|
+
const b = getBrandNameFromStage(stage);
|
|
17
|
+
if (b)
|
|
18
|
+
brands.push(b);
|
|
19
|
+
}
|
|
20
|
+
return brands;
|
|
21
|
+
}
|
|
22
|
+
function getBrandNameFromStage(stage) {
|
|
23
|
+
if (stage.kind !== "CallExpression")
|
|
24
|
+
return null;
|
|
25
|
+
const callee = stage.callee;
|
|
26
|
+
let isBrand = false;
|
|
27
|
+
if ((callee.kind === "UpperIdentifier" || callee.kind === "Identifier") &&
|
|
28
|
+
callee.name === "Brand") {
|
|
29
|
+
isBrand = true;
|
|
30
|
+
}
|
|
31
|
+
else if (callee.kind === "MemberExpression" &&
|
|
32
|
+
(callee.object.kind === "Identifier" ||
|
|
33
|
+
callee.object.kind === "UpperIdentifier") &&
|
|
34
|
+
(callee.object.name === "Schema" || callee.object.name === "Brand") &&
|
|
35
|
+
callee.property.name === "brand") {
|
|
36
|
+
isBrand = true;
|
|
37
|
+
}
|
|
38
|
+
if (!isBrand || stage.args.length === 0)
|
|
39
|
+
return null;
|
|
40
|
+
const first = stage.args[0];
|
|
41
|
+
if (first.kind === "StringLiteral") {
|
|
42
|
+
return first.parts
|
|
43
|
+
.map((p) => (p.kind === "StringRawPart" ? p.value : ""))
|
|
44
|
+
.join("");
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
function emitRefinementExpression(ctx, expr) {
|
|
49
|
+
if (expr.kind === "Identifier" || expr.kind === "UpperIdentifier") {
|
|
50
|
+
const name = expr.name;
|
|
51
|
+
if (!ctx.bindings.has(name) && !ctx.userImportBindings.has(name)) {
|
|
52
|
+
ctx.addEffectImport("Schema");
|
|
53
|
+
return `Schema.${name}`;
|
|
54
|
+
}
|
|
55
|
+
return name;
|
|
56
|
+
}
|
|
57
|
+
if (expr.kind === "CallExpression") {
|
|
58
|
+
const args = expr.args
|
|
59
|
+
.map((arg) => emitRefinementExpression(ctx, arg))
|
|
60
|
+
.join(", ");
|
|
61
|
+
if (expr.callee.kind === "Identifier" ||
|
|
62
|
+
expr.callee.kind === "UpperIdentifier") {
|
|
63
|
+
const name = expr.callee.name;
|
|
64
|
+
if (!ctx.bindings.has(name) && !ctx.userImportBindings.has(name)) {
|
|
65
|
+
ctx.addEffectImport("Schema");
|
|
66
|
+
return `Schema.${name}(${args})`;
|
|
67
|
+
}
|
|
68
|
+
return `${name}(${args})`;
|
|
69
|
+
}
|
|
70
|
+
if (expr.callee.kind === "MemberExpression") {
|
|
71
|
+
return `${ctx.emitExpression(expr.callee)}(${args})`;
|
|
72
|
+
}
|
|
73
|
+
return ctx.emitExpression(expr);
|
|
74
|
+
}
|
|
75
|
+
if (expr.kind === "PipelineExpression") {
|
|
76
|
+
ctx.addEffectImport("pipe");
|
|
77
|
+
const stages = flattenPipelineStages(expr);
|
|
78
|
+
return `pipe(${stages
|
|
79
|
+
.map((stage) => emitRefinementStage(ctx, stage))
|
|
80
|
+
.join(", ")})`;
|
|
81
|
+
}
|
|
82
|
+
return ctx.emitExpression(expr);
|
|
83
|
+
}
|
|
84
|
+
function emitRefinementStage(ctx, stage) {
|
|
85
|
+
const brandName = getBrandNameFromStage(stage);
|
|
86
|
+
if (brandName !== null) {
|
|
87
|
+
ctx.addEffectImport("Schema");
|
|
88
|
+
return `Schema.brand(${JSON.stringify(brandName)})`;
|
|
89
|
+
}
|
|
90
|
+
return emitRefinementExpression(ctx, stage);
|
|
91
|
+
}
|
|
92
|
+
/** Emits a record field schema, including an inline `|>` refinement when present. */
|
|
93
|
+
function emitRecordFieldSchema(ctx, field) {
|
|
94
|
+
const base = emitSchemaTypeField(ctx, field.typeAnnotation);
|
|
95
|
+
if (!field.refinement)
|
|
96
|
+
return base;
|
|
97
|
+
// Use the schema's `.pipe()` method rather than the generic `pipe` helper:
|
|
98
|
+
// it preserves the precise schema type through each refinement stage.
|
|
99
|
+
const stages = flattenPipelineStages(field.refinement).map((stage) => emitRefinementStage(ctx, stage));
|
|
100
|
+
return `${base}.pipe(${stages.join(", ")})`;
|
|
101
|
+
}
|
|
102
|
+
export function emitSchemaDeclaration(ctx, decl, isExport) {
|
|
103
|
+
const name = decl.id.name;
|
|
104
|
+
const exp = isExport ? "export " : "";
|
|
105
|
+
if (decl.typeParams?.length &&
|
|
106
|
+
decl.body.kind !== "TypeSignatureSchema" &&
|
|
107
|
+
decl.body.kind !== "TaggedUnionSchema" &&
|
|
108
|
+
decl.body.kind !== "RecordSchema" &&
|
|
109
|
+
decl.body.kind !== "StructuralUnionSchema") {
|
|
110
|
+
throw new FunScriptError("Generic runtime schemas are not supported yet; use a TypeScript type alias", decl.span);
|
|
111
|
+
}
|
|
112
|
+
switch (decl.body.kind) {
|
|
113
|
+
case "RecordSchema": {
|
|
114
|
+
if (ctx.recordContracts.has(name)) {
|
|
115
|
+
const brand = `${RECORD_CONTRACT_BRAND}$${name}`;
|
|
116
|
+
const typeParamsStr = ctx.emitTypeParameters(decl.typeParams);
|
|
117
|
+
const contract = `declare const ${brand}: unique symbol;\n${exp}type ${name}${typeParamsStr} = ${ctx.emitTypeNode(recordContractType(decl.body))} & { readonly [${brand}]?: never };`;
|
|
118
|
+
return contract + emitCheckedRecordDecoder(ctx, decl, exp);
|
|
119
|
+
}
|
|
120
|
+
if (decl.typeParams?.length)
|
|
121
|
+
return emitGenericDataSchema(ctx, decl, exp);
|
|
122
|
+
ctx.addEffectImport("Schema");
|
|
123
|
+
const schemaFields = decl.body.fields
|
|
124
|
+
.map((f) => {
|
|
125
|
+
const fieldKey = emitPropertyKey(f.name.name);
|
|
126
|
+
const optionInner = !f.defaultValue
|
|
127
|
+
? extractOptionInnerType(f.typeAnnotation)
|
|
128
|
+
: undefined;
|
|
129
|
+
if (optionInner) {
|
|
130
|
+
const innerSchema = emitSchemaTypeField(ctx, optionInner);
|
|
131
|
+
return ` ${fieldKey}: Schema.OptionFromOptionalNullOr(${innerSchema}, { onNoneEncoding: "omit" })`;
|
|
132
|
+
}
|
|
133
|
+
const schema = emitRecordFieldSchema(ctx, f);
|
|
134
|
+
if (!f.defaultValue)
|
|
135
|
+
return ` ${fieldKey}: ${schema}`;
|
|
136
|
+
ctx.addEffectImport("Effect");
|
|
137
|
+
return ` ${fieldKey}: ${schema}.pipe(Schema.withDecodingDefaultType(Effect.sync(() => ${ctx.emitExpression(f.defaultValue)})))`;
|
|
138
|
+
})
|
|
139
|
+
.join(",\n");
|
|
140
|
+
return `${exp}const ${name} = Schema.Struct({\n${schemaFields}\n});\n${exp}type ${name} = typeof ${name}.Type;\n${exp}const ${name}FromUnknown = (input: unknown): ${name} => Schema.decodeUnknownSync(${name})(input);`;
|
|
141
|
+
}
|
|
142
|
+
case "TaggedUnionSchema": {
|
|
143
|
+
ctx.addEffectImport("Data");
|
|
144
|
+
const typeParams = ctx.emitTypeParameters(decl.typeParams);
|
|
145
|
+
const hasTypeParams = Boolean(decl.typeParams && decl.typeParams.length > 0);
|
|
146
|
+
const anyArgs = hasTypeParams
|
|
147
|
+
? `<${decl.typeParams.map(() => "any").join(", ")}>`
|
|
148
|
+
: "";
|
|
149
|
+
const neverArgs = hasTypeParams
|
|
150
|
+
? `<${decl.typeParams.map(() => "never").join(", ")}>`
|
|
151
|
+
: "";
|
|
152
|
+
const typeArgs = hasTypeParams
|
|
153
|
+
? `<${decl.typeParams.map((tp) => tp.name.name).join(", ")}>`
|
|
154
|
+
: "";
|
|
155
|
+
const collectTypeParamNames = (type) => {
|
|
156
|
+
const names = new Set();
|
|
157
|
+
const walk = (t) => {
|
|
158
|
+
if (!t)
|
|
159
|
+
return;
|
|
160
|
+
if (t.kind === "TypeReferenceNode") {
|
|
161
|
+
names.add(t.name.name);
|
|
162
|
+
if (t.typeArgs)
|
|
163
|
+
t.typeArgs.forEach(walk);
|
|
164
|
+
}
|
|
165
|
+
else if (t.kind === "FunctionTypeNode") {
|
|
166
|
+
t.params.forEach((p) => walk(p.typeAnnotation));
|
|
167
|
+
walk(t.returnType);
|
|
168
|
+
}
|
|
169
|
+
else if (t.kind === "EffectTypeNode") {
|
|
170
|
+
walk(t.success);
|
|
171
|
+
walk(t.error);
|
|
172
|
+
walk(t.requirements);
|
|
173
|
+
}
|
|
174
|
+
else if (t.kind === "RecordTypeNode") {
|
|
175
|
+
t.fields.forEach((f) => walk(f.typeAnnotation));
|
|
176
|
+
}
|
|
177
|
+
else if (t.kind === "IntersectionTypeNode") {
|
|
178
|
+
t.types.forEach(walk);
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
walk(type);
|
|
182
|
+
return names;
|
|
183
|
+
};
|
|
184
|
+
const typeVariants = decl.body.variants
|
|
185
|
+
.map((v) => {
|
|
186
|
+
if (v.fields.length === 0) {
|
|
187
|
+
return ` ${v.name.name}: {}`;
|
|
188
|
+
}
|
|
189
|
+
const fields = v.fields
|
|
190
|
+
.map((f) => `readonly ${f.name.name}: ${ctx.emitTypeNode(f.typeAnnotation)}`)
|
|
191
|
+
.join("; ");
|
|
192
|
+
return ` ${v.name.name}: { ${fields} }`;
|
|
193
|
+
})
|
|
194
|
+
.join(";\n");
|
|
195
|
+
const constructors = decl.body.variants
|
|
196
|
+
.map((v) => {
|
|
197
|
+
if (v.fields.length === 0) {
|
|
198
|
+
const unionType = hasTypeParams ? `${name}${neverArgs}` : name;
|
|
199
|
+
const retType = `${unionType} & { readonly _tag: ${JSON.stringify(v.name.name)} }`;
|
|
200
|
+
return `${exp}const ${v.name.name}: ${retType} = $${name}.${v.name.name}();`;
|
|
201
|
+
}
|
|
202
|
+
const usedParams = new Set();
|
|
203
|
+
for (const f of v.fields) {
|
|
204
|
+
for (const pName of collectTypeParamNames(f.typeAnnotation)) {
|
|
205
|
+
usedParams.add(pName);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
let constrTypeParams = "";
|
|
209
|
+
if (hasTypeParams) {
|
|
210
|
+
const requiredParams = decl.typeParams.filter((tp) => usedParams.has(tp.name.name));
|
|
211
|
+
const optionalParams = decl.typeParams.filter((tp) => !usedParams.has(tp.name.name));
|
|
212
|
+
const paramsList = [
|
|
213
|
+
...requiredParams.map((tp) => tp.name.name),
|
|
214
|
+
...optionalParams.map((tp) => `${tp.name.name} = never`),
|
|
215
|
+
];
|
|
216
|
+
// A trailing comma disambiguates a single generic parameter from
|
|
217
|
+
// a JSX opening tag in emitted TSX files.
|
|
218
|
+
constrTypeParams = `<${paramsList.join(", ")}${paramsList.length === 1 ? "," : ""}>`;
|
|
219
|
+
}
|
|
220
|
+
const params = v.fields
|
|
221
|
+
.map((f) => `${f.name.name}: ${ctx.emitTypeNode(f.typeAnnotation)}`)
|
|
222
|
+
.join(", ");
|
|
223
|
+
const args = v.fields.map((f) => f.name.name).join(", ");
|
|
224
|
+
const unionType = hasTypeParams ? `${name}${typeArgs}` : name;
|
|
225
|
+
const retType = `${unionType} & { readonly _tag: ${JSON.stringify(v.name.name)} }`;
|
|
226
|
+
return `${exp}const ${v.name.name} = ${constrTypeParams}(${params}): ${retType} => $${name}.${v.name.name}({ ${args} });`;
|
|
227
|
+
})
|
|
228
|
+
.join("\n");
|
|
229
|
+
return `${exp}type ${name}${typeParams} = Data.TaggedEnum<{\n${typeVariants}\n}>;\nconst $${name} = Data.taggedEnum<${name}${anyArgs}>();\n${constructors}`;
|
|
230
|
+
}
|
|
231
|
+
case "StructuralUnionSchema": {
|
|
232
|
+
if (decl.typeParams?.length)
|
|
233
|
+
return emitGenericDataSchema(ctx, decl, exp);
|
|
234
|
+
ctx.addEffectImport("Schema");
|
|
235
|
+
const members = decl.body.members
|
|
236
|
+
.map((member) => emitSchemaTypeField(ctx, member))
|
|
237
|
+
.join(", ");
|
|
238
|
+
return `${exp}const ${name} = Schema.Union([${members}]);\n${exp}type ${name} = typeof ${name}.Type;\n${exp}const ${name}FromUnknown = (input: unknown): ${name} => Schema.decodeUnknownSync(${name})(input);`;
|
|
239
|
+
}
|
|
240
|
+
case "RefinementSchema": {
|
|
241
|
+
const stages = flattenPipelineStages(decl.body.refinement);
|
|
242
|
+
const brands = extractBrandNames(stages);
|
|
243
|
+
if (brands.length > 0) {
|
|
244
|
+
ctx.addEffectImport("Schema");
|
|
245
|
+
ctx.addEffectImport("Brand");
|
|
246
|
+
const baseSchema = emitSchemaTypeField(ctx, decl.body.baseType);
|
|
247
|
+
const emittedStages = stages.map((s) => emitRefinementStage(ctx, s));
|
|
248
|
+
const baseTypeName = decl.body.baseType.kind === "TypeReferenceNode" &&
|
|
249
|
+
decl.body.baseType.name.name === "Int"
|
|
250
|
+
? "number"
|
|
251
|
+
: ctx.emitTypeNode(decl.body.baseType);
|
|
252
|
+
const brandTypeStr = brands
|
|
253
|
+
.map((b) => `Brand.Brand<${JSON.stringify(b)}>`)
|
|
254
|
+
.join(" & ");
|
|
255
|
+
const typeDef = `${baseTypeName} & ${brandTypeStr}`;
|
|
256
|
+
return `${exp}const ${name} = ${baseSchema}.pipe(${emittedStages.join(", ")});\n${exp}type ${name} = ${typeDef};\n${exp}const ${name}FromUnknown = (input: unknown): ${name} => Schema.decodeUnknownSync(${name})(input);`;
|
|
257
|
+
}
|
|
258
|
+
ctx.addEffectImport("Schema");
|
|
259
|
+
const baseSchema = emitSchemaTypeField(ctx, decl.body.baseType);
|
|
260
|
+
const refinementStages = flattenPipelineStages(decl.body.refinement).map((stage) => emitRefinementStage(ctx, stage));
|
|
261
|
+
return `${exp}const ${name} = ${baseSchema}.pipe(${refinementStages.join(", ")});\n${exp}type ${name} = typeof ${name}.Type;\n${exp}const ${name}FromUnknown = (input: unknown): ${name} => Schema.decodeUnknownSync(${name})(input);`;
|
|
262
|
+
}
|
|
263
|
+
case "TypeSignatureSchema": {
|
|
264
|
+
return `${exp}type ${name}${ctx.emitTypeParameters(decl.typeParams)} = ${ctx.emitTypeNode(decl.body.signature)};`;
|
|
265
|
+
}
|
|
266
|
+
case "TsDerivedSchema": {
|
|
267
|
+
ctx.addEffectImport("Schema");
|
|
268
|
+
let schemaExpr;
|
|
269
|
+
const targetType = decl.body.targetType;
|
|
270
|
+
if (targetType.kind === "TypeReferenceNode" &&
|
|
271
|
+
ctx.options.importedSchemas?.has(decl.id.name)) {
|
|
272
|
+
schemaExpr = ctx.options.importedSchemas.get(decl.id.name);
|
|
273
|
+
}
|
|
274
|
+
else if (targetType.kind === "TypeReferenceNode" &&
|
|
275
|
+
ctx.recordContracts.has(targetType.name.name)) {
|
|
276
|
+
schemaExpr = emitSchemaTypeField(ctx, targetType);
|
|
277
|
+
}
|
|
278
|
+
else if (targetType.kind === "TypeReferenceNode" &&
|
|
279
|
+
!PRIMITIVE_TYPES[targetType.name.name] &&
|
|
280
|
+
targetType.name.name !== "Duration" &&
|
|
281
|
+
targetType.name.name !== "UUID" &&
|
|
282
|
+
!ctx.declaredTypeNames.has(targetType.name.name) &&
|
|
283
|
+
targetType.name.name !== "Option" &&
|
|
284
|
+
targetType.name.name !== "Array" &&
|
|
285
|
+
targetType.name.name !== "Record") {
|
|
286
|
+
schemaExpr =
|
|
287
|
+
ctx.options.importedSchemas?.get(decl.id.name) ??
|
|
288
|
+
`(Schema.Unknown as unknown as Schema.Codec<${ctx.emitTypeNode(targetType)}>)`;
|
|
289
|
+
}
|
|
290
|
+
else {
|
|
291
|
+
schemaExpr =
|
|
292
|
+
ctx.options.importedSchemas?.get(decl.id.name) ??
|
|
293
|
+
emitSchemaTypeField(ctx, targetType);
|
|
294
|
+
}
|
|
295
|
+
return `${exp}const ${name} = ${schemaExpr};\n${exp}type ${name} = typeof ${name}.Type;\n${exp}const ${name}FromUnknown = (input: unknown): ${name} => Schema.decodeUnknownSync(${name})(input);`;
|
|
296
|
+
}
|
|
297
|
+
case "ImportedTsSchema": {
|
|
298
|
+
ctx.addEffectImport("Schema");
|
|
299
|
+
const schemaExpr = ctx.options.importedSchemas?.get(decl.id.name) ??
|
|
300
|
+
`(Schema.Unknown as unknown as Schema.Codec<${ctx.emitTypeNode(decl.body.typeNode)}>)`;
|
|
301
|
+
return `${exp}const ${name} = ${schemaExpr};\n${exp}type ${name} = typeof ${name}.Type;\n${exp}const ${name}FromUnknown = (input: unknown): ${name} => Schema.decodeUnknownSync(${name})(input);`;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
function emitGenericDataSchema(ctx, decl, exp) {
|
|
306
|
+
if ((decl.body.kind !== "RecordSchema" &&
|
|
307
|
+
decl.body.kind !== "StructuralUnionSchema") ||
|
|
308
|
+
!decl.typeParams?.length)
|
|
309
|
+
throw new Error("Expected a generic record or union schema");
|
|
310
|
+
const parameters = decl.typeParams.map((param) => param.name.name);
|
|
311
|
+
const names = new Set(parameters);
|
|
312
|
+
if (ctx.unsafeSchemaBinding ||
|
|
313
|
+
ctx.declaredTypeNames.has("Schema") ||
|
|
314
|
+
ctx.bindings.has("Schema")) {
|
|
315
|
+
throw new FunScriptError("Generic data schemas require 'Schema' to refer to Effect Schema; rename the conflicting declaration or import.", decl.span);
|
|
316
|
+
}
|
|
317
|
+
if (names.size !== parameters.length ||
|
|
318
|
+
decl.typeParams.some((param) => param.constraint ||
|
|
319
|
+
[
|
|
320
|
+
"Schema",
|
|
321
|
+
"String",
|
|
322
|
+
"Number",
|
|
323
|
+
"Boolean",
|
|
324
|
+
"Array",
|
|
325
|
+
"Option",
|
|
326
|
+
"Record",
|
|
327
|
+
decl.id.name,
|
|
328
|
+
].includes(param.name.name))) {
|
|
329
|
+
throw new FunScriptError("Generic data schemas require distinct, unconstrained type parameters that do not shadow built-in schema names.", decl.span);
|
|
330
|
+
}
|
|
331
|
+
const visitFactory = (name, active) => {
|
|
332
|
+
if (active.has(name))
|
|
333
|
+
return false;
|
|
334
|
+
const target = ctx.genericSchemaDeclarations.get(name);
|
|
335
|
+
if (!target ||
|
|
336
|
+
(target.body.kind !== "RecordSchema" &&
|
|
337
|
+
target.body.kind !== "StructuralUnionSchema"))
|
|
338
|
+
return true;
|
|
339
|
+
const next = new Set(active).add(name);
|
|
340
|
+
const params = new Set(target.typeParams?.map((param) => param.name.name));
|
|
341
|
+
const visitType = (type) => {
|
|
342
|
+
if (type.kind === "ParenthesizedTypeNode")
|
|
343
|
+
return visitType(type.typeNode);
|
|
344
|
+
if (type.kind === "ArrayTypeNode")
|
|
345
|
+
return visitType(type.elementType);
|
|
346
|
+
if (type.kind === "UnionTypeNode")
|
|
347
|
+
return type.types.every(visitType);
|
|
348
|
+
if (type.kind === "RecordTypeNode")
|
|
349
|
+
return type.fields.every((field) => visitType(field.typeAnnotation));
|
|
350
|
+
if (type.kind !== "TypeReferenceNode")
|
|
351
|
+
return true;
|
|
352
|
+
return ((params.has(type.name.name) ||
|
|
353
|
+
!ctx.genericSchemaDeclarations.has(type.name.name) ||
|
|
354
|
+
visitFactory(type.name.name, next)) &&
|
|
355
|
+
(type.typeArgs?.every(visitType) ?? true));
|
|
356
|
+
};
|
|
357
|
+
if (target.body.kind === "RecordSchema") {
|
|
358
|
+
return target.body.fields.every((field) => visitType(field.typeAnnotation));
|
|
359
|
+
}
|
|
360
|
+
return target.body.members.every(visitType);
|
|
361
|
+
};
|
|
362
|
+
if (!visitFactory(decl.id.name, new Set())) {
|
|
363
|
+
throw new FunScriptError(`Generic data schema '${decl.id.name}' cannot use recursive generic schema factories.`, decl.span);
|
|
364
|
+
}
|
|
365
|
+
const supportsArgument = (type) => {
|
|
366
|
+
if (type.kind === "ParenthesizedTypeNode")
|
|
367
|
+
return supportsArgument(type.typeNode);
|
|
368
|
+
if (type.kind !== "TypeReferenceNode")
|
|
369
|
+
return false;
|
|
370
|
+
const name = type.name.name;
|
|
371
|
+
if (names.has(name))
|
|
372
|
+
return !type.typeArgs?.length;
|
|
373
|
+
if (["String", "Number", "Boolean"].includes(name))
|
|
374
|
+
return !type.typeArgs?.length && !ctx.declaredTypeNames.has(name);
|
|
375
|
+
if (name === "Array" || name === "Option")
|
|
376
|
+
return type.typeArgs?.length === 1 && supportsArgument(type.typeArgs[0]);
|
|
377
|
+
const arity = ctx.genericDataSchemas.get(name) ??
|
|
378
|
+
ctx.options.importedGenericDataSchemas?.get(name);
|
|
379
|
+
if (arity !== undefined)
|
|
380
|
+
return (type.typeArgs?.length === arity && type.typeArgs.every(supportsArgument));
|
|
381
|
+
return (!type.typeArgs?.length &&
|
|
382
|
+
((ctx.runtimeSchemaNames.has(name) &&
|
|
383
|
+
!ctx.genericDataSchemas.has(name)) ||
|
|
384
|
+
ctx.options.importedDataSchemas?.has(name) === true));
|
|
385
|
+
};
|
|
386
|
+
const supports = (type) => {
|
|
387
|
+
if (type.kind === "ParenthesizedTypeNode")
|
|
388
|
+
return supports(type.typeNode);
|
|
389
|
+
if (type.kind === "LiteralTypeNode")
|
|
390
|
+
return true;
|
|
391
|
+
if (type.kind === "ArrayTypeNode")
|
|
392
|
+
return supports(type.elementType);
|
|
393
|
+
if (type.kind === "UnionTypeNode")
|
|
394
|
+
return type.types.every(supports);
|
|
395
|
+
if (type.kind === "RecordTypeNode")
|
|
396
|
+
return type.fields.every((field) => field.name.name !== "__proto__" &&
|
|
397
|
+
!field.defaultValue &&
|
|
398
|
+
supports(field.typeAnnotation));
|
|
399
|
+
if (type.kind !== "TypeReferenceNode")
|
|
400
|
+
return false;
|
|
401
|
+
const name = type.name.name;
|
|
402
|
+
if (names.has(name))
|
|
403
|
+
return !type.typeArgs?.length;
|
|
404
|
+
if (["String", "Number", "Boolean"].includes(name))
|
|
405
|
+
return !type.typeArgs?.length && !ctx.declaredTypeNames.has(name);
|
|
406
|
+
if (name === "Array" || name === "Option" || name === "JSNullish")
|
|
407
|
+
return type.typeArgs?.length === 1 && supports(type.typeArgs[0]);
|
|
408
|
+
const arity = ctx.genericDataSchemas.get(name) ??
|
|
409
|
+
ctx.options.importedGenericDataSchemas?.get(name);
|
|
410
|
+
if (arity !== undefined)
|
|
411
|
+
return (type.typeArgs?.length === arity && type.typeArgs.every(supportsArgument));
|
|
412
|
+
return (!type.typeArgs?.length &&
|
|
413
|
+
((ctx.runtimeSchemaNames.has(name) &&
|
|
414
|
+
!ctx.genericDataSchemas.has(name)) ||
|
|
415
|
+
ctx.options.importedDataSchemas?.has(name) === true));
|
|
416
|
+
};
|
|
417
|
+
if (decl.body.kind === "RecordSchema") {
|
|
418
|
+
for (const field of decl.body.fields) {
|
|
419
|
+
if (field.name.name === "__proto__" ||
|
|
420
|
+
field.defaultValue ||
|
|
421
|
+
!supports(field.typeAnnotation)) {
|
|
422
|
+
throw new FunScriptError(`Generic data schema '${decl.id.name}' currently supports required or optional fields with primitive, local data-schema, type-parameter, array, union, verified generic application, or nested required-record types. Field '${field.name.name}' needs an explicit non-generic schema or contract.`, field.span);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
else {
|
|
427
|
+
for (const member of decl.body.members) {
|
|
428
|
+
if (!supports(member)) {
|
|
429
|
+
throw new FunScriptError(`Generic data schema '${decl.id.name}' currently supports primitive, local data-schema, type-parameter, array, union, verified generic application, or nested required-record types in union members. Member '${ctx.emitTypeNode(member)}' needs an explicit non-generic schema or contract.`, member.span);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
ctx.addEffectImport("Schema");
|
|
434
|
+
ctx.addEffectImport("SchemaAST as $funscriptSchemaAST");
|
|
435
|
+
const body = decl.body;
|
|
436
|
+
return ctx.withSchemaParameters(names, () => {
|
|
437
|
+
const args = parameters
|
|
438
|
+
.map((param) => `${param} extends Schema.Constraint & { readonly "~type.optionality": "required"; readonly "~type.mutability": "readonly" }`)
|
|
439
|
+
.join(", ");
|
|
440
|
+
const values = parameters.map((param) => `${param}: ${param}`).join(", ");
|
|
441
|
+
const checks = parameters
|
|
442
|
+
.map((param) => ` if (!Schema.isSchema(${param}) || $funscriptSchemaAST.isOptional($funscriptSchemaAST.toType(${param}.ast)) || $funscriptSchemaAST.toType(${param}.ast).context?.isMutable) throw new TypeError(${JSON.stringify(`${decl.id.name} requires a schema without optional-key or mutable-key modifiers for ${param}`)});`)
|
|
443
|
+
.join("\n");
|
|
444
|
+
if (body.kind === "RecordSchema") {
|
|
445
|
+
const fields = body.fields
|
|
446
|
+
.map((field) => {
|
|
447
|
+
const optionInner = !field.defaultValue
|
|
448
|
+
? extractOptionInnerType(field.typeAnnotation)
|
|
449
|
+
: undefined;
|
|
450
|
+
if (optionInner) {
|
|
451
|
+
const innerSchema = emitSchemaTypeField(ctx, optionInner);
|
|
452
|
+
return ` ${emitPropertyKey(field.name.name)}: Schema.OptionFromOptionalNullOr(${innerSchema}, { onNoneEncoding: "omit" })`;
|
|
453
|
+
}
|
|
454
|
+
const schema = emitRecordFieldSchema(ctx, field);
|
|
455
|
+
return ` ${emitPropertyKey(field.name.name)}: ${schema}`;
|
|
456
|
+
})
|
|
457
|
+
.join(",\n");
|
|
458
|
+
const dataType = `{ ${body.fields
|
|
459
|
+
.map((field) => {
|
|
460
|
+
const type = ctx.emitTypeNode(field.typeAnnotation);
|
|
461
|
+
return `readonly ${emitPropertyKey(field.name.name)}: ${type}`;
|
|
462
|
+
})
|
|
463
|
+
.join("; ")} }`;
|
|
464
|
+
return `${exp}const ${decl.id.name} = <${args}>(${values}) => {\n${checks}\n return Schema.Struct({\n${fields}\n });\n};\n${exp}type ${decl.id.name}<${parameters.join(", ")}> = ${dataType};`;
|
|
465
|
+
}
|
|
466
|
+
else {
|
|
467
|
+
const members = body.members
|
|
468
|
+
.map((member) => emitSchemaTypeField(ctx, member))
|
|
469
|
+
.join(", ");
|
|
470
|
+
const dataType = body.members
|
|
471
|
+
.map((member) => ctx.emitTypeNode(member))
|
|
472
|
+
.join(" | ");
|
|
473
|
+
return `${exp}const ${decl.id.name} = <${args}>(${values}) => {\n${checks}\n return Schema.Union([${members}]);\n};\n${exp}type ${decl.id.name}<${parameters.join(", ")}> = ${dataType};`;
|
|
474
|
+
}
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
function emitCheckedRecordDecoder(ctx, decl, exp) {
|
|
478
|
+
if (decl.body.kind !== "RecordSchema" || decl.typeParams?.length)
|
|
479
|
+
return "";
|
|
480
|
+
const primitive = (type) => type?.kind === "TypeReferenceNode" &&
|
|
481
|
+
!type.typeArgs?.length &&
|
|
482
|
+
["String", "Number", "Boolean"].includes(type.name.name) &&
|
|
483
|
+
!ctx.declaredTypeNames.has(type.name.name);
|
|
484
|
+
const codec = (type) => !!type &&
|
|
485
|
+
type.kind === "TypeReferenceNode" &&
|
|
486
|
+
((!type.typeArgs?.length &&
|
|
487
|
+
(primitive(type) ||
|
|
488
|
+
ctx.identityRecordSchemas.has(type.name.name) ||
|
|
489
|
+
ctx.checkedTaggedSchemas.has(type.name.name) ||
|
|
490
|
+
ctx.options.importedIdentitySchemas?.has(type.name.name) === true)) ||
|
|
491
|
+
(type.name.name === "Option" &&
|
|
492
|
+
type.typeArgs?.length === 1 &&
|
|
493
|
+
codec(type.typeArgs[0])));
|
|
494
|
+
const fields = decl.body.fields;
|
|
495
|
+
const hasEffect = fields.some((field) => field.typeAnnotation.kind === "FunctionTypeNode" &&
|
|
496
|
+
field.typeAnnotation.returnType.kind === "EffectTypeNode");
|
|
497
|
+
if (!fields.some((field) => field.typeAnnotation.kind === "FunctionTypeNode"))
|
|
498
|
+
return "";
|
|
499
|
+
for (const field of fields) {
|
|
500
|
+
if (field.defaultValue || field.name.name === "__proto__")
|
|
501
|
+
return "";
|
|
502
|
+
const type = field.typeAnnotation;
|
|
503
|
+
if (type.kind === "FunctionTypeNode") {
|
|
504
|
+
if (type.typeParams?.length ||
|
|
505
|
+
type.params.some((param) => param.isRest || !codec(param.typeAnnotation)))
|
|
506
|
+
return "";
|
|
507
|
+
if (type.returnType.kind === "EffectTypeNode") {
|
|
508
|
+
if (!codec(type.returnType.success))
|
|
509
|
+
return "";
|
|
510
|
+
}
|
|
511
|
+
else if (hasEffect ||
|
|
512
|
+
!(primitive(type.returnType) ||
|
|
513
|
+
(type.returnType.kind === "TypeReferenceNode" &&
|
|
514
|
+
type.returnType.name.name === "Void" &&
|
|
515
|
+
!type.returnType.typeArgs?.length &&
|
|
516
|
+
!ctx.declaredTypeNames.has("Void"))))
|
|
517
|
+
return "";
|
|
518
|
+
}
|
|
519
|
+
else if (!codec(type))
|
|
520
|
+
return "";
|
|
521
|
+
}
|
|
522
|
+
const name = `${decl.id.name}DecodeChecked`;
|
|
523
|
+
if (ctx.bindings.has(name) ||
|
|
524
|
+
ctx.declaredTypeNames.has(name) ||
|
|
525
|
+
ctx.userImportBindings.has(name)) {
|
|
526
|
+
return "";
|
|
527
|
+
}
|
|
528
|
+
if (hasEffect) {
|
|
529
|
+
const checkedName = `${decl.id.name}Checked`;
|
|
530
|
+
if (ctx.declaredTypeNames.has(checkedName) ||
|
|
531
|
+
ctx.bindings.has(checkedName) ||
|
|
532
|
+
ctx.userImportBindings.has(checkedName))
|
|
533
|
+
return "";
|
|
534
|
+
}
|
|
535
|
+
ctx.addEffectImport("Schema");
|
|
536
|
+
ctx.needsCheckedRecordDecoder = true;
|
|
537
|
+
const checkedCodec = (type) => {
|
|
538
|
+
if (type.kind === "TypeReferenceNode") {
|
|
539
|
+
const tagged = ctx.checkedTaggedSchemas.get(type.name.name);
|
|
540
|
+
if (tagged) {
|
|
541
|
+
const checks = tagged.variants
|
|
542
|
+
.map((variant) => {
|
|
543
|
+
const clauses = [
|
|
544
|
+
`($value as { readonly _tag?: unknown })._tag === ${JSON.stringify(variant.name.name)}`,
|
|
545
|
+
];
|
|
546
|
+
for (const field of variant.fields) {
|
|
547
|
+
const fieldType = field.typeAnnotation.name
|
|
548
|
+
.name;
|
|
549
|
+
const access = `($value as { readonly [key: string]: unknown })[${JSON.stringify(field.name.name)}]`;
|
|
550
|
+
if (ctx.identityRecordSchemas.has(fieldType) ||
|
|
551
|
+
ctx.options.importedIdentitySchemas?.has(fieldType)) {
|
|
552
|
+
clauses.push(`Schema.is(${fieldType})(${access})`);
|
|
553
|
+
}
|
|
554
|
+
else {
|
|
555
|
+
clauses.push(`typeof ${access} === ${JSON.stringify(fieldType.toLowerCase())}`);
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
return `(${clauses.join(" && ")})`;
|
|
559
|
+
})
|
|
560
|
+
.join(" || ");
|
|
561
|
+
return `Schema.declare(($value: unknown): $value is ${ctx.emitTypeNode(type)} => typeof $value === "object" && $value !== null && !globalThis.Array.isArray($value) && (${checks}))`;
|
|
562
|
+
}
|
|
563
|
+
if (ctx.options.importedIdentitySchemas?.has(type.name.name))
|
|
564
|
+
return type.name.name;
|
|
565
|
+
}
|
|
566
|
+
return emitSchemaTypeField(ctx, type);
|
|
567
|
+
};
|
|
568
|
+
const data = fields
|
|
569
|
+
.filter((field) => field.typeAnnotation.kind !== "FunctionTypeNode")
|
|
570
|
+
.map((field) => {
|
|
571
|
+
const optionInner = extractOptionInnerType(field.typeAnnotation);
|
|
572
|
+
if (optionInner) {
|
|
573
|
+
return `${emitPropertyKey(field.name.name)}: Schema.OptionFromOptionalNullOr(${checkedCodec(optionInner)}, { onNoneEncoding: "omit" })`;
|
|
574
|
+
}
|
|
575
|
+
return `${emitPropertyKey(field.name.name)}: ${checkedCodec(field.typeAnnotation)}`;
|
|
576
|
+
})
|
|
577
|
+
.join(", ");
|
|
578
|
+
const callbacks = fields
|
|
579
|
+
.filter((field) => field.typeAnnotation.kind === "FunctionTypeNode")
|
|
580
|
+
.map((field) => {
|
|
581
|
+
const type = field.typeAnnotation;
|
|
582
|
+
const args = type.params
|
|
583
|
+
.map((param) => checkedCodec(param.typeAnnotation))
|
|
584
|
+
.join(", ");
|
|
585
|
+
if (type.returnType.kind === "EffectTypeNode") {
|
|
586
|
+
ctx.checkedCallbackKinds.add("effect");
|
|
587
|
+
const callbackType = `${decl.id.name}[${JSON.stringify(field.name.name)}]`;
|
|
588
|
+
return `${emitPropertyKey(field.name.name)}: ($value: unknown) => $funscriptCheckedEffect($value as ${callbackType}, Schema.Tuple([${args}]), ${checkedCodec(type.returnType.success)})`;
|
|
589
|
+
}
|
|
590
|
+
if (type.returnType.kind === "TypeReferenceNode" &&
|
|
591
|
+
type.returnType.name.name === "Void") {
|
|
592
|
+
ctx.checkedCallbackKinds.add("void");
|
|
593
|
+
return `${emitPropertyKey(field.name.name)}: ($value: unknown) => $funscriptCheckedSyncVoid($value, Schema.Tuple([${args}]), ${type.params.length})`;
|
|
594
|
+
}
|
|
595
|
+
ctx.checkedCallbackKinds.add("sync");
|
|
596
|
+
return `${emitPropertyKey(field.name.name)}: ($value: unknown) => $funscriptCheckedSync($value, Schema.Tuple([${args}]), ${emitSchemaTypeField(ctx, type.returnType)})`;
|
|
597
|
+
})
|
|
598
|
+
.join(", ");
|
|
599
|
+
if (hasEffect) {
|
|
600
|
+
const callbackFields = fields.filter((field) => field.typeAnnotation.kind === "FunctionTypeNode");
|
|
601
|
+
const keys = callbackFields
|
|
602
|
+
.map((field) => JSON.stringify(field.name.name))
|
|
603
|
+
.join(" | ");
|
|
604
|
+
const checkedFields = callbackFields
|
|
605
|
+
.map((field) => {
|
|
606
|
+
const type = field.typeAnnotation;
|
|
607
|
+
const output = type.returnType;
|
|
608
|
+
const params = type.params
|
|
609
|
+
.map((param) => `${ctx.emitBindingTarget(param.name)}: ${ctx.emitTypeNode(param.typeAnnotation)}`)
|
|
610
|
+
.join(", ");
|
|
611
|
+
const error = output.error ? ctx.emitTypeNode(output.error) : "never";
|
|
612
|
+
const requirements = output.requirements
|
|
613
|
+
? ctx.emitTypeNode(output.requirements)
|
|
614
|
+
: "never";
|
|
615
|
+
ctx.addEffectImport("Effect");
|
|
616
|
+
return `${emitPropertyKey(field.name.name)}: (${params}) => Effect.Effect<${ctx.emitTypeNode(output.success)}, ${error} | $funscriptCallbackBoundaryError, ${requirements}>`;
|
|
617
|
+
})
|
|
618
|
+
.join("; ");
|
|
619
|
+
const checkedName = `${decl.id.name}Checked`;
|
|
620
|
+
return `\n${exp}type ${checkedName} = Omit<${decl.id.name}, ${keys}> & { ${checkedFields} };\n${exp}const ${name} = ($input: ${decl.id.name}): ${checkedName} => $funscriptDecodeCheckedRecord($input, Schema.Struct({ ${data} }), { ${callbacks} });`;
|
|
621
|
+
}
|
|
622
|
+
return `\n${exp}const ${name} = ($input: unknown): ${decl.id.name} => $funscriptDecodeCheckedRecord($input, Schema.Struct({ ${data} }), { ${callbacks} }, [] as const);`;
|
|
623
|
+
}
|
|
624
|
+
function extractOptionInnerType(typeNode) {
|
|
625
|
+
if (typeNode.kind === "TypeReferenceNode" &&
|
|
626
|
+
typeNode.name.name === "Option" &&
|
|
627
|
+
typeNode.typeArgs?.length === 1) {
|
|
628
|
+
return typeNode.typeArgs[0];
|
|
629
|
+
}
|
|
630
|
+
return undefined;
|
|
631
|
+
}
|
|
632
|
+
export function emitSchemaTypeField(ctx, typeNode) {
|
|
633
|
+
if (typeNode.kind === "QualifiedTypeReferenceNode" ||
|
|
634
|
+
typeNode.kind === "TypeQueryNode" ||
|
|
635
|
+
typeNode.kind === "IndexedAccessTypeNode") {
|
|
636
|
+
ctx.addEffectImport("Schema");
|
|
637
|
+
return `(Schema.Unknown as unknown as Schema.Codec<${ctx.emitTypeNode(typeNode)}>)`;
|
|
638
|
+
}
|
|
639
|
+
if (typeNode.kind === "ParenthesizedTypeNode") {
|
|
640
|
+
return emitSchemaTypeField(ctx, typeNode.typeNode);
|
|
641
|
+
}
|
|
642
|
+
ctx.addEffectImport("Schema");
|
|
643
|
+
if (typeNode.kind === "LiteralTypeNode")
|
|
644
|
+
return `Schema.Literal(${JSON.stringify(typeNode.value)})`;
|
|
645
|
+
if (typeNode.kind === "FunctionTypeNode" ||
|
|
646
|
+
typeNode.kind === "EffectTypeNode") {
|
|
647
|
+
throw new FunScriptError("Runtime schema fields cannot validate function or Effect types; use a separate type or an explicit schema", typeNode.span);
|
|
648
|
+
}
|
|
649
|
+
if (typeNode.kind === "RecordTypeNode") {
|
|
650
|
+
const inner = typeNode.fields
|
|
651
|
+
.map((f) => {
|
|
652
|
+
const fieldKey = emitPropertyKey(f.name.name);
|
|
653
|
+
const optionInner = !f.defaultValue
|
|
654
|
+
? extractOptionInnerType(f.typeAnnotation)
|
|
655
|
+
: undefined;
|
|
656
|
+
if (optionInner) {
|
|
657
|
+
const innerSchema = emitSchemaTypeField(ctx, optionInner);
|
|
658
|
+
return ` ${fieldKey}: Schema.OptionFromOptionalNullOr(${innerSchema}, { onNoneEncoding: "omit" })`;
|
|
659
|
+
}
|
|
660
|
+
const schema = emitSchemaTypeField(ctx, f.typeAnnotation);
|
|
661
|
+
if (f.defaultValue) {
|
|
662
|
+
ctx.addEffectImport("Effect");
|
|
663
|
+
return ` ${fieldKey}: ${schema}.pipe(Schema.withDecodingDefaultType(Effect.sync(() => ${ctx.emitExpression(f.defaultValue)})))`;
|
|
664
|
+
}
|
|
665
|
+
return ` ${fieldKey}: ${schema}`;
|
|
666
|
+
})
|
|
667
|
+
.join(",\n");
|
|
668
|
+
return `Schema.Struct({\n${inner}\n})`;
|
|
669
|
+
}
|
|
670
|
+
if (typeNode.kind === "ArrayTypeNode") {
|
|
671
|
+
return `Schema.Array(${emitSchemaTypeField(ctx, typeNode.elementType)})`;
|
|
672
|
+
}
|
|
673
|
+
if (typeNode.kind === "UnionTypeNode") {
|
|
674
|
+
return `Schema.Union([${typeNode.types.map((type) => emitSchemaTypeField(ctx, type)).join(", ")}])`;
|
|
675
|
+
}
|
|
676
|
+
if (typeNode.kind === "TypeReferenceNode") {
|
|
677
|
+
const tName = typeNode.name.name;
|
|
678
|
+
if (ctx.activeSchemaParameters?.has(tName))
|
|
679
|
+
return tName;
|
|
680
|
+
if (tName === "SchemaInput" && !ctx.declaredTypeNames.has(tName)) {
|
|
681
|
+
throw new Error("SchemaInput is a static input type, not a runtime schema; use the schema itself for validation");
|
|
682
|
+
}
|
|
683
|
+
if (PRIMITIVE_TYPES[tName] || tName === "Duration")
|
|
684
|
+
return `Schema.${tName}`;
|
|
685
|
+
if (tName === "UUID")
|
|
686
|
+
return "Schema.UUID";
|
|
687
|
+
if (tName === "Int")
|
|
688
|
+
return "Schema.Int";
|
|
689
|
+
if (tName === "Option" && typeNode.typeArgs) {
|
|
690
|
+
return `Schema.Option(${emitSchemaTypeField(ctx, typeNode.typeArgs[0])})`;
|
|
691
|
+
}
|
|
692
|
+
if ((tName === "JSOptional" || tName === "JSNullish") &&
|
|
693
|
+
typeNode.typeArgs?.length === 1) {
|
|
694
|
+
return `Schema.NullishOr(${emitSchemaTypeField(ctx, typeNode.typeArgs[0])})`;
|
|
695
|
+
}
|
|
696
|
+
if (tName === "JSNullish") {
|
|
697
|
+
throw new FunScriptError("JSNullish requires exactly one type argument", typeNode.span);
|
|
698
|
+
}
|
|
699
|
+
if (tName === "Array" && typeNode.typeArgs?.length === 1) {
|
|
700
|
+
return `Schema.Array(${emitSchemaTypeField(ctx, typeNode.typeArgs[0])})`;
|
|
701
|
+
}
|
|
702
|
+
if (tName === "Record" && typeNode.typeArgs?.length === 2) {
|
|
703
|
+
return `Schema.Record(${emitSchemaTypeField(ctx, typeNode.typeArgs[0])}, ${emitSchemaTypeField(ctx, typeNode.typeArgs[1])})`;
|
|
704
|
+
}
|
|
705
|
+
const genericArity = ctx.genericDataSchemas.get(tName) ??
|
|
706
|
+
ctx.options.importedGenericDataSchemas?.get(tName);
|
|
707
|
+
if (genericArity !== undefined) {
|
|
708
|
+
if (typeNode.typeArgs?.length !== genericArity)
|
|
709
|
+
throw new FunScriptError(`Generic data schema '${tName}' requires ${genericArity} schema argument(s).`, typeNode.span);
|
|
710
|
+
return `${tName}(${typeNode.typeArgs.map((arg) => emitGenericSchemaArgument(ctx, arg, ctx.options.importedGenericDataSchemas?.has(tName) === true)).join(", ")})`;
|
|
711
|
+
}
|
|
712
|
+
if (ctx.runtimeSchemaNames.has(tName))
|
|
713
|
+
return tName;
|
|
714
|
+
if (ctx.options.importedSchemas?.has(tName))
|
|
715
|
+
return ctx.options.importedSchemas.get(tName);
|
|
716
|
+
if (ctx.userImportBindings.has(tName)) {
|
|
717
|
+
if (typeNode.typeArgs?.length)
|
|
718
|
+
throw new FunScriptError(`Cannot derive a runtime schema for imported generic '${tName}' here. Instantiate its schema factory explicitly.`, typeNode.span);
|
|
719
|
+
return tName;
|
|
720
|
+
}
|
|
721
|
+
if (ctx.recordContracts.has(tName)) {
|
|
722
|
+
const contract = ctx.recordContracts.get(tName);
|
|
723
|
+
return emitSchemaTypeField(ctx, contract);
|
|
724
|
+
}
|
|
725
|
+
if (typeNode.typeArgs?.length)
|
|
726
|
+
throw new FunScriptError(`Cannot derive a runtime schema for generic '${tName}' here. Provide a concrete runtime schema explicitly.`, typeNode.span);
|
|
727
|
+
return `(Schema.Unknown as unknown as Schema.Codec<${ctx.emitTypeNode(typeNode)}>)`;
|
|
728
|
+
}
|
|
729
|
+
return ctx.emitTypeNode(typeNode);
|
|
730
|
+
}
|
|
731
|
+
function emitGenericSchemaArgument(ctx, type, verifyImports = false) {
|
|
732
|
+
if (type.kind === "ParenthesizedTypeNode")
|
|
733
|
+
return emitGenericSchemaArgument(ctx, type.typeNode, verifyImports);
|
|
734
|
+
if (type.kind === "LiteralTypeNode")
|
|
735
|
+
return `Schema.Literal(${JSON.stringify(type.value)})`;
|
|
736
|
+
if (type.kind === "RecordTypeNode" || type.kind === "UnionTypeNode") {
|
|
737
|
+
return emitSchemaTypeField(ctx, type);
|
|
738
|
+
}
|
|
739
|
+
if (type.kind === "TypeReferenceNode") {
|
|
740
|
+
const name = type.name.name;
|
|
741
|
+
if (ctx.activeSchemaParameters?.has(name) && !type.typeArgs?.length)
|
|
742
|
+
return name;
|
|
743
|
+
if (["String", "Number", "Boolean"].includes(name) &&
|
|
744
|
+
!type.typeArgs?.length &&
|
|
745
|
+
!ctx.declaredTypeNames.has(name))
|
|
746
|
+
return emitSchemaTypeField(ctx, type);
|
|
747
|
+
if (name === "Option" && type.typeArgs?.length === 1)
|
|
748
|
+
return `Schema.Option(${emitGenericSchemaArgument(ctx, type.typeArgs[0], verifyImports)})`;
|
|
749
|
+
if (name === "Array" && type.typeArgs?.length === 1)
|
|
750
|
+
return `Schema.Array(${emitGenericSchemaArgument(ctx, type.typeArgs[0], verifyImports)})`;
|
|
751
|
+
if (name === "Record" && type.typeArgs?.length === 2)
|
|
752
|
+
return `Schema.Record(${emitGenericSchemaArgument(ctx, type.typeArgs[0], verifyImports)}, ${emitGenericSchemaArgument(ctx, type.typeArgs[1], verifyImports)})`;
|
|
753
|
+
const arity = ctx.genericDataSchemas.get(name) ??
|
|
754
|
+
ctx.options.importedGenericDataSchemas?.get(name);
|
|
755
|
+
if (arity !== undefined && type.typeArgs?.length === arity)
|
|
756
|
+
return `${name}(${type.typeArgs.map((arg) => emitGenericSchemaArgument(ctx, arg, verifyImports || ctx.options.importedGenericDataSchemas?.has(name) === true)).join(", ")})`;
|
|
757
|
+
if (!type.typeArgs?.length &&
|
|
758
|
+
(ctx.runtimeSchemaNames.has(name) ||
|
|
759
|
+
ctx.recordContracts.has(name) ||
|
|
760
|
+
(ctx.userImportBindings.has(name) &&
|
|
761
|
+
(!verifyImports || ctx.options.importedDataSchemas?.has(name)))))
|
|
762
|
+
return emitSchemaTypeField(ctx, type);
|
|
763
|
+
}
|
|
764
|
+
throw new FunScriptError("Generic data schema arguments must name a runtime data schema or supported primitive; compile-time contracts and unknown types cannot validate data.", type.span);
|
|
765
|
+
}
|
|
766
|
+
//# sourceMappingURL=schemas.js.map
|