{"version":3,"file":"bootstrap.luau","names":[],"sources":["..\\src\\bootstrap.ts"],"sourcesContent":["import {\n\ttype AnySystem,\n\tcreatePackageRegistry,\n\tcreatePackageRuntime,\n\tfindSystems,\n\tstart,\n} from \"@lisachandra/matter\";\nimport type { MatterPackageDescriptor } from \"@lisachandra/matter/packages\";\nimport { RunService } from \"@rbxts/services\";\n\n// ─── Types ───────────────────────────────────────────────────────────────────\n\n/**\n * Options for configuring the Matter ECS bootstrap process.\n *\n * @remarks\n *   Combines pre-resolved systems, auto-collected Flamework barrels, hot-reload containers, and\n *   ad-hoc extensions into a single boundary passed to the Matter loop.\n */\nexport interface BootstrapOptions {\n\t/** `\"development\"` enables Rewire hot reload via the Matter Loop. Defaults to `\"production\"`. */\n\tmode?: \"production\" | \"development\";\n\n\t/**\n\t * Barrel modules (Flamework namespaces) whose `@meta`-annotated systems are auto-collected via\n\t * `findSystems()`.\n\t */\n\tmodules?: {\n\t\tclient?: object;\n\t\tserver?: object;\n\t\tshared?: object;\n\t};\n\n\t/**\n\t * Pre-resolved systems from the pipeline or package registry (Paths A / B / C in the bootstrap\n\t * chain).\n\t */\n\tsystems?: Array<AnySystem>;\n\n\t/**\n\t * Hot reload containers (Rewire `Folder` instances). Only meaningful when `mode ===\n\t * \"development\"`.\n\t */\n\thotReload?: {\n\t\tcontainers?: Array<Instance>;\n\t};\n\n\t/**\n\t * Ad-hoc user extensions — extra systems, modules, or containers merged into the final boundary\n\t * automatically.\n\t */\n\tpackages?: Array<MatterPackageDescriptor>;\n\n\textensions?: {\n\t\tcontainers?: Array<Instance>;\n\t\tmodules?: Array<object>;\n\t\tsystems?: Array<AnySystem>;\n\t};\n}\n\n/**\n * Resolved boundary produced from {@link BootstrapOptions}.\n *\n * @remarks\n *   This is the normalized input that `start()` receives after `resolveBoundary` merges all\n *   configured sources.\n */\nexport interface BootstrapBoundary {\n\tcontainers: Array<Instance>;\n\tmode: \"production\" | \"development\";\n\tsystems: Array<AnySystem>;\n}\n\n/**\n * Return value of {@link bootstrap}, providing access to the Matter world, crate, loop, and the\n * resolved boundary used.\n */\nexport type BootstrapResult = {\n\t/** The resolved boundary used — useful for debugging or reusing. */\n\tboundary: BootstrapBoundary;\n} & ReturnType<typeof start>;\n\nfunction collectSystems(modules: Array<object>): Array<AnySystem> {\n\tconst systems = new Array<AnySystem>();\n\tfor (const container of modules) {\n\t\tfor (const s of findSystems(container, [])) {\n\t\t\tsystems.push(s);\n\t\t}\n\t}\n\n\treturn systems;\n}\n\n/**\n * Merges all configured system/module/container sources into a single {@link BootstrapBoundary}\n * suitable for `start()`.\n *\n * @param options - The bootstrap options specifying mode, modules, systems, hot-reload containers,\n *   and extensions.\n * @returns A resolved boundary with the final system list, mode, and\n * containers.\n */\nexport function resolveBoundary(options: BootstrapOptions = {}): BootstrapBoundary {\n\tconst mode = options.mode ?? \"production\";\n\tconst scope = RunService.IsClient() ? \"client\" : \"server\";\n\n\tconst hotReloadEnabled =\n\t\tRunService.IsStudio() &&\n\t\tmode === \"development\" &&\n\t\t(options.hotReload?.containers?.size() ?? 0) > 0;\n\n\tconst allSystems = new Array<AnySystem>();\n\n\t// 1. Pre-resolved systems (pipeline / packages output)\n\tif (options.systems) {\n\t\tfor (const s of options.systems) {\n\t\t\tallSystems.push(s);\n\t\t}\n\t}\n\n\t// 2. Auto-collected systems from Flamework barrel modules\n\tif (options.modules && !hotReloadEnabled) {\n\t\tif (options.modules.shared) {\n\t\t\tfor (const s of findSystems(options.modules.shared)) {\n\t\t\t\tallSystems.push(s);\n\t\t\t}\n\t\t}\n\n\t\tconst scopeModule = options.modules[scope];\n\t\tif (scopeModule) {\n\t\t\tfor (const s of findSystems(scopeModule)) {\n\t\t\t\tallSystems.push(s);\n\t\t\t}\n\t\t}\n\t}\n\n\t// 3. Extension modules & systems\n\tif (options.extensions) {\n\t\tif (options.extensions.modules) {\n\t\t\tfor (const s of collectSystems(options.extensions.modules)) {\n\t\t\t\tallSystems.push(s);\n\t\t\t}\n\t\t}\n\n\t\tif (options.extensions.systems) {\n\t\t\tfor (const s of options.extensions.systems) {\n\t\t\t\tallSystems.push(s);\n\t\t\t}\n\t\t}\n\t}\n\n\t// 4. Package descriptors (builtin or third-party)\n\tif (options.packages) {\n\t\tconst registry = createPackageRegistry();\n\t\tfor (const pkg of options.packages) {\n\t\t\tregistry.register(pkg);\n\t\t}\n\n\t\tconst allIds = new Array<string>();\n\t\tfor (const [id] of registry.entries()) {\n\t\t\tallIds.push(id);\n\t\t}\n\n\t\tconst resolved = registry.resolve(allIds);\n\t\tconst runtime = createPackageRuntime(resolved as never);\n\t\tfor (const s of runtime.buildSystems()) {\n\t\t\tallSystems.push(s as AnySystem);\n\t\t}\n\t}\n\n\t// Build container list\n\tconst containers = new Array<Instance>();\n\tif (mode === \"development\" && options.hotReload?.containers) {\n\t\tfor (const c of options.hotReload.containers) {\n\t\t\tcontainers.push(c);\n\t\t}\n\t}\n\n\tif (options.extensions?.containers) {\n\t\tfor (const c of options.extensions.containers) {\n\t\t\tcontainers.push(c);\n\t\t}\n\t}\n\n\treturn { containers, mode, systems: allSystems };\n}\n\n/**\n * Single bootstrap entry point — works on both client and server.\n *\n * @example\n * \t```ts\n * \t// Full pipeline path\n * \tconst systems = createPipeline().use(families).build();\n * \tconst { world, crate, loop } = bootstrap({ mode: \"development\", systems });\n * \t```;\n *\n * @example\n * \t```ts\n * \t// Auto-collect from Flamework barrels (no pipeline)\n * \t// Include builtin matter systems via packages\n * \tconst { world, crate } = bootstrap({\n * \tpackages: [builtinPackage],\n * \tmodules: { server: systems, shared: sharedSystems },\n * \t```;\n */\nexport function bootstrap(options: BootstrapOptions = {}): BootstrapResult {\n\tconst boundary = resolveBoundary(options);\n\n\tconst runtime = start({\n\t\tcontainers: boundary.containers,\n\t\tsystems: boundary.systems,\n\t});\n\n\treturn {\n\t\tboundary,\n\t\tcrate: runtime.crate,\n\t\tdebugger: runtime.debugger,\n\t\tloop: runtime.loop,\n\t\tworld: runtime.world,\n\t};\n}\n"],"mappings":";;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA;;;;;;;;;;;;;;;;;;;;;;;;;;AA0EA;AACC;AACA;AACC;AACC;AACD;AACD;AAEA;AACD;;;;;;;;;;;;AAWA;;;;AACC;AACA;AAEA;AAAA;;;;;;;;;;;;;AAGiD;AAHjD;AAKA;;AAGA;AACC;AACC;AACD;AACD;;AAGA;AACC;AACC;AACC;AACD;AACD;AAEA;AACA;AACC;AACC;AACD;AACD;AACD;;AAGA;AACC;AACC;AACC;AACD;AACD;AAEA;AACC;AACC;AACD;AACD;AACD;;AAGA;AACC;AACA;AACC;AACD;AAEA;AACA;AACC;AACD;AAEA;AACA;AACA;AACC;AACD;AACD;;AAGA;AACA;AAAA;;;;;;AAIA;AAJA;AACC;AACC;AACD;AACD;AAEA;AAAA;;AAIA;AAJA;AACC;AACC;AACD;AACD;AAEA;;;;;AACD;;;;;;;;;;;;;;;;;;;;;;AAqBA;;;;AACC;AAEA;;;;AAKA;;;;;;;AAOD","ignoreList":[]}