svelte-effect-runtime 4.0.1 → 4.1.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/.dist/chunks/{client-BrZka6DW.js → client-DbwVAMWm.js} +5 -5
- package/.dist/chunks/{client-BrZka6DW.js.map → client-DbwVAMWm.js.map} +1 -1
- package/.dist/chunks/{compiler-COVzgLYo.js → compiler-Dpyu4Owd.js} +2 -2
- package/.dist/chunks/{compiler-COVzgLYo.js.map → compiler-Dpyu4Owd.js.map} +1 -1
- package/.dist/chunks/{descriptors-B4otDlm1.js → descriptors-q909VWyR.js} +3 -3
- package/.dist/chunks/{descriptors-B4otDlm1.js.map → descriptors-q909VWyR.js.map} +1 -1
- package/.dist/chunks/{diagnostics-BDrky-Di.js → diagnostics-DLwwrBWb.js} +2 -2
- package/.dist/chunks/{diagnostics-BDrky-Di.js.map → diagnostics-DLwwrBWb.js.map} +1 -1
- package/.dist/chunks/{dispatcher-_x0MQZBS.js → dispatcher-CTWINW5I.js} +219 -16
- package/.dist/chunks/dispatcher-CTWINW5I.js.map +1 -0
- package/.dist/chunks/dispatcher-pZPzarul.js +23 -0
- package/.dist/chunks/dispatcher-pZPzarul.js.map +1 -0
- package/.dist/chunks/{errors-CLsbGjIa.js → errors-qhcbUH6o.js} +19 -2
- package/.dist/chunks/{errors-CLsbGjIa.js.map → errors-qhcbUH6o.js.map} +1 -1
- package/.dist/chunks/{live-BundLSoY.js → live-BW7xZKjb.js} +2 -2
- package/.dist/chunks/{live-BundLSoY.js.map → live-BW7xZKjb.js.map} +1 -1
- package/.dist/chunks/{runtime-HDTlEnzp.js → runtime-CPosEhGl.js} +3 -3
- package/.dist/chunks/{runtime-HDTlEnzp.js.map → runtime-CPosEhGl.js.map} +1 -1
- package/.dist/chunks/{server-BNrA1I-u.js → server-yQrNoiCR.js} +2 -2
- package/.dist/chunks/{server-BNrA1I-u.js.map → server-yQrNoiCR.js.map} +1 -1
- package/.dist/chunks/{source-scan-9pZxnfct.js → source-scan-cSawCvsg.js} +2 -2
- package/.dist/chunks/source-scan-cSawCvsg.js.map +1 -0
- package/.dist/chunks/{transform-BXyYUAez.js → transform-D7TTlPpK.js} +75 -27
- package/.dist/chunks/transform-D7TTlPpK.js.map +1 -0
- package/.dist/compiler.js +1 -1
- package/.dist/dispatcher/index.d.ts +49 -0
- package/.dist/dispatcher/scope.d.ts +36 -0
- package/.dist/dispatcher.d.ts +2 -1
- package/.dist/dispatcher.js +2 -2
- package/.dist/errors.d.ts +14 -0
- package/.dist/generated/dispatcher.d.ts +6 -1
- package/.dist/generators.d.ts +1 -0
- package/.dist/internal/generators.js +4 -4
- package/.dist/internal/remote-client.js +1 -1
- package/.dist/internal/remote-server.js +1 -1
- package/.dist/markup/promise.js +1 -1
- package/.dist/markup/run.js +1 -1
- package/.dist/markup/transform/apply.d.ts +4 -3
- package/.dist/markup/transform/constants.d.ts +1 -0
- package/.dist/markup/transform/types.d.ts +16 -0
- package/.dist/markup/transform.js +1 -1
- package/.dist/markup/value.js +1 -1
- package/.dist/mod.d.ts +1 -1
- package/.dist/mod.js +5 -5
- package/.dist/mod.js.map +1 -1
- package/.dist/remote/client.js +1 -1
- package/.dist/remote/server.js +1 -1
- package/.dist/runtime/transform.js +26 -12
- package/.dist/runtime/transform.js.map +1 -1
- package/.dist/script-transform/imports.d.ts +3 -1
- package/.dist/script-transform/index.d.ts +2 -0
- package/.dist/script-transform/types.d.ts +8 -0
- package/.dist/server.js +5 -5
- package/package.json +2 -2
- package/.dist/chunks/dispatcher-BA0PLQhA.js +0 -16
- package/.dist/chunks/dispatcher-BA0PLQhA.js.map +0 -1
- package/.dist/chunks/dispatcher-_x0MQZBS.js.map +0 -1
- package/.dist/chunks/source-scan-9pZxnfct.js.map +0 -1
- package/.dist/chunks/transform-BXyYUAez.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"descriptors-B4otDlm1.js","names":["carrier"],"sources":["../../../modules/svelte-effect-runtime/src/remote/failures.ts","../../../modules/svelte-effect-runtime/src/remote/effect.ts","../../../modules/svelte-effect-runtime/src/remote/resource.ts","../../../modules/svelte-effect-runtime/src/internal/schema.ts","../../../modules/svelte-effect-runtime/src/remote/query-update.ts","../../../modules/svelte-effect-runtime/src/internal/descriptors.ts"],"sourcesContent":["import {\n\tcreate_remote_http_error,\n\tcreate_remote_transport_error,\n\tis_serialized_remote_failure_envelope,\n} from \"$/remote/shared.ts\";\nimport type { RemoteFailure } from \"$/remote/shared.ts\";\nimport { RemoteErrorDecodeError } from \"$/errors.ts\";\nimport { Option, Result, Schema } from \"effect\";\nimport { parse } from \"devalue\";\n\ntype JsonStringDecode =\n\t| {\n\t\t\treadonly _tag: \"JsonStringDecoded\";\n\t\t\treadonly value: unknown;\n\t }\n\t| {\n\t\t\treadonly _tag: \"JsonStringIgnored\";\n\t };\n\ntype EmbeddedRemoteFailureDecode =\n\t| {\n\t\t\treadonly _tag: \"EmbeddedRemoteFailureDecoded\";\n\t\t\treadonly value: unknown;\n\t }\n\t| {\n\t\t\treadonly _tag: \"EmbeddedRemoteFailureIgnored\";\n\t };\n\ntype SerializedRemoteFailureDecode<ErrorType> =\n\t| {\n\t\t\treadonly _tag: \"SerializedRemoteFailureDecoded\";\n\t\t\treadonly value: RemoteFailure<ErrorType>;\n\t }\n\t| {\n\t\t\treadonly _tag: \"SerializedRemoteFailureInvalid\";\n\t };\n\nconst RemoteErrorMessageEnvelopeSchema = Schema.Struct({\n\tmessage: Schema.String,\n});\n\nconst DecodedRemoteFailureSchema = Schema.Struct({\n\t_tag: Schema.String,\n});\n\nconst DecodeJsonString = Schema.decodeUnknownOption(Schema.UnknownFromJsonString);\nconst is_decoded_remote_failure_value = Schema.is(DecodedRemoteFailureSchema);\nconst is_remote_error_message_envelope = Schema.is(RemoteErrorMessageEnvelopeSchema);\n\nexport function decode_remote_error<ErrorType = never>(\n\traw: unknown,\n\tdecode?: (encoded: string) => unknown,\n): RemoteFailure<ErrorType> | unknown {\n\tconst embedded = decode_embedded_remote_failure(raw);\n\n\tif (embedded._tag === \"EmbeddedRemoteFailureDecoded\") {\n\t\treturn decode_remote_error<ErrorType>(embedded.value, decode);\n\t}\n\n\tif (is_serialized_remote_failure_envelope(raw)) {\n\t\tconst decoded = decode_serialized_remote_failure<ErrorType>(raw.encoded, decode);\n\n\t\tif (decoded._tag === \"SerializedRemoteFailureInvalid\") {\n\t\t\treturn create_remote_transport_error(new RemoteErrorDecodeError(raw), raw);\n\t\t}\n\n\t\treturn decoded.value;\n\t}\n\n\treturn raw;\n}\n\nfunction decode_embedded_remote_failure(raw: unknown): EmbeddedRemoteFailureDecode {\n\tif (typeof raw === \"string\") {\n\t\treturn decode_embedded_json_remote_failure(raw);\n\t}\n\n\tif (!is_remote_error_message_envelope(raw)) {\n\t\treturn { _tag: \"EmbeddedRemoteFailureIgnored\" };\n\t}\n\n\treturn decode_embedded_json_remote_failure(raw.message);\n}\n\nfunction decode_embedded_json_remote_failure(value: string): EmbeddedRemoteFailureDecode {\n\tconst decoded = decode_json_string(value);\n\n\tif (decoded._tag === \"JsonStringIgnored\") {\n\t\treturn { _tag: \"EmbeddedRemoteFailureIgnored\" };\n\t}\n\n\treturn {\n\t\t_tag: \"EmbeddedRemoteFailureDecoded\",\n\t\tvalue: decoded.value,\n\t};\n}\n\nfunction decode_json_string(value: string): JsonStringDecode {\n\tconst decoded = DecodeJsonString(value);\n\n\tif (!Option.isSome(decoded)) {\n\t\treturn { _tag: \"JsonStringIgnored\" };\n\t}\n\n\treturn {\n\t\t_tag: \"JsonStringDecoded\",\n\t\tvalue: decoded.value,\n\t};\n}\n\nfunction decode_serialized_remote_failure<ErrorType>(\n\tencoded: string,\n\tdecode: ((encoded: string) => unknown) | undefined,\n): SerializedRemoteFailureDecode<ErrorType> {\n\tconst decoded = Result.try(() => (decode ? decode(encoded) : parse(encoded)));\n\n\tif (Result.isFailure(decoded)) {\n\t\treturn { _tag: \"SerializedRemoteFailureInvalid\" };\n\t}\n\n\treturn {\n\t\t_tag: \"SerializedRemoteFailureDecoded\",\n\t\tvalue: decoded.success as RemoteFailure<ErrorType>,\n\t};\n}\n\nexport function is_decoded_remote_failure(value: unknown): value is RemoteFailure<never> {\n\treturn is_decoded_remote_failure_value(value);\n}\n\nexport function normalize_native_error<ErrorType = never>(\n\terror: unknown,\n): RemoteFailure<ErrorType> {\n\tconst body = get_error_body(error);\n\tconst decoded = decode_remote_error<ErrorType>(body);\n\tconst status = get_error_status(error);\n\n\tif (is_decoded_remote_failure(decoded)) {\n\t\treturn decoded;\n\t}\n\n\tif (status !== undefined) {\n\t\treturn create_remote_http_error(status, body, error);\n\t}\n\n\treturn create_remote_transport_error(error);\n}\n\nfunction get_error_status(error: unknown): number | undefined {\n\tif (typeof error !== \"object\" || error === null) {\n\t\treturn undefined;\n\t}\n\n\tconst status = (error as { status?: unknown }).status;\n\n\treturn typeof status === \"number\" ? status : undefined;\n}\n\nfunction get_error_body(error: unknown): unknown {\n\tif (typeof error !== \"object\" || error === null) {\n\t\treturn undefined;\n\t}\n\n\tif (\"body\" in error) {\n\t\treturn (error as { body?: unknown }).body;\n\t}\n\n\tif (\"data\" in error) {\n\t\treturn (error as { data?: unknown }).data;\n\t}\n\n\treturn undefined;\n}\n","import { is_decoded_remote_failure, normalize_native_error } from \"./failures.ts\";\nimport type { RemoteFailure } from \"$/remote/shared.ts\";\nimport { isRedirect } from \"@sveltejs/kit\";\nimport { Effect } from \"effect\";\n\nexport const MakeEffectFromPromise = <Output, ErrorType = never>(\n\trun: (signal: AbortSignal) => PromiseLike<Output>,\n) =>\n\tEffect.tryPromise({\n\t\ttry: run,\n\t\tcatch: normalize_remote_effect_error<ErrorType>,\n\t});\n\nexport const MakeEffectFromSync = <Output, ErrorType = never>(run: () => Output) =>\n\tEffect.try({\n\t\ttry: run,\n\t\tcatch: normalize_remote_effect_error<ErrorType>,\n\t});\n\nexport const FailWithRemoteError = <ErrorType = never>(error: unknown) =>\n\tEffect.gen(function* () {\n\t\tif (isRedirect(error)) {\n\t\t\treturn yield* Effect.die(error);\n\t\t}\n\n\t\treturn yield* Effect.fail(normalize_remote_effect_error<ErrorType>(error));\n\t});\n\nexport function normalize_remote_effect_error<ErrorType>(error: unknown): RemoteFailure<ErrorType> {\n\tif (isRedirect(error)) {\n\t\tthrow error;\n\t}\n\n\tif (is_decoded_remote_failure(error)) {\n\t\treturn error;\n\t}\n\n\treturn normalize_native_error<ErrorType>(error);\n}\n","import { FailWithRemoteError, normalize_remote_effect_error } from \"./effect.ts\";\nimport type { RemoteFailure } from \"$/remote/shared.ts\";\nimport { Result, type Effect } from \"effect\";\n\nexport type RemoteResourceEffect<Output, ErrorType = never> = Effect.Effect<\n\tOutput,\n\tRemoteFailure<ErrorType>\n> & {\n\treadonly current: Output | undefined;\n\treadonly error: unknown;\n\treadonly loading: boolean;\n\treadonly ready: boolean;\n};\n\ntype RemoteQueryResourceEffect<Output, ErrorType = never> = RemoteResourceEffect<\n\tOutput,\n\tErrorType\n> & {\n\treadonly refresh: () => Effect.Effect<void, unknown, never>;\n\treadonly set: (value: Output) => void;\n\treadonly withOverride: (update: (current: Output) => Output) => unknown;\n};\n\nexport type NativeRemoteResource<Output> = {\n\treadonly current?: Output;\n\treadonly error?: unknown;\n\treadonly loading?: boolean;\n\treadonly ready?: boolean;\n};\n\nexport function is_remote_resource<Output>(\n\tresource: unknown,\n): resource is NativeRemoteResource<Output> {\n\tconst resource_type = typeof resource;\n\n\treturn (resource_type === \"object\" && resource !== null) || resource_type === \"function\";\n}\n\nexport function attach_remote_resource_getters<Output, ErrorType = never>(\n\tresource: unknown,\n\teffect: RemoteResourceEffect<Output, ErrorType>,\n): void {\n\tconst methods = is_remote_resource<Output>(resource) ? resource : undefined;\n\tconst keys = [\"current\", \"error\", \"loading\", \"ready\"] as const;\n\n\tif (!methods) {\n\t\treturn;\n\t}\n\n\tfor (const key of keys) {\n\t\tif (!(key in methods)) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tObject.defineProperty(effect, key, {\n\t\t\tconfigurable: true,\n\t\t\tget: () => methods[key],\n\t\t});\n\t}\n}\n\nexport function attach_failed_remote_resource_getters<Output, ErrorType = never>(\n\terror: unknown,\n\teffect: RemoteResourceEffect<Output, ErrorType>,\n): void {\n\tconst normalized_error = normalize_remote_resource_error<ErrorType>(error);\n\n\tObject.defineProperties(effect, {\n\t\tcurrent: {\n\t\t\tconfigurable: true,\n\t\t\tget: () => undefined,\n\t\t},\n\t\terror: {\n\t\t\tconfigurable: true,\n\t\t\tget: () => normalized_error,\n\t\t},\n\t\tloading: {\n\t\t\tconfigurable: true,\n\t\t\tget: () => false,\n\t\t},\n\t\tready: {\n\t\t\tconfigurable: true,\n\t\t\tget: () => false,\n\t\t},\n\t});\n}\n\nexport function attach_failed_remote_query_resource<Output, ErrorType = never>(\n\terror: unknown,\n\teffect: RemoteQueryResourceEffect<Output, ErrorType>,\n): void {\n\tconst normalized_error = normalize_remote_resource_error<ErrorType>(error);\n\tconst RefreshFailedResource = () => FailWithRemoteError<ErrorType>(error);\n\tconst throw_resource_error = (): never => {\n\t\tthrow normalized_error;\n\t};\n\n\tattach_failed_remote_resource_getters(normalized_error, effect);\n\n\tObject.defineProperties(effect, {\n\t\trefresh: {\n\t\t\tconfigurable: true,\n\t\t\tvalue: RefreshFailedResource,\n\t\t},\n\t\tset: {\n\t\t\tconfigurable: true,\n\t\t\tvalue: throw_resource_error,\n\t\t},\n\t\twithOverride: {\n\t\t\tconfigurable: true,\n\t\t\tvalue: throw_resource_error,\n\t\t},\n\t});\n}\n\nexport function normalize_remote_resource_error<ErrorType>(error: unknown): unknown {\n\tconst normalized = Result.try(() => normalize_remote_effect_error<ErrorType>(error));\n\n\treturn Result.isSuccess(normalized) ? normalized.success : error;\n}\n","import { Schema } from \"effect\";\n\nexport type StandardSchema = {\n\treadonly \"~standard\": {\n\t\treadonly types?: {\n\t\t\treadonly input: unknown;\n\t\t\treadonly output: unknown;\n\t\t};\n\t\treadonly validate: (input: unknown) => unknown;\n\t};\n};\n\nexport function is_standard_schema(value: unknown): value is StandardSchema {\n\treturn typeof value === \"object\" && value !== null && \"~standard\" in value;\n}\n\nexport function is_effect_schema(value: unknown): value is Schema.Schema<unknown> {\n\treturn Schema.isSchema(value);\n}\n\nexport function normalize_validator(value: unknown): unknown {\n\tif (is_standard_schema(value) || !is_effect_schema(value)) {\n\t\treturn value;\n\t}\n\n\treturn Schema.toStandardSchemaV1(value as never);\n}\n","import { get_native_remote_live_resource } from \"$/live.ts\";\n\nconst native_remote_query_update: unique symbol = Symbol.for(\n\t\"svelte-effect-runtime/native-remote-query-update\",\n) as never;\n\ntype NativeRemoteQueryUpdateCarrier = {\n\treadonly [native_remote_query_update]?: unknown;\n};\n\nexport function attach_native_remote_query_update(target: unknown, native_update: unknown): void {\n\tif (!is_reference(target)) {\n\t\treturn;\n\t}\n\n\tObject.defineProperty(target, native_remote_query_update, {\n\t\tconfigurable: true,\n\t\tvalue: native_update,\n\t});\n}\n\nexport function resolve_native_remote_query_updates(updates: readonly unknown[]): unknown[] {\n\treturn updates.map(resolve_native_remote_query_update);\n}\n\nfunction resolve_native_remote_query_update(update: unknown): unknown {\n\tif (!is_reference(update)) {\n\t\treturn update;\n\t}\n\n\tconst carrier = update as NativeRemoteQueryUpdateCarrier;\n\tconst attached_update = carrier[native_remote_query_update];\n\tconst live_resource = get_native_remote_live_resource(update);\n\n\treturn attached_update ?? live_resource ?? update;\n}\n\nfunction is_reference(value: unknown): value is object | ((...args: never[]) => unknown) {\n\treturn (typeof value === \"object\" && value !== null) || typeof value === \"function\";\n}\n","const default_excluded_descriptor_keys = new Set<PropertyKey>([\"length\", \"name\", \"prototype\"]);\n\nexport function copy_property_descriptors(\n\tsource: unknown,\n\ttarget: object,\n\texclude: ReadonlySet<PropertyKey> = default_excluded_descriptor_keys,\n): void {\n\tif (typeof source !== \"object\" && typeof source !== \"function\") {\n\t\treturn;\n\t}\n\n\tif (source === null) {\n\t\treturn;\n\t}\n\n\tfor (const key of Reflect.ownKeys(source)) {\n\t\tif (default_excluded_descriptor_keys.has(key) || exclude.has(key)) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst descriptor = Object.getOwnPropertyDescriptor(source, key);\n\n\t\tif (!descriptor) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tObject.defineProperty(target, key, descriptor);\n\t}\n}\n"],"mappings":";;;;;;;AAqCA,MAAM,mCAAmC,OAAO,OAAO,EACtD,SAAS,OAAO,OACjB,CAAC;AAED,MAAM,6BAA6B,OAAO,OAAO,EAChD,MAAM,OAAO,OACd,CAAC;AAED,MAAM,mBAAmB,OAAO,oBAAoB,OAAO,qBAAqB;AAChF,MAAM,kCAAkC,OAAO,GAAG,0BAA0B;AAC5E,MAAM,mCAAmC,OAAO,GAAG,gCAAgC;AAEnF,SAAgB,oBACf,KACA,QACqC;CACrC,MAAM,WAAW,+BAA+B,GAAG;CAEnD,IAAI,SAAS,SAAS,gCACrB,OAAO,oBAA+B,SAAS,OAAO,MAAM;CAG7D,IAAI,sCAAsC,GAAG,GAAG;EAC/C,MAAM,UAAU,iCAA4C,IAAI,SAAS,MAAM;EAE/E,IAAI,QAAQ,SAAS,kCACpB,OAAO,8BAA8B,IAAI,uBAAuB,GAAG,GAAG,GAAG;EAG1E,OAAO,QAAQ;CAChB;CAEA,OAAO;AACR;AAEA,SAAS,+BAA+B,KAA2C;CAClF,IAAI,OAAO,QAAQ,UAClB,OAAO,oCAAoC,GAAG;CAG/C,IAAI,CAAC,iCAAiC,GAAG,GACxC,OAAO,EAAE,MAAM,+BAA+B;CAG/C,OAAO,oCAAoC,IAAI,OAAO;AACvD;AAEA,SAAS,oCAAoC,OAA4C;CACxF,MAAM,UAAU,mBAAmB,KAAK;CAExC,IAAI,QAAQ,SAAS,qBACpB,OAAO,EAAE,MAAM,+BAA+B;CAG/C,OAAO;EACN,MAAM;EACN,OAAO,QAAQ;CAChB;AACD;AAEA,SAAS,mBAAmB,OAAiC;CAC5D,MAAM,UAAU,iBAAiB,K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B,QAAQ,GAAG;EAE9D,IAAI,CAAC,YACJ;EAGD,OAAO,eAAe,QAAQ,KAAK,UAAU;CAC9C;AACD"}
|
|
1
|
+
{"version":3,"file":"descriptors-q909VWyR.js","names":["carrier"],"sources":["../../../modules/svelte-effect-runtime/src/remote/failures.ts","../../../modules/svelte-effect-runtime/src/remote/effect.ts","../../../modules/svelte-effect-runtime/src/remote/resource.ts","../../../modules/svelte-effect-runtime/src/internal/schema.ts","../../../modules/svelte-effect-runtime/src/remote/query-update.ts","../../../modules/svelte-effect-runtime/src/internal/descriptors.ts"],"sourcesContent":["import {\n\tcreate_remote_http_error,\n\tcreate_remote_transport_error,\n\tis_serialized_remote_failure_envelope,\n} from \"$/remote/shared.ts\";\nimport type { RemoteFailure } from \"$/remote/shared.ts\";\nimport { RemoteErrorDecodeError } from \"$/errors.ts\";\nimport { Option, Result, Schema } from \"effect\";\nimport { parse } from \"devalue\";\n\ntype JsonStringDecode =\n\t| {\n\t\t\treadonly _tag: \"JsonStringDecoded\";\n\t\t\treadonly value: unknown;\n\t }\n\t| {\n\t\t\treadonly _tag: \"JsonStringIgnored\";\n\t };\n\ntype EmbeddedRemoteFailureDecode =\n\t| {\n\t\t\treadonly _tag: \"EmbeddedRemoteFailureDecoded\";\n\t\t\treadonly value: unknown;\n\t }\n\t| {\n\t\t\treadonly _tag: \"EmbeddedRemoteFailureIgnored\";\n\t };\n\ntype SerializedRemoteFailureDecode<ErrorType> =\n\t| {\n\t\t\treadonly _tag: \"SerializedRemoteFailureDecoded\";\n\t\t\treadonly value: RemoteFailure<ErrorType>;\n\t }\n\t| {\n\t\t\treadonly _tag: \"SerializedRemoteFailureInvalid\";\n\t };\n\nconst RemoteErrorMessageEnvelopeSchema = Schema.Struct({\n\tmessage: Schema.String,\n});\n\nconst DecodedRemoteFailureSchema = Schema.Struct({\n\t_tag: Schema.String,\n});\n\nconst DecodeJsonString = Schema.decodeUnknownOption(Schema.UnknownFromJsonString);\nconst is_decoded_remote_failure_value = Schema.is(DecodedRemoteFailureSchema);\nconst is_remote_error_message_envelope = Schema.is(RemoteErrorMessageEnvelopeSchema);\n\nexport function decode_remote_error<ErrorType = never>(\n\traw: unknown,\n\tdecode?: (encoded: string) => unknown,\n): RemoteFailure<ErrorType> | unknown {\n\tconst embedded = decode_embedded_remote_failure(raw);\n\n\tif (embedded._tag === \"EmbeddedRemoteFailureDecoded\") {\n\t\treturn decode_remote_error<ErrorType>(embedded.value, decode);\n\t}\n\n\tif (is_serialized_remote_failure_envelope(raw)) {\n\t\tconst decoded = decode_serialized_remote_failure<ErrorType>(raw.encoded, decode);\n\n\t\tif (decoded._tag === \"SerializedRemoteFailureInvalid\") {\n\t\t\treturn create_remote_transport_error(new RemoteErrorDecodeError(raw), raw);\n\t\t}\n\n\t\treturn decoded.value;\n\t}\n\n\treturn raw;\n}\n\nfunction decode_embedded_remote_failure(raw: unknown): EmbeddedRemoteFailureDecode {\n\tif (typeof raw === \"string\") {\n\t\treturn decode_embedded_json_remote_failure(raw);\n\t}\n\n\tif (!is_remote_error_message_envelope(raw)) {\n\t\treturn { _tag: \"EmbeddedRemoteFailureIgnored\" };\n\t}\n\n\treturn decode_embedded_json_remote_failure(raw.message);\n}\n\nfunction decode_embedded_json_remote_failure(value: string): EmbeddedRemoteFailureDecode {\n\tconst decoded = decode_json_string(value);\n\n\tif (decoded._tag === \"JsonStringIgnored\") {\n\t\treturn { _tag: \"EmbeddedRemoteFailureIgnored\" };\n\t}\n\n\treturn {\n\t\t_tag: \"EmbeddedRemoteFailureDecoded\",\n\t\tvalue: decoded.value,\n\t};\n}\n\nfunction decode_json_string(value: string): JsonStringDecode {\n\tconst decoded = DecodeJsonString(value);\n\n\tif (!Option.isSome(decoded)) {\n\t\treturn { _tag: \"JsonStringIgnored\" };\n\t}\n\n\treturn {\n\t\t_tag: \"JsonStringDecoded\",\n\t\tvalue: decoded.value,\n\t};\n}\n\nfunction decode_serialized_remote_failure<ErrorType>(\n\tencoded: string,\n\tdecode: ((encoded: string) => unknown) | undefined,\n): SerializedRemoteFailureDecode<ErrorType> {\n\tconst decoded = Result.try(() => (decode ? decode(encoded) : parse(encoded)));\n\n\tif (Result.isFailure(decoded)) {\n\t\treturn { _tag: \"SerializedRemoteFailureInvalid\" };\n\t}\n\n\treturn {\n\t\t_tag: \"SerializedRemoteFailureDecoded\",\n\t\tvalue: decoded.success as RemoteFailure<ErrorType>,\n\t};\n}\n\nexport function is_decoded_remote_failure(value: unknown): value is RemoteFailure<never> {\n\treturn is_decoded_remote_failure_value(value);\n}\n\nexport function normalize_native_error<ErrorType = never>(\n\terror: unknown,\n): RemoteFailure<ErrorType> {\n\tconst body = get_error_body(error);\n\tconst decoded = decode_remote_error<ErrorType>(body);\n\tconst status = get_error_status(error);\n\n\tif (is_decoded_remote_failure(decoded)) {\n\t\treturn decoded;\n\t}\n\n\tif (status !== undefined) {\n\t\treturn create_remote_http_error(status, body, error);\n\t}\n\n\treturn create_remote_transport_error(error);\n}\n\nfunction get_error_status(error: unknown): number | undefined {\n\tif (typeof error !== \"object\" || error === null) {\n\t\treturn undefined;\n\t}\n\n\tconst status = (error as { status?: unknown }).status;\n\n\treturn typeof status === \"number\" ? status : undefined;\n}\n\nfunction get_error_body(error: unknown): unknown {\n\tif (typeof error !== \"object\" || error === null) {\n\t\treturn undefined;\n\t}\n\n\tif (\"body\" in error) {\n\t\treturn (error as { body?: unknown }).body;\n\t}\n\n\tif (\"data\" in error) {\n\t\treturn (error as { data?: unknown }).data;\n\t}\n\n\treturn undefined;\n}\n","import { is_decoded_remote_failure, normalize_native_error } from \"./failures.ts\";\nimport type { RemoteFailure } from \"$/remote/shared.ts\";\nimport { isRedirect } from \"@sveltejs/kit\";\nimport { Effect } from \"effect\";\n\nexport const MakeEffectFromPromise = <Output, ErrorType = never>(\n\trun: (signal: AbortSignal) => PromiseLike<Output>,\n) =>\n\tEffect.tryPromise({\n\t\ttry: run,\n\t\tcatch: normalize_remote_effect_error<ErrorType>,\n\t});\n\nexport const MakeEffectFromSync = <Output, ErrorType = never>(run: () => Output) =>\n\tEffect.try({\n\t\ttry: run,\n\t\tcatch: normalize_remote_effect_error<ErrorType>,\n\t});\n\nexport const FailWithRemoteError = <ErrorType = never>(error: unknown) =>\n\tEffect.gen(function* () {\n\t\tif (isRedirect(error)) {\n\t\t\treturn yield* Effect.die(error);\n\t\t}\n\n\t\treturn yield* Effect.fail(normalize_remote_effect_error<ErrorType>(error));\n\t});\n\nexport function normalize_remote_effect_error<ErrorType>(error: unknown): RemoteFailure<ErrorType> {\n\tif (isRedirect(error)) {\n\t\tthrow error;\n\t}\n\n\tif (is_decoded_remote_failure(error)) {\n\t\treturn error;\n\t}\n\n\treturn normalize_native_error<ErrorType>(error);\n}\n","import { FailWithRemoteError, normalize_remote_effect_error } from \"./effect.ts\";\nimport type { RemoteFailure } from \"$/remote/shared.ts\";\nimport { Result, type Effect } from \"effect\";\n\nexport type RemoteResourceEffect<Output, ErrorType = never> = Effect.Effect<\n\tOutput,\n\tRemoteFailure<ErrorType>\n> & {\n\treadonly current: Output | undefined;\n\treadonly error: unknown;\n\treadonly loading: boolean;\n\treadonly ready: boolean;\n};\n\ntype RemoteQueryResourceEffect<Output, ErrorType = never> = RemoteResourceEffect<\n\tOutput,\n\tErrorType\n> & {\n\treadonly refresh: () => Effect.Effect<void, unknown, never>;\n\treadonly set: (value: Output) => void;\n\treadonly withOverride: (update: (current: Output) => Output) => unknown;\n};\n\nexport type NativeRemoteResource<Output> = {\n\treadonly current?: Output;\n\treadonly error?: unknown;\n\treadonly loading?: boolean;\n\treadonly ready?: boolean;\n};\n\nexport function is_remote_resource<Output>(\n\tresource: unknown,\n): resource is NativeRemoteResource<Output> {\n\tconst resource_type = typeof resource;\n\n\treturn (resource_type === \"object\" && resource !== null) || resource_type === \"function\";\n}\n\nexport function attach_remote_resource_getters<Output, ErrorType = never>(\n\tresource: unknown,\n\teffect: RemoteResourceEffect<Output, ErrorType>,\n): void {\n\tconst methods = is_remote_resource<Output>(resource) ? resource : undefined;\n\tconst keys = [\"current\", \"error\", \"loading\", \"ready\"] as const;\n\n\tif (!methods) {\n\t\treturn;\n\t}\n\n\tfor (const key of keys) {\n\t\tif (!(key in methods)) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tObject.defineProperty(effect, key, {\n\t\t\tconfigurable: true,\n\t\t\tget: () => methods[key],\n\t\t});\n\t}\n}\n\nexport function attach_failed_remote_resource_getters<Output, ErrorType = never>(\n\terror: unknown,\n\teffect: RemoteResourceEffect<Output, ErrorType>,\n): void {\n\tconst normalized_error = normalize_remote_resource_error<ErrorType>(error);\n\n\tObject.defineProperties(effect, {\n\t\tcurrent: {\n\t\t\tconfigurable: true,\n\t\t\tget: () => undefined,\n\t\t},\n\t\terror: {\n\t\t\tconfigurable: true,\n\t\t\tget: () => normalized_error,\n\t\t},\n\t\tloading: {\n\t\t\tconfigurable: true,\n\t\t\tget: () => false,\n\t\t},\n\t\tready: {\n\t\t\tconfigurable: true,\n\t\t\tget: () => false,\n\t\t},\n\t});\n}\n\nexport function attach_failed_remote_query_resource<Output, ErrorType = never>(\n\terror: unknown,\n\teffect: RemoteQueryResourceEffect<Output, ErrorType>,\n): void {\n\tconst normalized_error = normalize_remote_resource_error<ErrorType>(error);\n\tconst RefreshFailedResource = () => FailWithRemoteError<ErrorType>(error);\n\tconst throw_resource_error = (): never => {\n\t\tthrow normalized_error;\n\t};\n\n\tattach_failed_remote_resource_getters(normalized_error, effect);\n\n\tObject.defineProperties(effect, {\n\t\trefresh: {\n\t\t\tconfigurable: true,\n\t\t\tvalue: RefreshFailedResource,\n\t\t},\n\t\tset: {\n\t\t\tconfigurable: true,\n\t\t\tvalue: throw_resource_error,\n\t\t},\n\t\twithOverride: {\n\t\t\tconfigurable: true,\n\t\t\tvalue: throw_resource_error,\n\t\t},\n\t});\n}\n\nexport function normalize_remote_resource_error<ErrorType>(error: unknown): unknown {\n\tconst normalized = Result.try(() => normalize_remote_effect_error<ErrorType>(error));\n\n\treturn Result.isSuccess(normalized) ? normalized.success : error;\n}\n","import { Schema } from \"effect\";\n\nexport type StandardSchema = {\n\treadonly \"~standard\": {\n\t\treadonly types?: {\n\t\t\treadonly input: unknown;\n\t\t\treadonly output: unknown;\n\t\t};\n\t\treadonly validate: (input: unknown) => unknown;\n\t};\n};\n\nexport function is_standard_schema(value: unknown): value is StandardSchema {\n\treturn typeof value === \"object\" && value !== null && \"~standard\" in value;\n}\n\nexport function is_effect_schema(value: unknown): value is Schema.Schema<unknown> {\n\treturn Schema.isSchema(value);\n}\n\nexport function normalize_validator(value: unknown): unknown {\n\tif (is_standard_schema(value) || !is_effect_schema(value)) {\n\t\treturn value;\n\t}\n\n\treturn Schema.toStandardSchemaV1(value as never);\n}\n","import { get_native_remote_live_resource } from \"$/live.ts\";\n\nconst native_remote_query_update: unique symbol = Symbol.for(\n\t\"svelte-effect-runtime/native-remote-query-update\",\n) as never;\n\ntype NativeRemoteQueryUpdateCarrier = {\n\treadonly [native_remote_query_update]?: unknown;\n};\n\nexport function attach_native_remote_query_update(target: unknown, native_update: unknown): void {\n\tif (!is_reference(target)) {\n\t\treturn;\n\t}\n\n\tObject.defineProperty(target, native_remote_query_update, {\n\t\tconfigurable: true,\n\t\tvalue: native_update,\n\t});\n}\n\nexport function resolve_native_remote_query_updates(updates: readonly unknown[]): unknown[] {\n\treturn updates.map(resolve_native_remote_query_update);\n}\n\nfunction resolve_native_remote_query_update(update: unknown): unknown {\n\tif (!is_reference(update)) {\n\t\treturn update;\n\t}\n\n\tconst carrier = update as NativeRemoteQueryUpdateCarrier;\n\tconst attached_update = carrier[native_remote_query_update];\n\tconst live_resource = get_native_remote_live_resource(update);\n\n\treturn attached_update ?? live_resource ?? update;\n}\n\nfunction is_reference(value: unknown): value is object | ((...args: never[]) => unknown) {\n\treturn (typeof value === \"object\" && value !== null) || typeof value === \"function\";\n}\n","const default_excluded_descriptor_keys = new Set<PropertyKey>([\"length\", \"name\", \"prototype\"]);\n\nexport function copy_property_descriptors(\n\tsource: unknown,\n\ttarget: object,\n\texclude: ReadonlySet<PropertyKey> = default_excluded_descriptor_keys,\n): void {\n\tif (typeof source !== \"object\" && typeof source !== \"function\") {\n\t\treturn;\n\t}\n\n\tif (source === null) {\n\t\treturn;\n\t}\n\n\tfor (const key of Reflect.ownKeys(source)) {\n\t\tif (default_excluded_descriptor_keys.has(key) || exclude.has(key)) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst descriptor = Object.getOwnPropertyDescriptor(source, key);\n\n\t\tif (!descriptor) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tObject.defineProperty(target, key, descriptor);\n\t}\n}\n"],"mappings":";;;;;;;AAqCA,MAAM,mCAAmC,OAAO,OAAO,EACtD,SAAS,OAAO,OACjB,CAAC;AAED,MAAM,6BAA6B,OAAO,OAAO,EAChD,MAAM,OAAO,OACd,CAAC;AAED,MAAM,mBAAmB,OAAO,oBAAoB,OAAO,qBAAqB;AAChF,MAAM,kCAAkC,OAAO,GAAG,0BAA0B;AAC5E,MAAM,mCAAmC,OAAO,GAAG,gCAAgC;AAEnF,SAAgB,oBACf,KACA,QACqC;CACrC,MAAM,WAAW,+BAA+B,GAAG;CAEnD,IAAI,SAAS,SAAS,gCACrB,OAAO,oBAA+B,SAAS,OAAO,MAAM;CAG7D,IAAI,sCAAsC,GAAG,GAAG;EAC/C,MAAM,UAAU,iCAA4C,IAAI,SAAS,MAAM;EAE/E,IAAI,QAAQ,SAAS,kCACpB,OAAO,8BAA8B,IAAI,uBAAuB,GAAG,GAAG,GAAG;EAG1E,OAAO,QAAQ;CAChB;CAEA,OAAO;AACR;AAEA,SAAS,+BAA+B,KAA2C;CAClF,IAAI,OAAO,QAAQ,UAClB,OAAO,oCAAoC,GAAG;CAG/C,IAAI,CAAC,iCAAiC,GAAG,GACxC,OAAO,EAAE,MAAM,+BAA+B;CAG/C,OAAO,oCAAoC,IAAI,OAAO;AACvD;AAEA,SAAS,oCAAoC,OAA4C;CACxF,MAAM,UAAU,mBAAmB,KAAK;CAExC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IAAI,WAAW,MACd;CAGD,KAAK,MAAM,OAAO,QAAQ,QAAQ,MAAM,GAAG;EAC1C,IAAI,iCAAiC,IAAI,GAAG,KAAK,QAAQ,IAAI,GAAG,GAC/D;EAGD,MAAM,aAAa,OAAO,yBAAyB,QAAQ,GAAG;EAE9D,IAAI,CAAC,YACJ;EAGD,OAAO,eAAe,QAAQ,KAAK,UAAU;CAC9C;AACD"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as scan_svelte_effect_source } from "./source-scan-
|
|
1
|
+
import { t as scan_svelte_effect_source } from "./source-scan-cSawCvsg.js";
|
|
2
2
|
import ts from "typescript";
|
|
3
3
|
//#region src/diagnostics.ts
|
|
4
4
|
const effect_member_names = [
|
|
@@ -356,4 +356,4 @@ function make_line_starts(code) {
|
|
|
356
356
|
//#endregion
|
|
357
357
|
export { find_svelte_effect_diagnostics };
|
|
358
358
|
|
|
359
|
-
//# sourceMappingURL=diagnostics-
|
|
359
|
+
//# sourceMappingURL=diagnostics-DLwwrBWb.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diagnostics-BDrky-Di.js","names":[],"sources":["../../../modules/svelte-effect-runtime/src/diagnostics.ts"],"sourcesContent":["import type { MarkupBraceExpression, ScriptRegion } from \"$/compiler/source-scan.ts\";\nimport { scan_svelte_effect_source } from \"$/compiler/source-scan.ts\";\n\nimport ts from \"typescript\";\n\n/**\n * Warning diagnostic produced by the SER Vite diagnostics plugin.\n */\ninterface Diagnostic {\n\tmessage: string;\n\tline: number;\n\tcolumn: number;\n}\n\ninterface SourceLocation {\n\tline: number;\n\tcolumn: number;\n}\n\ninterface ParsedMarkupExpression {\n\tsource_file: ts.SourceFile;\n\troot_expression: ts.Expression | undefined;\n\tis_direct_expression: boolean;\n}\n\ninterface EffectBindings {\n\tpaths: ReadonlySet<string>;\n\troot_names: readonly string[];\n}\n\ninterface NormalizedMarkupExpression {\n\tkind: \"declaration\" | \"expression\";\n\ttext: string;\n\tis_direct_expression: boolean;\n}\n\nconst effect_member_names = [\n\t\"all\",\n\t\"fail\",\n\t\"gen\",\n\t\"log\",\n\t\"promise\",\n\t\"runFork\",\n\t\"runPromise\",\n\t\"runSync\",\n\t\"succeed\",\n\t\"sync\",\n\t\"try\",\n\t\"tryPromise\",\n\t\"void\",\n] as const;\nconst effect_member_name_set = new Set<string>(effect_member_names);\nconst effect_runner_names = new Set([\"runFork\", \"runPromise\", \"runSync\"]);\nconst effect_gen_name = new Set([\"gen\"]);\n\nexport function find_svelte_effect_diagnostics(\n\tcode: string,\n\tfilename: string,\n): Array<{ message: string; line: number; column: number }> {\n\tconst scan = scan_svelte_effect_source(code, filename);\n\tconst effect_binding_paths = find_effect_binding_paths(scan.scripts);\n\tconst line_starts = make_line_starts(code);\n\n\treturn scan.markup_expressions.flatMap((expression) =>\n\t\tmake_expression_diagnostics(filename, effect_binding_paths, expression, line_starts),\n\t);\n}\n\nfunction find_effect_binding_paths(scripts: readonly ScriptRegion[]): EffectBindings {\n\tconst seen_paths = new Set([\"Effect\"]);\n\tconst root_names = new Set([\"Effect\"]);\n\n\tfor (const script of scripts) {\n\t\tconst source_file = ts.createSourceFile(\n\t\t\t\"diagnostics-script.ts\",\n\t\t\tscript.text,\n\t\t\tts.ScriptTarget.Latest,\n\t\t\ttrue,\n\t\t\tts.ScriptKind.TS,\n\t\t);\n\n\t\tfor (const statement of source_file.statements) {\n\t\t\tfor (const binding_path of get_effect_import_binding_paths(statement)) {\n\t\t\t\tconst key = binding_path.join(\".\");\n\n\t\t\t\tif (seen_paths.has(key)) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tseen_paths.add(key);\n\t\t\t\troot_names.add(binding_path[0]);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn { paths: seen_paths, root_names: [...root_names] };\n}\n\nfunction get_effect_import_binding_paths(statement: ts.Statement): string[][] {\n\tif (\n\t\t!ts.isImportDeclaration(statement) ||\n\t\t!ts.isStringLiteral(statement.moduleSpecifier) ||\n\t\t!statement.importClause ||\n\t\tstatement.importClause.isTypeOnly\n\t) {\n\t\treturn [];\n\t}\n\n\tconst module_name = statement.moduleSpecifier.text;\n\tconst named_bindings = statement.importClause.namedBindings;\n\n\tif (!named_bindings) {\n\t\treturn [];\n\t}\n\n\tif (module_name === \"effect\" && ts.isNamedImports(named_bindings)) {\n\t\treturn named_bindings.elements.flatMap((specifier) => {\n\t\t\tconst imported_name = specifier.propertyName?.text ?? specifier.name.text;\n\n\t\t\treturn !specifier.isTypeOnly && imported_name === \"Effect\"\n\t\t\t\t? [[specifier.name.text]]\n\t\t\t\t: [];\n\t\t});\n\t}\n\n\tif (module_name === \"effect\" && ts.isNamespaceImport(named_bindings)) {\n\t\treturn [[named_bindings.name.text, \"Effect\"]];\n\t}\n\n\tif (module_name === \"effect/Effect\" && ts.isNamespaceImport(named_bindings)) {\n\t\treturn [[named_bindings.name.text]];\n\t}\n\n\treturn [];\n}\n\nfunction make_expression_diagnostics(\n\tfilename: string,\n\teffect_binding_paths: EffectBindings,\n\texpression: MarkupBraceExpression,\n\tline_starts: number[],\n): Diagnostic[] {\n\tconst attribute_name = expression.attribute_name;\n\tconst expression_text = expression.expression_text;\n\tconst is_event_attribute = attribute_name !== undefined && attribute_name.startsWith(\"on\");\n\tconst is_attribute = attribute_name !== undefined;\n\tconst parsed_expression = parse_markup_expression(expression_text, effect_binding_paths);\n\n\tif (!parsed_expression) {\n\t\treturn [];\n\t}\n\n\tconst is_callback = is_callback_expression(parsed_expression);\n\tconst has_yield_star = is_callback\n\t\t? contains_callback_yield_star(parsed_expression)\n\t\t: contains_yield_star(parsed_expression);\n\tconst is_hidden_event_yield = is_event_attribute && is_callback && has_yield_star;\n\tconst has_effect_reference = contains_effect_reference(parsed_expression, effect_binding_paths);\n\n\tif (!has_effect_reference && !is_hidden_event_yield) {\n\t\treturn [];\n\t}\n\n\tif (\n\t\t!contains_unyielded_effect_reference(parsed_expression, effect_binding_paths) &&\n\t\t!is_hidden_event_yield\n\t) {\n\t\treturn [];\n\t}\n\n\tconst loc = get_line_column(line_starts, expression.open);\n\n\tif (is_hidden_event_yield) {\n\t\treturn [\n\t\t\tmake_diagnostic(\n\t\t\t\tloc,\n\t\t\t\tmake_hidden_event_yield_warning(filename, attribute_name, expression_text),\n\t\t\t),\n\t\t];\n\t}\n\n\tif (contains_effect_runner(parsed_expression, effect_binding_paths)) {\n\t\treturn [\n\t\t\tmake_diagnostic(\n\t\t\t\tloc,\n\t\t\t\tmake_explicit_runner_warning(filename, attribute_name, expression_text),\n\t\t\t),\n\t\t];\n\t}\n\n\tif (is_bare_effect_gen(parsed_expression, effect_binding_paths)) {\n\t\treturn [\n\t\t\tmake_diagnostic(\n\t\t\t\tloc,\n\t\t\t\tmake_bare_effect_gen_warning(filename, attribute_name, expression_text),\n\t\t\t),\n\t\t];\n\t}\n\n\tif (is_event_attribute && is_callback) {\n\t\treturn [\n\t\t\tmake_diagnostic(\n\t\t\t\tloc,\n\t\t\t\tmake_event_callback_returns_effect_warning(\n\t\t\t\t\tfilename,\n\t\t\t\t\tattribute_name,\n\t\t\t\t\texpression_text,\n\t\t\t\t),\n\t\t\t),\n\t\t];\n\t}\n\n\tif (is_event_attribute) {\n\t\treturn [\n\t\t\tmake_diagnostic(\n\t\t\t\tloc,\n\t\t\t\tmake_event_attribute_effect_warning(filename, attribute_name, expression_text),\n\t\t\t),\n\t\t];\n\t}\n\n\tif (is_attribute) {\n\t\treturn [\n\t\t\tmake_diagnostic(\n\t\t\t\tloc,\n\t\t\t\tmake_attribute_effect_warning(filename, attribute_name, expression_text),\n\t\t\t),\n\t\t];\n\t}\n\n\treturn [make_diagnostic(loc, make_sync_markup_effect_warning(filename, expression_text))];\n}\n\nfunction make_diagnostic(loc: { line: number; column: number }, message: string): Diagnostic {\n\treturn {\n\t\tmessage,\n\t\tline: loc.line,\n\t\tcolumn: loc.column,\n\t};\n}\n\nfunction make_hidden_event_yield_warning(\n\tfilename: string,\n\tattribute_name: string,\n\texpression_text: string,\n): string {\n\treturn [\n\t\t`[svelte-effect-runtime] Detected yield* hidden inside an event callback.`,\n\t\t`${filename}: ${attribute_name}={${expression_text}}`,\n\t\t`SER can only lower yield* at the event attribute boundary.`,\n\t\t`Write the event expression directly, for example: ${attribute_name}={yield* save()}`,\n\t].join(\"\\n\");\n}\n\nfunction make_explicit_runner_warning(\n\tfilename: string,\n\tattribute_name: string | undefined,\n\texpression_text: string,\n): string {\n\tconst location = attribute_name\n\t\t? `${attribute_name}={${expression_text}}`\n\t\t: `{${expression_text}}`;\n\n\treturn [\n\t\t`[svelte-effect-runtime] Detected an explicit Effect runner inside Svelte markup.`,\n\t\t`${filename}: ${location}`,\n\t\t`Explicit runners bypass SER cancellation and error handling for markup effects.`,\n\t\t`Prefer yield* so SER can manage the Effect lifecycle.`,\n\t].join(\"\\n\");\n}\n\nfunction make_bare_effect_gen_warning(\n\tfilename: string,\n\tattribute_name: string | undefined,\n\texpression_text: string,\n): string {\n\tconst location = attribute_name\n\t\t? `${attribute_name}={${expression_text}}`\n\t\t: `{${expression_text}}`;\n\tconst fixed = attribute_name\n\t\t? `${attribute_name}={yield* ${expression_text}(function* () { ... })}`\n\t\t: `{yield* ${expression_text}(function* () { ... })}`;\n\n\treturn [\n\t\t`[svelte-effect-runtime] Detected Effect.gen used as a value instead of an Effect program.`,\n\t\t`${filename}: ${location}`,\n\t\t`${expression_text} is a constructor, not the result of running a generator.`,\n\t\t`Use: ${fixed}`,\n\t].join(\"\\n\");\n}\n\nfunction make_event_callback_returns_effect_warning(\n\tfilename: string,\n\tattribute_name: string,\n\texpression_text: string,\n): string {\n\treturn [\n\t\t`[svelte-effect-runtime] Detected an event callback that returns an Effect but does not run it.`,\n\t\t`${filename}: ${attribute_name}={${expression_text}}`,\n\t\t`Svelte will call the callback and receive an Effect value, but SER will not manage it from inside the callback.`,\n\t\t`Use yield* at the event attribute boundary or explicitly run the Effect if you really want to bypass SER.`,\n\t].join(\"\\n\");\n}\n\nfunction make_event_attribute_effect_warning(\n\tfilename: string,\n\tattribute_name: string,\n\texpression_text: string,\n): string {\n\tconst fixed = `${attribute_name}={yield* ${expression_text}}`;\n\n\treturn [\n\t\t`[svelte-effect-runtime] Detected an event attribute that looks like an Effect but is not written with yield*.`,\n\t\t`${filename}: ${attribute_name}={${expression_text}}`,\n\t\t`If you are trying to use Effect in this event handler, use yield* at the beginning.`,\n\t\t`Use: ${fixed}`,\n\t].join(\"\\n\");\n}\n\nfunction make_attribute_effect_warning(\n\tfilename: string,\n\tattribute_name: string,\n\texpression_text: string,\n): string {\n\tconst fixed = `${attribute_name}={yield* ${expression_text}}`;\n\n\treturn [\n\t\t`[svelte-effect-runtime] Detected an attribute value that looks like an Effect but is not written with yield*.`,\n\t\t`${filename}: ${attribute_name}={${expression_text}}`,\n\t\t`Svelte attributes need the resolved Effect value, not the Effect object itself.`,\n\t\t`Use: ${fixed}`,\n\t].join(\"\\n\");\n}\n\nfunction make_sync_markup_effect_warning(filename: string, expression_text: string): string {\n\treturn [\n\t\t`[svelte-effect-runtime] Detected a markup expression that creates an Effect but is not written with yield*.`,\n\t\t`${filename}: {${expression_text}}`,\n\t\t`This expression will produce an Effect value, not its result.`,\n\t\t`Use yield* where Svelte expects the resolved value.`,\n\t].join(\"\\n\");\n}\n\nfunction parse_markup_expression(\n\texpression_text: string,\n\teffect_binding_paths: EffectBindings,\n): ParsedMarkupExpression | undefined {\n\tconst has_binding_candidate = effect_binding_paths.root_names.some((root_name) =>\n\t\texpression_text.includes(root_name),\n\t);\n\tconst has_member_candidate = effect_member_names.some((member_name) =>\n\t\texpression_text.includes(member_name),\n\t);\n\tconst has_yield_candidate = /\\byield\\s*\\*/.test(expression_text);\n\n\tif ((!has_binding_candidate || !has_member_candidate) && !has_yield_candidate) {\n\t\treturn undefined;\n\t}\n\n\tconst normalized = normalize_markup_expression(expression_text);\n\n\tif (normalized.kind === \"declaration\") {\n\t\tconst source_file = ts.createSourceFile(\n\t\t\t\"diagnostics-declaration.ts\",\n\t\t\t`${normalized.text};`,\n\t\t\tts.ScriptTarget.Latest,\n\t\t\ttrue,\n\t\t\tts.ScriptKind.TS,\n\t\t);\n\t\tconst variable_statement = source_file.statements.find(ts.isVariableStatement);\n\t\tconst root_expression = unwrap_parentheses(\n\t\t\tvariable_statement?.declarationList.declarations[0]?.initializer,\n\t\t);\n\n\t\treturn {\n\t\t\tsource_file,\n\t\t\troot_expression,\n\t\t\tis_direct_expression: false,\n\t\t};\n\t}\n\n\tconst source_file = ts.createSourceFile(\n\t\t\"diagnostics-expression.ts\",\n\t\t`function* __SER___diagnostic() { return (${normalized.text}); }`,\n\t\tts.ScriptTarget.Latest,\n\t\ttrue,\n\t\tts.ScriptKind.TS,\n\t);\n\tconst wrapper = source_file.statements.find(ts.isFunctionDeclaration);\n\tconst return_statement = wrapper?.body?.statements.find(ts.isReturnStatement);\n\tconst root_expression = unwrap_parentheses(return_statement?.expression);\n\n\treturn {\n\t\tsource_file,\n\t\troot_expression,\n\t\tis_direct_expression: normalized.is_direct_expression,\n\t};\n}\n\nfunction normalize_markup_expression(expression_text: string): NormalizedMarkupExpression {\n\tconst trimmed = expression_text.trim();\n\n\tif (/^@const\\s+/.test(trimmed)) {\n\t\treturn {\n\t\t\tkind: \"declaration\",\n\t\t\ttext: trimmed.slice(1),\n\t\t\tis_direct_expression: false,\n\t\t};\n\t}\n\n\tif (/^(?:const|let)\\s+/.test(trimmed)) {\n\t\treturn {\n\t\t\tkind: \"declaration\",\n\t\t\ttext: trimmed,\n\t\t\tis_direct_expression: false,\n\t\t};\n\t}\n\n\tconst prefix = find_markup_expression_prefix(trimmed);\n\tlet text = prefix ? trimmed.slice(prefix.length) : trimmed;\n\n\tif (prefix?.kind === \"each\") {\n\t\tconst boundaries = [...text.matchAll(/\\s+as\\s+/g)];\n\t\tconst boundary = boundaries.at(-1)?.index ?? -1;\n\n\t\ttext = boundary === -1 ? text : text.slice(0, boundary);\n\t}\n\n\tif (prefix?.kind === \"await\") {\n\t\ttext = slice_before_await_context(text);\n\t}\n\n\treturn {\n\t\tkind: \"expression\",\n\t\ttext: text.trim(),\n\t\tis_direct_expression: prefix === undefined,\n\t};\n}\n\nfunction find_markup_expression_prefix(\n\texpression_text: string,\n): { kind: string; length: number } | undefined {\n\tconst prefixes: Array<{ kind: string; pattern: RegExp }> = [\n\t\t{ kind: \"else_if\", pattern: /^:else\\s+if\\s+/ },\n\t\t{ kind: \"attach\", pattern: /^@attach\\s+/ },\n\t\t{ kind: \"render\", pattern: /^@render\\s+/ },\n\t\t{ kind: \"debug\", pattern: /^@debug\\s+/ },\n\t\t{ kind: \"html\", pattern: /^@html\\s+/ },\n\t\t{ kind: \"await\", pattern: /^#await\\s+/ },\n\t\t{ kind: \"each\", pattern: /^#each\\s+/ },\n\t\t{ kind: \"key\", pattern: /^#key\\s+/ },\n\t\t{ kind: \"if\", pattern: /^#if\\s+/ },\n\t\t{ kind: \"spread\", pattern: /^\\.\\.\\./ },\n\t];\n\n\tfor (const prefix of prefixes) {\n\t\tconst match = prefix.pattern.exec(expression_text);\n\n\t\tif (match) {\n\t\t\treturn { kind: prefix.kind, length: match[0].length };\n\t\t}\n\t}\n\n\treturn undefined;\n}\n\nfunction slice_before_await_context(expression_text: string): string {\n\tconst wrapper_prefix = \"function* __SER___await() { return (\";\n\tconst source_file = ts.createSourceFile(\n\t\t\"diagnostics-await.ts\",\n\t\t`${wrapper_prefix}${expression_text}); }`,\n\t\tts.ScriptTarget.Latest,\n\t\ttrue,\n\t\tts.ScriptKind.TS,\n\t);\n\tconst wrapper = source_file.statements.find(ts.isFunctionDeclaration);\n\tconst return_statement = wrapper?.body?.statements.find(ts.isReturnStatement);\n\tconst root_expression = unwrap_parentheses(return_statement?.expression);\n\tconst boundary = root_expression ? root_expression.end - wrapper_prefix.length : -1;\n\tconst remainder = boundary === -1 ? \"\" : expression_text.slice(boundary).trimStart();\n\n\tif (!/^(?:then|catch)(?:\\s|$)/.test(remainder)) {\n\t\treturn expression_text;\n\t}\n\n\treturn expression_text.slice(0, boundary);\n}\n\nfunction contains_effect_reference(\n\tparsed_expression: ParsedMarkupExpression,\n\teffect_binding_paths: EffectBindings,\n): boolean {\n\treturn some_node(parsed_expression.source_file, (node) =>\n\t\tis_effect_member(node, effect_binding_paths, effect_member_name_set),\n\t);\n}\n\nfunction contains_effect_runner(\n\tparsed_expression: ParsedMarkupExpression,\n\teffect_binding_paths: EffectBindings,\n): boolean {\n\treturn some_node(parsed_expression.source_file, (node) =>\n\t\tis_effect_member(node, effect_binding_paths, effect_runner_names),\n\t);\n}\n\nfunction contains_unyielded_effect_reference(\n\tparsed_expression: ParsedMarkupExpression,\n\teffect_binding_paths: EffectBindings,\n): boolean {\n\treturn some_node(\n\t\tparsed_expression.source_file,\n\t\t(node) =>\n\t\t\tis_effect_member(node, effect_binding_paths, effect_member_name_set) &&\n\t\t\t!has_yield_star_ancestor(node),\n\t);\n}\n\nfunction is_bare_effect_gen(\n\tparsed_expression: ParsedMarkupExpression,\n\teffect_binding_paths: EffectBindings,\n): boolean {\n\tconst root_expression = parsed_expression.root_expression;\n\n\treturn (\n\t\tparsed_expression.is_direct_expression &&\n\t\troot_expression !== undefined &&\n\t\tis_effect_member(root_expression, effect_binding_paths, effect_gen_name)\n\t);\n}\n\nfunction contains_yield_star(parsed_expression: ParsedMarkupExpression): boolean {\n\treturn some_node(parsed_expression.source_file, is_yield_star_expression);\n}\n\nfunction contains_callback_yield_star(parsed_expression: ParsedMarkupExpression): boolean {\n\tconst callback = parsed_expression.root_expression;\n\tlet matched = false;\n\n\tif (!callback || (!ts.isArrowFunction(callback) && !ts.isFunctionExpression(callback))) {\n\t\treturn false;\n\t}\n\n\tfunction visit(node: ts.Node): void {\n\t\tif (matched || (node !== callback && ts.isFunctionLike(node))) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (is_yield_star_expression(node)) {\n\t\t\tmatched = true;\n\n\t\t\treturn;\n\t\t}\n\n\t\tts.forEachChild(node, visit);\n\t}\n\n\tvisit(callback.body);\n\n\treturn matched;\n}\n\nfunction is_callback_expression(parsed_expression: ParsedMarkupExpression): boolean {\n\tconst root_expression = parsed_expression.root_expression;\n\n\treturn (\n\t\tparsed_expression.is_direct_expression &&\n\t\troot_expression !== undefined &&\n\t\t(ts.isArrowFunction(root_expression) || ts.isFunctionExpression(root_expression))\n\t);\n}\n\nfunction is_effect_member(\n\tnode: ts.Node,\n\teffect_binding_paths: EffectBindings,\n\tmember_names: ReadonlySet<string>,\n): boolean {\n\tconst access_path = get_static_access_path(node);\n\n\tif (!access_path || access_path.length < 2) {\n\t\treturn false;\n\t}\n\n\tconst member_name = access_path[access_path.length - 1];\n\tconst owner_path = access_path.slice(0, -1);\n\n\tif (member_name === undefined) {\n\t\treturn false;\n\t}\n\n\treturn member_names.has(member_name) && effect_binding_paths.paths.has(owner_path.join(\".\"));\n}\n\nfunction get_static_access_path(node: ts.Node): string[] | undefined {\n\tif (ts.isParenthesizedExpression(node)) {\n\t\treturn get_static_access_path(node.expression);\n\t}\n\n\tif (ts.isIdentifier(node)) {\n\t\treturn [node.text];\n\t}\n\n\tif (ts.isPropertyAccessExpression(node)) {\n\t\tconst owner_path = get_static_access_path(node.expression);\n\n\t\treturn owner_path ? [...owner_path, node.name.text] : undefined;\n\t}\n\n\tif (\n\t\tts.isElementAccessExpression(node) &&\n\t\tnode.argumentExpression &&\n\t\t(ts.isStringLiteral(node.argumentExpression) ||\n\t\t\tts.isNoSubstitutionTemplateLiteral(node.argumentExpression))\n\t) {\n\t\tconst owner_path = get_static_access_path(node.expression);\n\n\t\treturn owner_path ? [...owner_path, node.argumentExpression.text] : undefined;\n\t}\n\n\treturn undefined;\n}\n\nfunction some_node(node: ts.Node, predicate: (node: ts.Node) => boolean): boolean {\n\tlet matched = false;\n\n\tif (predicate(node)) {\n\t\treturn true;\n\t}\n\n\tts.forEachChild(node, (child) => {\n\t\tmatched ||= some_node(child, predicate);\n\t});\n\n\treturn matched;\n}\n\nfunction is_yield_star_expression(node: ts.Node): boolean {\n\treturn (\n\t\t(ts.isYieldExpression(node) && node.asteriskToken !== undefined) ||\n\t\t(ts.isBinaryExpression(node) &&\n\t\t\tnode.operatorToken.kind === ts.SyntaxKind.AsteriskToken &&\n\t\t\tts.isIdentifier(node.left) &&\n\t\t\tnode.left.text === \"yield\")\n\t);\n}\n\nfunction has_yield_star_ancestor(node: ts.Node): boolean {\n\tlet current = node.parent;\n\n\twhile (current) {\n\t\tif (is_yield_star_expression(current)) {\n\t\t\treturn true;\n\t\t}\n\n\t\tcurrent = current.parent;\n\t}\n\n\treturn false;\n}\n\nfunction unwrap_parentheses(expression: ts.Expression | undefined): ts.Expression | undefined {\n\tlet current = expression;\n\n\twhile (current && ts.isParenthesizedExpression(current)) {\n\t\tcurrent = current.expression;\n\t}\n\n\treturn current;\n}\n\nfunction get_line_column(line_starts: number[], position: number): SourceLocation {\n\tlet low = 0;\n\tlet high = line_starts.length - 1;\n\n\twhile (low <= high) {\n\t\tconst mid = Math.floor((low + high) / 2);\n\n\t\tif (line_starts[mid] <= position) {\n\t\t\tlow = mid + 1;\n\t\t} else {\n\t\t\thigh = mid - 1;\n\t\t}\n\t}\n\n\tconst line_index = Math.max(0, high);\n\tconst line = line_index + 1;\n\tconst column = position - line_starts[line_index];\n\n\treturn { line, column };\n}\n\nfunction make_line_starts(code: string): number[] {\n\tconst line_starts = [0];\n\n\tfor (let i = 0; i < code.length; i += 1) {\n\t\tif (code[i] !== \"\\n\") {\n\t\t\tcontinue;\n\t\t}\n\n\t\tline_starts.push(i + 1);\n\t}\n\n\treturn line_starts;\n}\n"],"mappings":";;;AAoCA,MAAM,sBAAsB;CAC3B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD;AACA,MAAM,yBAAyB,IAAI,IAAY,mBAAmB;AAClE,MAAM,sCAAsB,IAAI,IAAI;CAAC;CAAW;CAAc;AAAS,CAAC;AACxE,MAAM,kCAAkB,IAAI,IAAI,CAAC,KAAK,CAAC;AAEvC,SAA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],"sources":["../../../modules/svelte-effect-runtime/src/diagnostics.ts"],"sourcesContent":["import type { MarkupBraceExpression, ScriptRegion } from \"$/compiler/source-scan.ts\";\nimport { scan_svelte_effect_source } from \"$/compiler/source-scan.ts\";\n\nimport ts from \"typescript\";\n\n/**\n * Warning diagnostic produced by the SER Vite diagnostics plugin.\n */\ninterface Diagnostic {\n\tmessage: string;\n\tline: number;\n\tcolumn: number;\n}\n\ninterface SourceLocation {\n\tline: number;\n\tcolumn: number;\n}\n\ninterface ParsedMarkupExpression {\n\tsource_file: ts.SourceFile;\n\troot_expression: ts.Expression | undefined;\n\tis_direct_expression: boolean;\n}\n\ninterface EffectBindings {\n\tpaths: ReadonlySet<string>;\n\troot_names: readonly string[];\n}\n\ninterface NormalizedMarkupExpression {\n\tkind: \"declaration\" | \"expression\";\n\ttext: string;\n\tis_direct_expression: boolean;\n}\n\nconst effect_member_names = [\n\t\"all\",\n\t\"fail\",\n\t\"gen\",\n\t\"log\",\n\t\"promise\",\n\t\"runFork\",\n\t\"runPromise\",\n\t\"runSync\",\n\t\"succeed\",\n\t\"sync\",\n\t\"try\",\n\t\"tryPromise\",\n\t\"void\",\n] as const;\nconst effect_member_name_set = new Set<string>(effect_member_names);\nconst effect_runner_names = new Set([\"runFork\", \"runPromise\", \"runSync\"]);\nconst effect_gen_name = new Set([\"gen\"]);\n\nexport function find_svelte_effect_diagnostics(\n\tcode: string,\n\tfilename: string,\n): Array<{ message: string; line: number; column: number }> {\n\tconst scan = scan_svelte_effect_source(code, filename);\n\tconst effect_binding_paths = find_effect_binding_paths(scan.scripts);\n\tconst line_starts = make_line_starts(code);\n\n\treturn scan.markup_expressions.flatMap((expression) =>\n\t\tmake_expression_diagnostics(filename, effect_binding_paths, expression, line_starts),\n\t);\n}\n\nfunction find_effect_binding_paths(scripts: readonly ScriptRegion[]): EffectBindings {\n\tconst seen_paths = new Set([\"Effect\"]);\n\tconst root_names = new Set([\"Effect\"]);\n\n\tfor (const script of scripts) {\n\t\tconst source_file = ts.createSourceFile(\n\t\t\t\"diagnostics-script.ts\",\n\t\t\tscript.text,\n\t\t\tts.ScriptTarget.Latest,\n\t\t\ttrue,\n\t\t\tts.ScriptKind.TS,\n\t\t);\n\n\t\tfor (const statement of source_file.statements) {\n\t\t\tfor (const binding_path of get_effect_import_binding_paths(statement)) {\n\t\t\t\tconst key = binding_path.join(\".\");\n\n\t\t\t\tif (seen_paths.has(key)) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tseen_paths.add(key);\n\t\t\t\troot_names.add(binding_path[0]);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn { paths: seen_paths, root_names: [...root_names] };\n}\n\nfunction get_effect_import_binding_paths(statement: ts.Statement): string[][] {\n\tif (\n\t\t!ts.isImportDeclaration(statement) ||\n\t\t!ts.isStringLiteral(statement.moduleSpecifier) ||\n\t\t!statement.importClause ||\n\t\tstatement.importClause.isTypeOnly\n\t) {\n\t\treturn [];\n\t}\n\n\tconst module_name = statement.moduleSpecifier.text;\n\tconst named_bindings = statement.importClause.namedBindings;\n\n\tif (!named_bindings) {\n\t\treturn [];\n\t}\n\n\tif (module_name === \"effect\" && ts.isNamedImports(named_bindings)) {\n\t\treturn named_bindings.elements.flatMap((specifier) => {\n\t\t\tconst imported_name = specifier.propertyName?.text ?? specifier.name.text;\n\n\t\t\treturn !specifier.isTypeOnly && imported_name === \"Effect\"\n\t\t\t\t? [[specifier.name.text]]\n\t\t\t\t: [];\n\t\t});\n\t}\n\n\tif (module_name === \"effect\" && ts.isNamespaceImport(named_bindings)) {\n\t\treturn [[named_bindings.name.text, \"Effect\"]];\n\t}\n\n\tif (module_name === \"effect/Effect\" && ts.isNamespaceImport(named_bindings)) {\n\t\treturn [[named_bindings.name.text]];\n\t}\n\n\treturn [];\n}\n\nfunction make_expression_diagnostics(\n\tfilename: string,\n\teffect_binding_paths: EffectBindings,\n\texpression: MarkupBraceExpression,\n\tline_starts: number[],\n): Diagnostic[] {\n\tconst attribute_name = expression.attribute_name;\n\tconst expression_text = expression.expression_text;\n\tconst is_event_attribute = attribute_name !== undefined && attribute_name.startsWith(\"on\");\n\tconst is_attribute = attribute_name !== undefined;\n\tconst parsed_expression = parse_markup_expression(expression_text, effect_binding_paths);\n\n\tif (!parsed_expression) {\n\t\treturn [];\n\t}\n\n\tconst is_callback = is_callback_expression(parsed_expression);\n\tconst has_yield_star = is_callback\n\t\t? contains_callback_yield_star(parsed_expression)\n\t\t: contains_yield_star(parsed_expression);\n\tconst is_hidden_event_yield = is_event_attribute && is_callback && has_yield_star;\n\tconst has_effect_reference = contains_effect_reference(parsed_expression, effect_binding_paths);\n\n\tif (!has_effect_reference && !is_hidden_event_yield) {\n\t\treturn [];\n\t}\n\n\tif (\n\t\t!contains_unyielded_effect_reference(parsed_expression, effect_binding_paths) &&\n\t\t!is_hidden_event_yield\n\t) {\n\t\treturn [];\n\t}\n\n\tconst loc = get_line_column(line_starts, expression.open);\n\n\tif (is_hidden_event_yield) {\n\t\treturn [\n\t\t\tmake_diagnostic(\n\t\t\t\tloc,\n\t\t\t\tmake_hidden_event_yield_warning(filename, attribute_name, expression_text),\n\t\t\t),\n\t\t];\n\t}\n\n\tif (contains_effect_runner(parsed_expression, effect_binding_paths)) {\n\t\treturn [\n\t\t\tmake_diagnostic(\n\t\t\t\tloc,\n\t\t\t\tmake_explicit_runner_warning(filename, attribute_name, expression_text),\n\t\t\t),\n\t\t];\n\t}\n\n\tif (is_bare_effect_gen(parsed_expression, effect_binding_paths)) {\n\t\treturn [\n\t\t\tmake_diagnostic(\n\t\t\t\tloc,\n\t\t\t\tmake_bare_effect_gen_warning(filename, attribute_name, expression_text),\n\t\t\t),\n\t\t];\n\t}\n\n\tif (is_event_attribute && is_callback) {\n\t\treturn [\n\t\t\tmake_diagnostic(\n\t\t\t\tloc,\n\t\t\t\tmake_event_callback_returns_effect_warning(\n\t\t\t\t\tfilename,\n\t\t\t\t\tattribute_name,\n\t\t\t\t\texpression_text,\n\t\t\t\t),\n\t\t\t),\n\t\t];\n\t}\n\n\tif (is_event_attribute) {\n\t\treturn [\n\t\t\tmake_diagnostic(\n\t\t\t\tloc,\n\t\t\t\tmake_event_attribute_effect_warning(filename, attribute_name, expression_text),\n\t\t\t),\n\t\t];\n\t}\n\n\tif (is_attribute) {\n\t\treturn [\n\t\t\tmake_diagnostic(\n\t\t\t\tloc,\n\t\t\t\tmake_attribute_effect_warning(filename, attribute_name, expression_text),\n\t\t\t),\n\t\t];\n\t}\n\n\treturn [make_diagnostic(loc, make_sync_markup_effect_warning(filename, expression_text))];\n}\n\nfunction make_diagnostic(loc: { line: number; column: number }, message: string): Diagnostic {\n\treturn {\n\t\tmessage,\n\t\tline: loc.line,\n\t\tcolumn: loc.column,\n\t};\n}\n\nfunction make_hidden_event_yield_warning(\n\tfilename: string,\n\tattribute_name: string,\n\texpression_text: string,\n): string {\n\treturn [\n\t\t`[svelte-effect-runtime] Detected yield* hidden inside an event callback.`,\n\t\t`${filename}: ${attribute_name}={${expression_text}}`,\n\t\t`SER can only lower yield* at the event attribute boundary.`,\n\t\t`Write the event expression directly, for example: ${attribute_name}={yield* save()}`,\n\t].join(\"\\n\");\n}\n\nfunction make_explicit_runner_warning(\n\tfilename: string,\n\tattribute_name: string | undefined,\n\texpression_text: string,\n): string {\n\tconst location = attribute_name\n\t\t? `${attribute_name}={${expression_text}}`\n\t\t: `{${expression_text}}`;\n\n\treturn [\n\t\t`[svelte-effect-runtime] Detected an explicit Effect runner inside Svelte markup.`,\n\t\t`${filename}: ${location}`,\n\t\t`Explicit runners bypass SER cancellation and error handling for markup effects.`,\n\t\t`Prefer yield* so SER can manage the Effect lifecycle.`,\n\t].join(\"\\n\");\n}\n\nfunction make_bare_effect_gen_warning(\n\tfilename: string,\n\tattribute_name: string | undefined,\n\texpression_text: string,\n): string {\n\tconst location = attribute_name\n\t\t? `${attribute_name}={${expression_text}}`\n\t\t: `{${expression_text}}`;\n\tconst fixed = attribute_name\n\t\t? `${attribute_name}={yield* ${expression_text}(function* () { ... })}`\n\t\t: `{yield* ${expression_text}(function* () { ... })}`;\n\n\treturn [\n\t\t`[svelte-effect-runtime] Detected Effect.gen used as a value instead of an Effect program.`,\n\t\t`${filename}: ${location}`,\n\t\t`${expression_text} is a constructor, not the result of running a generator.`,\n\t\t`Use: ${fixed}`,\n\t].join(\"\\n\");\n}\n\nfunction make_event_callback_returns_effect_warning(\n\tfilename: string,\n\tattribute_name: string,\n\texpression_text: string,\n): string {\n\treturn [\n\t\t`[svelte-effect-runtime] Detected an event callback that returns an Effect but does not run it.`,\n\t\t`${filename}: ${attribute_name}={${expression_text}}`,\n\t\t`Svelte will call the callback and receive an Effect value, but SER will not manage it from inside the callback.`,\n\t\t`Use yield* at the event attribute boundary or explicitly run the Effect if you really want to bypass SER.`,\n\t].join(\"\\n\");\n}\n\nfunction make_event_attribute_effect_warning(\n\tfilename: string,\n\tattribute_name: string,\n\texpression_text: string,\n): string {\n\tconst fixed = `${attribute_name}={yield* ${expression_text}}`;\n\n\treturn [\n\t\t`[svelte-effect-runtime] Detected an event attribute that looks like an Effect but is not written with yield*.`,\n\t\t`${filename}: ${attribute_name}={${expression_text}}`,\n\t\t`If you are trying to use Effect in this event handler, use yield* at the beginning.`,\n\t\t`Use: ${fixed}`,\n\t].join(\"\\n\");\n}\n\nfunction make_attribute_effect_warning(\n\tfilename: string,\n\tattribute_name: string,\n\texpression_text: string,\n): string {\n\tconst fixed = `${attribute_name}={yield* ${expression_text}}`;\n\n\treturn [\n\t\t`[svelte-effect-runtime] Detected an attribute value that looks like an Effect but is not written with yield*.`,\n\t\t`${filename}: ${attribute_name}={${expression_text}}`,\n\t\t`Svelte attributes need the resolved Effect value, not the Effect object itself.`,\n\t\t`Use: ${fixed}`,\n\t].join(\"\\n\");\n}\n\nfunction make_sync_markup_effect_warning(filename: string, expression_text: string): string {\n\treturn [\n\t\t`[svelte-effect-runtime] Detected a markup expression that creates an Effect but is not written with yield*.`,\n\t\t`${filename}: {${expression_text}}`,\n\t\t`This expression will produce an Effect value, not its result.`,\n\t\t`Use yield* where Svelte expects the resolved value.`,\n\t].join(\"\\n\");\n}\n\nfunction parse_markup_expression(\n\texpression_text: string,\n\teffect_binding_paths: EffectBindings,\n): ParsedMarkupExpression | undefined {\n\tconst has_binding_candidate = effect_binding_paths.root_names.some((root_name) =>\n\t\texpression_text.includes(root_name),\n\t);\n\tconst has_member_candidate = effect_member_names.some((member_name) =>\n\t\texpression_text.includes(member_name),\n\t);\n\tconst has_yield_candidate = /\\byield\\s*\\*/.test(expression_text);\n\n\tif ((!has_binding_candidate || !has_member_candidate) && !has_yield_candidate) {\n\t\treturn undefined;\n\t}\n\n\tconst normalized = normalize_markup_expression(expression_text);\n\n\tif (normalized.kind === \"declaration\") {\n\t\tconst source_file = ts.createSourceFile(\n\t\t\t\"diagnostics-declaration.ts\",\n\t\t\t`${normalized.text};`,\n\t\t\tts.ScriptTarget.Latest,\n\t\t\ttrue,\n\t\t\tts.ScriptKind.TS,\n\t\t);\n\t\tconst variable_statement = source_file.statements.find(ts.isVariableStatement);\n\t\tconst root_expression = unwrap_parentheses(\n\t\t\tvariable_statement?.declarationList.declarations[0]?.initializer,\n\t\t);\n\n\t\treturn {\n\t\t\tsource_file,\n\t\t\troot_expression,\n\t\t\tis_direct_expression: false,\n\t\t};\n\t}\n\n\tconst source_file = ts.createSourceFile(\n\t\t\"diagnostics-expression.ts\",\n\t\t`function* __SER___diagnostic() { return (${normalized.text}); }`,\n\t\tts.ScriptTarget.Latest,\n\t\ttrue,\n\t\tts.ScriptKind.TS,\n\t);\n\tconst wrapper = source_file.statements.find(ts.isFunctionDeclaration);\n\tconst return_statement = wrapper?.body?.statements.find(ts.isReturnStatement);\n\tconst root_expression = unwrap_parentheses(return_statement?.expression);\n\n\treturn {\n\t\tsource_file,\n\t\troot_expression,\n\t\tis_direct_expression: normalized.is_direct_expression,\n\t};\n}\n\nfunction normalize_markup_expression(expression_text: string): NormalizedMarkupExpression {\n\tconst trimmed = expression_text.trim();\n\n\tif (/^@const\\s+/.test(trimmed)) {\n\t\treturn {\n\t\t\tkind: \"declaration\",\n\t\t\ttext: trimmed.slice(1),\n\t\t\tis_direct_expression: false,\n\t\t};\n\t}\n\n\tif (/^(?:const|let)\\s+/.test(trimmed)) {\n\t\treturn {\n\t\t\tkind: \"declaration\",\n\t\t\ttext: trimmed,\n\t\t\tis_direct_expression: false,\n\t\t};\n\t}\n\n\tconst prefix = find_markup_expression_prefix(trimmed);\n\tlet text = prefix ? trimmed.slice(prefix.length) : trimmed;\n\n\tif (prefix?.kind === \"each\") {\n\t\tconst boundaries = [...text.matchAll(/\\s+as\\s+/g)];\n\t\tconst boundary = boundaries.at(-1)?.index ?? -1;\n\n\t\ttext = boundary === -1 ? text : text.slice(0, boundary);\n\t}\n\n\tif (prefix?.kind === \"await\") {\n\t\ttext = slice_before_await_context(text);\n\t}\n\n\treturn {\n\t\tkind: \"expression\",\n\t\ttext: text.trim(),\n\t\tis_direct_expression: prefix === undefined,\n\t};\n}\n\nfunction find_markup_expression_prefix(\n\texpression_text: string,\n): { kind: string; length: number } | undefined {\n\tconst prefixes: Array<{ kind: string; pattern: RegExp }> = [\n\t\t{ kind: \"else_if\", pattern: /^:else\\s+if\\s+/ },\n\t\t{ kind: \"attach\", pattern: /^@attach\\s+/ },\n\t\t{ kind: \"render\", pattern: /^@render\\s+/ },\n\t\t{ kind: \"debug\", pattern: /^@debug\\s+/ },\n\t\t{ kind: \"html\", pattern: /^@html\\s+/ },\n\t\t{ kind: \"await\", pattern: /^#await\\s+/ },\n\t\t{ kind: \"each\", pattern: /^#each\\s+/ },\n\t\t{ kind: \"key\", pattern: /^#key\\s+/ },\n\t\t{ kind: \"if\", pattern: /^#if\\s+/ },\n\t\t{ kind: \"spread\", pattern: /^\\.\\.\\./ },\n\t];\n\n\tfor (const prefix of prefixes) {\n\t\tconst match = prefix.pattern.exec(expression_text);\n\n\t\tif (match) {\n\t\t\treturn { kind: prefix.kind, length: match[0].length };\n\t\t}\n\t}\n\n\treturn undefined;\n}\n\nfunction slice_before_await_context(expression_text: string): string {\n\tconst wrapper_prefix = \"function* __SER___await() { return (\";\n\tconst source_file = ts.createSourceFile(\n\t\t\"diagnostics-await.ts\",\n\t\t`${wrapper_prefix}${expression_text}); }`,\n\t\tts.ScriptTarget.Latest,\n\t\ttrue,\n\t\tts.ScriptKind.TS,\n\t);\n\tconst wrapper = source_file.statements.find(ts.isFunctionDeclaration);\n\tconst return_statement = wrapper?.body?.statements.find(ts.isReturnStatement);\n\tconst root_expression = unwrap_parentheses(return_statement?.expression);\n\tconst boundary = root_expression ? root_expression.end - wrapper_prefix.length : -1;\n\tconst remainder = boundary === -1 ? \"\" : expression_text.slice(boundary).trimStart();\n\n\tif (!/^(?:then|catch)(?:\\s|$)/.test(remainder)) {\n\t\treturn expression_text;\n\t}\n\n\treturn expression_text.slice(0, boundary);\n}\n\nfunction contains_effect_reference(\n\tparsed_expression: ParsedMarkupExpression,\n\teffect_binding_paths: EffectBindings,\n): boolean {\n\treturn some_node(parsed_expression.source_file, (node) =>\n\t\tis_effect_member(node, effect_binding_paths, effect_member_name_set),\n\t);\n}\n\nfunction contains_effect_runner(\n\tparsed_expression: ParsedMarkupExpression,\n\teffect_binding_paths: EffectBindings,\n): boolean {\n\treturn some_node(parsed_expression.source_file, (node) =>\n\t\tis_effect_member(node, effect_binding_paths, effect_runner_names),\n\t);\n}\n\nfunction contains_unyielded_effect_reference(\n\tparsed_expression: ParsedMarkupExpression,\n\teffect_binding_paths: EffectBindings,\n): boolean {\n\treturn some_node(\n\t\tparsed_expression.source_file,\n\t\t(node) =>\n\t\t\tis_effect_member(node, effect_binding_paths, effect_member_name_set) &&\n\t\t\t!has_yield_star_ancestor(node),\n\t);\n}\n\nfunction is_bare_effect_gen(\n\tparsed_expression: ParsedMarkupExpression,\n\teffect_binding_paths: EffectBindings,\n): boolean {\n\tconst root_expression = parsed_expression.root_expression;\n\n\treturn (\n\t\tparsed_expression.is_direct_expression &&\n\t\troot_expression !== undefined &&\n\t\tis_effect_member(root_expression, effect_binding_paths, effect_gen_name)\n\t);\n}\n\nfunction contains_yield_star(parsed_expression: ParsedMarkupExpression): boolean {\n\treturn some_node(parsed_expression.source_file, is_yield_star_expression);\n}\n\nfunction contains_callback_yield_star(parsed_expression: ParsedMarkupExpression): boolean {\n\tconst callback = parsed_expression.root_expression;\n\tlet matched = false;\n\n\tif (!callback || (!ts.isArrowFunction(callback) && !ts.isFunctionExpression(callback))) {\n\t\treturn false;\n\t}\n\n\tfunction visit(node: ts.Node): void {\n\t\tif (matched || (node !== callback && ts.isFunctionLike(node))) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (is_yield_star_expression(node)) {\n\t\t\tmatched = true;\n\n\t\t\treturn;\n\t\t}\n\n\t\tts.forEachChild(node, visit);\n\t}\n\n\tvisit(callback.body);\n\n\treturn matched;\n}\n\nfunction is_callback_expression(parsed_expression: ParsedMarkupExpression): boolean {\n\tconst root_expression = parsed_expression.root_expression;\n\n\treturn (\n\t\tparsed_expression.is_direct_expression &&\n\t\troot_expression !== undefined &&\n\t\t(ts.isArrowFunction(root_expression) || ts.isFunctionExpression(root_expression))\n\t);\n}\n\nfunction is_effect_member(\n\tnode: ts.Node,\n\teffect_binding_paths: EffectBindings,\n\tmember_names: ReadonlySet<string>,\n): boolean {\n\tconst access_path = get_static_access_path(node);\n\n\tif (!access_path || access_path.length < 2) {\n\t\treturn false;\n\t}\n\n\tconst member_name = access_path[access_path.length - 1];\n\tconst owner_path = access_path.slice(0, -1);\n\n\tif (member_name === undefined) {\n\t\treturn false;\n\t}\n\n\treturn member_names.has(member_name) && effect_binding_paths.paths.has(owner_path.join(\".\"));\n}\n\nfunction get_static_access_path(node: ts.Node): string[] | undefined {\n\tif (ts.isParenthesizedExpression(node)) {\n\t\treturn get_static_access_path(node.expression);\n\t}\n\n\tif (ts.isIdentifier(node)) {\n\t\treturn [node.text];\n\t}\n\n\tif (ts.isPropertyAccessExpression(node)) {\n\t\tconst owner_path = get_static_access_path(node.expression);\n\n\t\treturn owner_path ? [...owner_path, node.name.text] : undefined;\n\t}\n\n\tif (\n\t\tts.isElementAccessExpression(node) &&\n\t\tnode.argumentExpression &&\n\t\t(ts.isStringLiteral(node.argumentExpression) ||\n\t\t\tts.isNoSubstitutionTemplateLiteral(node.argumentExpression))\n\t) {\n\t\tconst owner_path = get_static_access_path(node.expression);\n\n\t\treturn owner_path ? [...owner_path, node.argumentExpression.text] : undefined;\n\t}\n\n\treturn undefined;\n}\n\nfunction some_node(node: ts.Node, predicate: (node: ts.Node) => boolean): boolean {\n\tlet matched = false;\n\n\tif (predicate(node)) {\n\t\treturn true;\n\t}\n\n\tts.forEachChild(node, (child) => {\n\t\tmatched ||= some_node(child, predicate);\n\t});\n\n\treturn matched;\n}\n\nfunction is_yield_star_expression(node: ts.Node): boolean {\n\treturn (\n\t\t(ts.isYieldExpression(node) && node.asteriskToken !== undefined) ||\n\t\t(ts.isBinaryExpression(node) &&\n\t\t\tnode.operatorToken.kind === ts.SyntaxKind.AsteriskToken &&\n\t\t\tts.isIdentifier(node.left) &&\n\t\t\tnode.left.text === \"yield\")\n\t);\n}\n\nfunction has_yield_star_ancestor(node: ts.Node): boolean {\n\tlet current = node.parent;\n\n\twhile (current) {\n\t\tif (is_yield_star_expression(current)) {\n\t\t\treturn true;\n\t\t}\n\n\t\tcurrent = current.parent;\n\t}\n\n\treturn false;\n}\n\nfunction unwrap_parentheses(expression: ts.Expression | undefined): ts.Expression | undefined {\n\tlet current = expression;\n\n\twhile (current && ts.isParenthesizedExpression(current)) {\n\t\tcurrent = current.expression;\n\t}\n\n\treturn current;\n}\n\nfunction get_line_column(line_starts: number[], position: number): SourceLocation {\n\tlet low = 0;\n\tlet high = line_starts.length - 1;\n\n\twhile (low <= high) {\n\t\tconst mid = Math.floor((low + high) / 2);\n\n\t\tif (line_starts[mid] <= position) {\n\t\t\tlow = mid + 1;\n\t\t} else {\n\t\t\thigh = mid - 1;\n\t\t}\n\t}\n\n\tconst line_index = Math.max(0, high);\n\tconst line = line_index + 1;\n\tconst column = position - line_starts[line_index];\n\n\treturn { line, column };\n}\n\nfunction make_line_starts(code: string): number[] {\n\tconst line_starts = [0];\n\n\tfor (let i = 0; i < code.length; i += 1) {\n\t\tif (code[i] !== \"\\n\") {\n\t\t\tcontinue;\n\t\t}\n\n\t\tline_starts.push(i + 1);\n\t}\n\n\treturn line_starts;\n}\n"],"mappings":";;;AAoCA,MAAM,sBAAsB;CAC3B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD;AACA,MAAM,yBAAyB,IAAI,IAAY,mBAAmB;AAClE,MAAM,sCAAsB,IAAI,IAAI;CAAC;CAAW;CAAc;AAAS,CAAC;AACxE,MAAM,kCAAkB,IAAI,IAAI,CAAC,KAAK,CAAC;AAEvC,SAAgB,+BACf,MACA,UAC2D;CAC3D,MAAM,OAAO,0BAA0B,MAAM,QAAQ;CACrD,MAAM,uBAAuB,0BAA0B,KAAK,OAAO;CACnE,MAAM,cAAc,iBAAiB,IAAI;CAEzC,OAAO,KAAK,mBAAmB,SAAS,eACvC,4BAA4B,UAAU,sBAAsB,YAAY,WAAW,CACpF;AACD;AAEA,SAAS,0BAA0B,SAAkD;CACpF,MAAM,6BAAa,IAAI,IAAI,CAAC,QAAQ,CAAC;CACrC,MAAM,6BAAa,IAAI,IAAI,CAAC,QAAQ,CAAC;CAErC,KAAK,MAAM,UAAU,SAAS;EAC7B,MAAM,cAAc,GAAG,iBACtB,yBACA,OAAO,MACP,GAAG,aAAa,QAChB,MACA,GAAG,WAAW,EACf;EAEA,KAAK,MAAM,aAAa,YAAY,YACnC,KAAK,MAAM,gBAAgB,gCAAgC,SAAS,GAAG;GACtE,MAAM,MAAM,aAAa,KAAK,GAAG;GAEjC,IAAI,WAAW,IAAI,GAAG,GACrB;GAGD,WAAW,IAAI,GAAG;GAClB,WAAW,IAAI,aAAa,EAAE;EAC/B;CAEF;CAEA,OAAO;EAAE,OAAO;E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,YAAY,SAAS;CAEhC,OAAO,OAAO,MAAM;EACnB,MAAM,MAAM,KAAK,OAAO,MAAM,QAAQ,CAAC;EAEvC,IAAI,YAAY,QAAQ,UACvB,MAAM,MAAM;OAEZ,OAAO,MAAM;CAEf;CAEA,MAAM,aAAa,KAAK,IAAI,GAAG,IAAI;CAInC,OAAO;EAAE,MAHI,aAAa;EAGX,QAFA,WAAW,YAAY;CAEhB;AACvB;AAEA,SAAS,iBAAiB,MAAwB;CACjD,MAAM,cAAc,CAAC,CAAC;CAEtB,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK,GAAG;EACxC,IAAI,KAAK,OAAO,MACf;EAGD,YAAY,KAAK,IAAI,CAAC;CACvB;CAEA,OAAO;AACR"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as DispatcherDisposedError, b as RuntimeAlreadyInitializedError } from "./errors-
|
|
2
|
-
import { Cause, Effect, Exit, Fiber, Layer, ManagedRuntime } from "effect";
|
|
1
|
+
import { S as ScopeDisposedError, a as DispatcherDisposedError, b as RuntimeAlreadyInitializedError } from "./errors-qhcbUH6o.js";
|
|
2
|
+
import { Cause, Effect, Exit, Fiber, Layer, ManagedRuntime, Scope } from "effect";
|
|
3
3
|
import { createSubscriber } from "svelte/reactivity";
|
|
4
4
|
import { isRedirect } from "@sveltejs/kit";
|
|
5
5
|
//#region src/dispatcher/fibers.ts
|
|
@@ -29,6 +29,67 @@ const WatchFiberExit = (options) => {
|
|
|
29
29
|
});
|
|
30
30
|
};
|
|
31
31
|
//#endregion
|
|
32
|
+
//#region src/dispatcher/scope.ts
|
|
33
|
+
/**
|
|
34
|
+
* A component-owned Effect scope.
|
|
35
|
+
*
|
|
36
|
+
* A `ComponentScope` wraps a `Scope.Closeable` forked from the dispatcher's
|
|
37
|
+
* root scope. Work is forked into the scope with `Effect.forkIn`, so closing
|
|
38
|
+
* the scope interrupts that work and runs its finalizers. The generated
|
|
39
|
+
* component teardown disposes the scope on destroy. Disposal is idempotent.
|
|
40
|
+
*
|
|
41
|
+
* @since 4.1.0
|
|
42
|
+
*/
|
|
43
|
+
var ComponentScope = class ComponentScope {
|
|
44
|
+
#scope;
|
|
45
|
+
#disposed = false;
|
|
46
|
+
#on_dispose;
|
|
47
|
+
constructor(scope, on_dispose) {
|
|
48
|
+
this.#scope = scope;
|
|
49
|
+
this.#on_dispose = on_dispose;
|
|
50
|
+
}
|
|
51
|
+
/** Forks a child scope from the given root and returns it wrapped. */
|
|
52
|
+
static fork(root, on_dispose) {
|
|
53
|
+
return new ComponentScope(Scope.forkUnsafe(root), on_dispose);
|
|
54
|
+
}
|
|
55
|
+
/** The underlying closeable scope used to bind Effect work. */
|
|
56
|
+
get underlying() {
|
|
57
|
+
return this.#scope;
|
|
58
|
+
}
|
|
59
|
+
/** Whether this scope has already been disposed. */
|
|
60
|
+
get disposed() {
|
|
61
|
+
return this.#disposed;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Forks an effect into this scope. The fiber becomes a child of the scope,
|
|
65
|
+
* so disposing the scope interrupts it and runs its finalizers. The scope
|
|
66
|
+
* is provided ambiently so `Effect.forkIn` registers the fiber as a child.
|
|
67
|
+
*/
|
|
68
|
+
fork_in(effect) {
|
|
69
|
+
/**
|
|
70
|
+
* The effect must see the scope before it is forked: provide the scope
|
|
71
|
+
* inside the forked program so `acquireRelease`-style work resolves it,
|
|
72
|
+
* and fork that program into the scope so the fiber is a child whose
|
|
73
|
+
* finalizers run when the scope closes.
|
|
74
|
+
*/
|
|
75
|
+
return Effect.forkIn(Effect.provideService(effect, Scope.Scope, this.#scope), this.#scope);
|
|
76
|
+
}
|
|
77
|
+
/** Effect that closes the scope. Must be run by the owning dispatcher. */
|
|
78
|
+
get close_effect() {
|
|
79
|
+
return Scope.close(this.#scope, Exit.void);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Marks the scope disposed and detaches it from the dispatcher. The caller
|
|
83
|
+
* is responsible for running {@link close_effect} to run finalizers.
|
|
84
|
+
* Idempotent.
|
|
85
|
+
*/
|
|
86
|
+
dispose() {
|
|
87
|
+
if (this.#disposed) return;
|
|
88
|
+
this.#disposed = true;
|
|
89
|
+
this.#on_dispose(this);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
//#endregion
|
|
32
93
|
//#region src/dispatcher/deps.ts
|
|
33
94
|
function make_dependency_hasher() {
|
|
34
95
|
const object_dep_ids = /* @__PURE__ */ new WeakMap();
|
|
@@ -91,9 +152,18 @@ var Dispatcher = class Dispatcher {
|
|
|
91
152
|
#promise_values = /* @__PURE__ */ new Map();
|
|
92
153
|
#value_ids = /* @__PURE__ */ new Map();
|
|
93
154
|
#promise_ids = /* @__PURE__ */ new Map();
|
|
155
|
+
#scope_ids = /* @__PURE__ */ new WeakMap();
|
|
94
156
|
#hash_deps = make_dependency_hasher();
|
|
95
157
|
#disposed = false;
|
|
96
158
|
#next_fiber_id = 0;
|
|
159
|
+
#next_scope_id = 0;
|
|
160
|
+
#root_scope = Scope.makeUnsafe();
|
|
161
|
+
#component_scopes = /* @__PURE__ */ new Set();
|
|
162
|
+
/**
|
|
163
|
+
* The component scope that effect execution currently enters. Set by
|
|
164
|
+
* generated code via {@link with_scope}; `undefined` outside components.
|
|
165
|
+
*/
|
|
166
|
+
#current_scope = void 0;
|
|
97
167
|
static make(layer) {
|
|
98
168
|
if (current_dispatcher) throw new RuntimeAlreadyInitializedError("ClientRuntime");
|
|
99
169
|
const runtime = ManagedRuntime.make(layer ?? Layer.empty);
|
|
@@ -104,6 +174,76 @@ var Dispatcher = class Dispatcher {
|
|
|
104
174
|
constructor(runtime) {
|
|
105
175
|
this.#runtime = runtime ?? ManagedRuntime.make(Layer.empty);
|
|
106
176
|
}
|
|
177
|
+
/**
|
|
178
|
+
* Begin a component-owned Effect scope. Pass the returned scope to
|
|
179
|
+
* {@link run_scoped} so the work is interrupted and finalized when the
|
|
180
|
+
* component is destroyed. Disposal is idempotent.
|
|
181
|
+
*/
|
|
182
|
+
begin_scope() {
|
|
183
|
+
const scope = ComponentScope.fork(this.#root_scope, (disposed) => {
|
|
184
|
+
this.#component_scopes.delete(disposed);
|
|
185
|
+
});
|
|
186
|
+
this.#component_scopes.add(scope);
|
|
187
|
+
return scope;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Runs `fn` with `scope` as the current component scope. While active,
|
|
191
|
+
* every effect path ({@link promise}, {@link run}, {@link value}) forks
|
|
192
|
+
* its work into `scope` so disposing the scope interrupts it and runs its
|
|
193
|
+
* finalizers. A disposed scope falls back to unscoped execution.
|
|
194
|
+
*/
|
|
195
|
+
with_scope(scope, fn) {
|
|
196
|
+
if (scope.disposed) return fn();
|
|
197
|
+
const previous = this.#current_scope;
|
|
198
|
+
this.#current_scope = scope;
|
|
199
|
+
try {
|
|
200
|
+
return fn();
|
|
201
|
+
} finally {
|
|
202
|
+
this.#current_scope = previous;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Forks an effect into a component scope and starts it. The fiber becomes
|
|
207
|
+
* a child of the scope, so disposing the scope interrupts it and runs its
|
|
208
|
+
* finalizers. Returns an idempotent handle that interrupts the scoped
|
|
209
|
+
* fiber directly.
|
|
210
|
+
*
|
|
211
|
+
* Throws {@link ScopeDisposedError} when the scope was already disposed
|
|
212
|
+
* and {@link DispatcherDisposedError} when the dispatcher was shut down.
|
|
213
|
+
*/
|
|
214
|
+
run_scoped(scope, effect) {
|
|
215
|
+
if (this.#disposed) return () => {};
|
|
216
|
+
if (scope.disposed || !this.#component_scopes.has(scope)) throw new ScopeDisposedError();
|
|
217
|
+
/**
|
|
218
|
+
* Track the scoped fiber itself: `forkIn` binds it to the component
|
|
219
|
+
* scope rather than the awaiting parent, so per-run disposal must
|
|
220
|
+
* interrupt the scoped fiber directly.
|
|
221
|
+
*/
|
|
222
|
+
let scoped_fiber;
|
|
223
|
+
this.#runtime.runFork(Effect.flatMap(scope.fork_in(effect), (fiber) => {
|
|
224
|
+
scoped_fiber = fiber;
|
|
225
|
+
return Effect.asVoid(Fiber.await(fiber));
|
|
226
|
+
}));
|
|
227
|
+
let disposed = false;
|
|
228
|
+
return () => {
|
|
229
|
+
if (disposed) return;
|
|
230
|
+
disposed = true;
|
|
231
|
+
if (scoped_fiber) this.#runtime.runFork(InterruptFiber(scoped_fiber));
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Disposes a component scope owned by this dispatcher, interrupting its
|
|
236
|
+
* bound work and running its finalizers. Idempotent. Rejects scopes owned
|
|
237
|
+
* by another dispatcher with {@link ScopeDisposedError}.
|
|
238
|
+
*/
|
|
239
|
+
dispose_scope(scope) {
|
|
240
|
+
if (!this.#component_scopes.has(scope)) {
|
|
241
|
+
if (scope.disposed) return;
|
|
242
|
+
throw new ScopeDisposedError();
|
|
243
|
+
}
|
|
244
|
+
scope.dispose();
|
|
245
|
+
this.#runtime.runFork(scope.close_effect);
|
|
246
|
+
}
|
|
107
247
|
emit(event) {
|
|
108
248
|
switch (event.type) {
|
|
109
249
|
case Code.Markup.Value: return this.#emit_markup_value(event);
|
|
@@ -130,15 +270,17 @@ var Dispatcher = class Dispatcher {
|
|
|
130
270
|
}
|
|
131
271
|
value(options) {
|
|
132
272
|
if (this.#disposed) return options.fallback;
|
|
133
|
-
const
|
|
134
|
-
const
|
|
273
|
+
const scope_id = this.#scope_id(this.#current_scope);
|
|
274
|
+
const cache_id = this.#make_scoped_id(scope_id, options.id);
|
|
275
|
+
const cache_key = this.#make_value_cache_key(cache_id, options.deps);
|
|
276
|
+
const old_key = this.#value_ids.get(cache_id);
|
|
135
277
|
this.#subscribe_value_cells();
|
|
136
278
|
const cell = this.#value_cells.get(cache_key);
|
|
137
279
|
if (old_key !== void 0 && old_key !== cache_key) {
|
|
138
280
|
const old_fiber = this.#interrupt_cached_fiber(old_key);
|
|
139
281
|
this.#clear_pending_value_cell(old_key, old_fiber);
|
|
140
282
|
}
|
|
141
|
-
this.#value_ids.set(
|
|
283
|
+
this.#value_ids.set(cache_id, cache_key);
|
|
142
284
|
if (this.#should_start_value_fiber(cache_key, cell)) this.#start_value_fiber(cache_key, options);
|
|
143
285
|
if (cell?.status === "success") return cell.value;
|
|
144
286
|
if (cell?.status === "failure") throw cell.error;
|
|
@@ -146,16 +288,18 @@ var Dispatcher = class Dispatcher {
|
|
|
146
288
|
}
|
|
147
289
|
promise(options) {
|
|
148
290
|
if (this.#disposed) return Promise.reject(new DispatcherDisposedError());
|
|
149
|
-
const
|
|
150
|
-
const
|
|
291
|
+
const scope_id = this.#scope_id(this.#current_scope);
|
|
292
|
+
const cache_id = this.#make_scoped_id(scope_id, options.id);
|
|
293
|
+
const cache_key = this.#make_promise_cache_key(cache_id, options.deps);
|
|
294
|
+
const old_key = this.#promise_ids.get(cache_id);
|
|
151
295
|
if (old_key !== void 0 && old_key !== cache_key) {
|
|
152
296
|
this.#interrupt_cached_fiber(old_key);
|
|
153
297
|
this.#promise_values.delete(old_key);
|
|
154
298
|
}
|
|
155
|
-
this.#promise_ids.set(
|
|
299
|
+
this.#promise_ids.set(cache_id, cache_key);
|
|
156
300
|
const existing = this.#promise_values.get(cache_key);
|
|
157
301
|
if (existing) return existing;
|
|
158
|
-
const promise = this.#start_promise_fiber(cache_key, options);
|
|
302
|
+
const promise = this.#start_promise_fiber(cache_key, options, cache_id);
|
|
159
303
|
this.#promise_values.set(cache_key, promise);
|
|
160
304
|
return promise;
|
|
161
305
|
}
|
|
@@ -174,7 +318,8 @@ var Dispatcher = class Dispatcher {
|
|
|
174
318
|
});
|
|
175
319
|
return yield* Effect.fail(error);
|
|
176
320
|
});
|
|
177
|
-
|
|
321
|
+
const scope = this.#current_scope;
|
|
322
|
+
return this.#runtime.runPromise(scope ? Effect.provideService(Program, Scope.Scope, scope.underlying) : Program);
|
|
178
323
|
}
|
|
179
324
|
#emit_markup_value(event) {
|
|
180
325
|
if (this.#is_server_render()) return event.fallback;
|
|
@@ -202,6 +347,9 @@ var Dispatcher = class Dispatcher {
|
|
|
202
347
|
}
|
|
203
348
|
dispose() {
|
|
204
349
|
this.#disposed = true;
|
|
350
|
+
for (const scope of this.#component_scopes) scope.dispose();
|
|
351
|
+
this.#component_scopes.clear();
|
|
352
|
+
this.#runtime.runFork(Scope.close(this.#root_scope, Exit.void));
|
|
205
353
|
for (const fiber of this.#fibers.values()) this.#runtime.runFork(InterruptFiber(fiber));
|
|
206
354
|
this.#fibers.clear();
|
|
207
355
|
this.#clear_value_cells();
|
|
@@ -223,6 +371,18 @@ var Dispatcher = class Dispatcher {
|
|
|
223
371
|
#is_server_render() {
|
|
224
372
|
return typeof document === "undefined";
|
|
225
373
|
}
|
|
374
|
+
#scope_id(scope) {
|
|
375
|
+
if (!scope || scope.disposed) return "global";
|
|
376
|
+
const existing = this.#scope_ids.get(scope);
|
|
377
|
+
if (existing) return existing;
|
|
378
|
+
const next = String(this.#next_scope_id);
|
|
379
|
+
this.#next_scope_id += 1;
|
|
380
|
+
this.#scope_ids.set(scope, next);
|
|
381
|
+
return next;
|
|
382
|
+
}
|
|
383
|
+
#make_scoped_id(scope_id, id) {
|
|
384
|
+
return `${scope_id}|${id}`;
|
|
385
|
+
}
|
|
226
386
|
#interrupt_cached_fiber(cache_key) {
|
|
227
387
|
const old_fiber = this.#fibers.get(cache_key);
|
|
228
388
|
if (!old_fiber) return;
|
|
@@ -237,7 +397,15 @@ var Dispatcher = class Dispatcher {
|
|
|
237
397
|
const Program = Effect.gen(function* () {
|
|
238
398
|
return yield* Effect.gen(options.factory);
|
|
239
399
|
});
|
|
240
|
-
|
|
400
|
+
/**
|
|
401
|
+
* Provide the active component scope so scoped acquisition works and
|
|
402
|
+
* finalizers run when the scope closes on unmount. Interruption of an
|
|
403
|
+
* individual run does not close the component scope; its finalizers
|
|
404
|
+
* run at scope disposal, matching the component lifetime.
|
|
405
|
+
*/
|
|
406
|
+
const scope = this.#current_scope;
|
|
407
|
+
const ScopedProgram = scope ? Effect.provideService(Program, Scope.Scope, scope.underlying) : Program;
|
|
408
|
+
const fiber = this.#runtime.runFork(ScopedProgram);
|
|
241
409
|
this.#fibers.set(cache_key, fiber);
|
|
242
410
|
queueMicrotask(() => {
|
|
243
411
|
if (!this.#is_current_fiber(cache_key, fiber)) return;
|
|
@@ -255,16 +423,22 @@ var Dispatcher = class Dispatcher {
|
|
|
255
423
|
on_failure: (error) => this.#publish_value_failure(cache_key, fiber, error)
|
|
256
424
|
}));
|
|
257
425
|
}
|
|
258
|
-
#start_promise_fiber(cache_key, options) {
|
|
426
|
+
#start_promise_fiber(cache_key, options, cache_id) {
|
|
259
427
|
const Program = Effect.gen(function* () {
|
|
260
428
|
return yield* Effect.gen(options.factory);
|
|
261
429
|
});
|
|
262
|
-
|
|
430
|
+
/**
|
|
431
|
+
* See #start_value_fiber: the component scope is provided ambiently so
|
|
432
|
+
* scoped acquisition works and finalizers run on unmount.
|
|
433
|
+
*/
|
|
434
|
+
const scope = this.#current_scope;
|
|
435
|
+
const ScopedProgram = scope ? Effect.provideService(Program, Scope.Scope, scope.underlying) : Program;
|
|
436
|
+
const fiber = this.#runtime.runFork(ScopedProgram);
|
|
263
437
|
const ReleaseFiber = Effect.sync(() => {
|
|
264
438
|
if (!this.#is_current_fiber(cache_key, fiber)) return;
|
|
265
439
|
this.#fibers.delete(cache_key);
|
|
266
440
|
this.#promise_values.delete(cache_key);
|
|
267
|
-
if (this.#promise_ids.get(
|
|
441
|
+
if (this.#promise_ids.get(cache_id) === cache_key) this.#promise_ids.delete(cache_id);
|
|
268
442
|
});
|
|
269
443
|
const AwaitFiber = Effect.gen(function* () {
|
|
270
444
|
const exit = yield* Fiber.await(fiber);
|
|
@@ -325,7 +499,36 @@ function reset_dispatcher() {
|
|
|
325
499
|
current_dispatcher?.dispose();
|
|
326
500
|
current_dispatcher = null;
|
|
327
501
|
}
|
|
502
|
+
/**
|
|
503
|
+
* Lazily-created component scope used by generated component code.
|
|
504
|
+
*
|
|
505
|
+
* The holder is created synchronously during component init (before any
|
|
506
|
+
* top-level `await`, where `onDestroy` is not yet available), and the scope
|
|
507
|
+
* itself is materialized on first use. Disposal is registered separately
|
|
508
|
+
* through `onDestroy` during component initialisation, so the scope is
|
|
509
|
+
* reliably closed on unmount.
|
|
510
|
+
*
|
|
511
|
+
* @since 4.1.0
|
|
512
|
+
*/
|
|
513
|
+
var ComponentScopeRef = class {
|
|
514
|
+
#get_dispatcher;
|
|
515
|
+
#scope;
|
|
516
|
+
constructor(get_dispatcher_fn) {
|
|
517
|
+
this.#get_dispatcher = get_dispatcher_fn;
|
|
518
|
+
}
|
|
519
|
+
/** The component scope, creating it on first access. */
|
|
520
|
+
get scope() {
|
|
521
|
+
this.#scope ??= this.#get_dispatcher().begin_scope();
|
|
522
|
+
return this.#scope;
|
|
523
|
+
}
|
|
524
|
+
/** Disposes the scope if it was created. Idempotent. */
|
|
525
|
+
dispose() {
|
|
526
|
+
const scope = this.#scope;
|
|
527
|
+
this.#scope = void 0;
|
|
528
|
+
if (scope && !scope.disposed) this.#get_dispatcher().dispose_scope(scope);
|
|
529
|
+
}
|
|
530
|
+
};
|
|
328
531
|
//#endregion
|
|
329
|
-
export { Code as i,
|
|
532
|
+
export { Code as a, reset_dispatcher as i, Dispatcher as n, ComponentScope as o, get_dispatcher as r, ComponentScopeRef as t };
|
|
330
533
|
|
|
331
|
-
//# sourceMappingURL=dispatcher-
|
|
534
|
+
//# sourceMappingURL=dispatcher-CTWINW5I.js.map
|