@notation/factory 0.0.0-stage → 0.1.0

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.
@@ -0,0 +1,2 @@
1
+ /** The modules that an outpost's config can import. Generated by `pnpm build:sdk`. */
2
+ export default {"collect.js":"import { r as collectResourceGraph } from \"./dist-Bwjh3db-.js\";\n// packages/factory/deployer/collect.ts\n/** Runs an outpost's config with `load`, and returns the outpost config that its resources contribute. */\nconst collectOutpost = async (load) => {\n\tconst store = (await collectResourceGraph(async () => {\n\t\tawait load();\n\t})).resources.find((resource) => resource.type === \"factory/deployer/OutpostConfig\");\n\tif (!store) throw new Error(\".factory/config.ts declares no outpost resources\");\n\treturn await store.getParams();\n};\n/** Runs an outpost's config with `load`, and calls the worktree function of the trigger `id` with `event`. */\nconst collectWorktree = async (load, id, event) => {\n\tconst trigger = (await collectResourceGraph(async () => {\n\t\tawait load();\n\t})).resourceGroups.find((group) => group.type === \"factory/Trigger\" && group.id === id);\n\tif (!trigger) throw new Error(`.factory/config.ts declares no trigger ${id}`);\n\tconst worktree = trigger.config.worktree;\n\treturn worktree?.(event);\n};\nexport { collectOutpost, collectWorktree };\n","factory-claude.js":"import { n as ResourceGroup } from \"./dist-Bwjh3db-.js\";\nimport { S as unknown, a as OutpostGroup, b as string, g as picklist, h as parse, m as optional, p as object, v as record } from \"./outpost-6-Dvnk0L.js\";\nimport { readFileSync } from \"node:fs\";\n// packages/claude/implementations/runtime.ts\n/** Claude Code. `setup` installs its CLI, `claude`, in a container's image. Read lazily: an outpost's config, which has no filesystem, never touches it. */\nconst runtime = {\n\tid: \"claude\",\n\tget setup() {\n\t\treturn readFileSync(new URL(\"../runtime/setup.sh\", import.meta.url), \"utf8\");\n\t}\n};\n// packages/claude/implementations/account.ts\n/** The credentials Claude Code runs on. The deployer binds them, and injects them into every container that lists `claude.runtime`, and no other. */\nvar Account = class extends ResourceGroup {\n\truntime = runtime;\n\tsecrets;\n\tconstructor(id, { auth }) {\n\t\tsuper(\"claude/Account\", id, {});\n\t\tthis.secrets = { CLAUDE_CODE_OAUTH_TOKEN: auth };\n\t}\n};\n// packages/claude/implementations/agent.ts\nconst agentConfig = object({\n\tmodel: string(),\n\teffort: optional(picklist([\n\t\t\"low\",\n\t\t\"medium\",\n\t\t\"high\",\n\t\t\"xhigh\",\n\t\t\"max\"\n\t])),\n\t/** Relative to `.factory/`. Appended to the runner's prompt. */\n\tsystemPrompt: optional(string()),\n\t/** Merged into `/data/agents/<id>/settings.json`. */\n\tsettings: optional(record(string(), unknown())),\n\t/** `~/.claude/*` is written to `/data/agents/<id>/`, other `~/*` to `/data/home/`. */\n\tfiles: optional(record(string(), string()))\n});\n/** A Claude Code agent. A trigger that runs it must target a container that lists `claude.runtime`. */\nvar Agent = class extends OutpostGroup {\n\truntime = runtime;\n\tconstructor(id, config) {\n\t\tconst settings = parse(agentConfig, config);\n\t\tsuper(\"claude/Agent\", id, config);\n\t\tthis.outpost.store.contribute({ agents: { [id]: {\n\t\t\truntime: runtime.id,\n\t\t\t...settings\n\t\t} } });\n\t}\n};\nexport { Account, Agent, runtime };\n","factory-droid.js":"import { n as ResourceGroup } from \"./dist-Bwjh3db-.js\";\nimport { S as unknown, a as OutpostGroup, b as string, g as picklist, h as parse, m as optional, p as object, v as record } from \"./outpost-6-Dvnk0L.js\";\nimport { readFileSync } from \"node:fs\";\n// packages/droid/implementations/runtime.ts\n/** Droid, Factory's agent. `setup` installs its CLI, `droid`, in a container's image. Read lazily: an outpost's config, which has no filesystem, never touches it. */\nconst runtime = {\n\tid: \"droid\",\n\tget setup() {\n\t\treturn readFileSync(new URL(\"../runtime/setup.sh\", import.meta.url), \"utf8\");\n\t}\n};\n// packages/droid/implementations/account.ts\n/** The credentials Droid runs on. The deployer binds them, and injects them into every container that lists `droid.runtime`, and no other. */\nvar Account = class extends ResourceGroup {\n\truntime = runtime;\n\tsecrets;\n\tconstructor(id, { auth }) {\n\t\tsuper(\"droid/Account\", id, {});\n\t\tthis.secrets = { FACTORY_API_KEY: auth };\n\t}\n};\n// packages/droid/implementations/agent.ts\nconst agentConfig = object({\n\tmodel: string(),\n\t/** Passed as `--reasoning-effort`. The levels a model accepts depend on the model. */\n\teffort: optional(picklist([\n\t\t\"none\",\n\t\t\"low\",\n\t\t\"medium\",\n\t\t\"high\"\n\t])),\n\t/**\n\t* Passed as `--auto`. Without it, a run skips every permission prompt\n\t* with `--skip-permissions-unsafe`, which only a disposable container\n\t* should use.\n\t*/\n\tautonomy: optional(picklist([\n\t\t\"low\",\n\t\t\"medium\",\n\t\t\"high\"\n\t])),\n\t/** Relative to `.factory/`. Appended to the runner's prompt. */\n\tsystemPrompt: optional(string()),\n\t/** Written to `/data/agents/<id>/settings.json`, and merged for each run. */\n\tsettings: optional(record(string(), unknown())),\n\t/** `~/.factory/*` is written to `/data/agents/<id>/`, other `~/*` to `/data/home/`. */\n\tfiles: optional(record(string(), string()))\n});\n/** A Droid agent. A trigger that runs it must target a container that lists `droid.runtime`. */\nvar Agent = class extends OutpostGroup {\n\truntime = runtime;\n\tconstructor(id, config) {\n\t\tconst settings = parse(agentConfig, config);\n\t\tsuper(\"droid/Agent\", id, config);\n\t\tthis.outpost.store.contribute({ agents: { [id]: {\n\t\t\truntime: runtime.id,\n\t\t\t...settings\n\t\t} } });\n\t}\n};\nexport { Account, Agent, runtime };\n","factory-github.js":"import { n as ResourceGroup } from \"./dist-Bwjh3db-.js\";\nimport { C as variant, a as OutpostGroup, b as string, d as array, f as literal, g as picklist, h as parse, m as optional, p as object, u as channelConfig, x as union } from \"./outpost-6-Dvnk0L.js\";\n// packages/github/implementations/selectors.ts\n/** Who may start a run. Data, so the router can check it when a delivery arrives. */\nconst authorSet = variant(\"kind\", [\n\tobject({ kind: literal(\"collaborators\") }),\n\tobject({\n\t\tkind: literal(\"team\"),\n\t\tslug: string()\n\t}),\n\tobject({\n\t\tkind: literal(\"user\"),\n\t\tlogin: string()\n\t})\n]);\n/** Users with write access to the repo. */\nconst collaborators = () => ({ kind: \"collaborators\" });\n/** Members of a team, e.g. `\"acme/core\"`. */\nconst team = (slug) => ({\n\tkind: \"team\",\n\tslug\n});\n/** One user, by login. */\nconst user = (login) => ({\n\tkind: \"user\",\n\tlogin\n});\n/** Required: nothing is trusted by default. */\nconst from = union([authorSet, array(authorSet)]);\nconst issueSelector = object({\n\tactions: optional(array(picklist([\n\t\t\"opened\",\n\t\t\"edited\",\n\t\t\"reopened\",\n\t\t\"labeled\"\n\t])), [\"opened\"]),\n\tmention: optional(string()),\n\tlabels: optional(array(string())),\n\tfrom\n});\nconst issueCommentSelector = object({\n\tactions: optional(array(picklist([\"created\", \"edited\"])), [\"created\"]),\n\tmention: optional(string()),\n\tlabels: optional(array(string())),\n\tfrom\n});\n// packages/github/implementations/channel.ts\n/**\n* A repo's issues on a GitHub connection, made by `connection.channel(...)`.\n* Its grant is the App's installation on the repo. Its selectors are data the\n* router matches; a conversation is an issue.\n*/\nvar Channel = class extends OutpostGroup {\n\t/** Unset means the outpost's repo. */\n\tscope;\n\tconnection;\n\tconstructor(id, { connection, ...config }) {\n\t\tsuper(\"github/Channel\", id, config);\n\t\tconst { outpost } = this;\n\t\tconst { scope } = parse(channelConfig, config);\n\t\tthis.scope = scope;\n\t\tthis.connection = connection;\n\t\toutpost.store.contribute({ channels: { [id]: {\n\t\t\tprovider: \"github\",\n\t\t\tconnection: this.connection.name,\n\t\t\t...scope ? { scope } : {}\n\t\t} } });\n\t}\n\t/** Issue events. `actions` defaults to `[\"opened\"]`. */\n\tissue(opts) {\n\t\treturn {\n\t\t\tchannel: this,\n\t\t\tevent: \"issues\",\n\t\t\tmatch: parse(issueSelector, opts)\n\t\t};\n\t}\n\t/** Comments on issues and pull requests. `actions` defaults to `[\"created\"]`; with `\"edited\"`, only edits that newly add `mention` match. */\n\tissueComment(opts) {\n\t\treturn {\n\t\t\tchannel: this,\n\t\t\tevent: \"issue_comment\",\n\t\t\tmatch: parse(issueCommentSelector, opts)\n\t\t};\n\t}\n};\n// packages/github/implementations/connection-ref.ts\n/** In an outpost: a GitHub connection the infra declares, from `github.Connection.get(name)`. */\nvar ConnectionRef = class extends ResourceGroup {\n\tname;\n\tconstructor(id, config) {\n\t\tsuper(\"github/ConnectionRef\", id, config);\n\t\tthis.name = config.name;\n\t}\n\t/** A repo's issues. `scope` defaults to the outpost's repo. */\n\tchannel({ id, ...config }) {\n\t\treturn new Channel(id, {\n\t\t\t...config,\n\t\t\tconnection: this\n\t\t});\n\t}\n};\n// packages/github/implementations/policy.ts\nconst level = optional(picklist([\"read\", \"write\"]));\nconst policyConfig = object({\n\trepo: optional(string()),\n\tpermissions: object({\n\t\tactions: level,\n\t\tactions_variables: level,\n\t\tchecks: level,\n\t\tcontents: level,\n\t\tissues: level,\n\t\tmetadata: level,\n\t\tpull_requests: level,\n\t\tstatuses: level,\n\t\tworkflows: level\n\t})\n});\n/** A 1-hour installation token for `repo` (default: the outpost's repo), with `permissions`, minted by the code host before each run. */\nvar Policy = class extends OutpostGroup {\n\tprovider = \"github\";\n\tconstructor(id, config) {\n\t\tsuper(\"github/Policy\", id, config);\n\t\tconst { outpost } = this;\n\t\tconst { repo, permissions } = parse(policyConfig, config);\n\t\toutpost.store.contribute({ policies: { [id]: {\n\t\t\tprovider: \"github\",\n\t\t\t...repo ? { repo } : {},\n\t\t\tpermissions\n\t\t} } });\n\t}\n};\n// packages/github/implementations/outpost.ts\n/** In an outpost, `Connection` only has `get`: the connection itself is the hub's. */\nconst Connection = { \n/** The connection the infra declares as `name`. */\nget: (name) => new ConnectionRef(name, { name }) };\nexport { Connection, Policy, collaborators, team, user };\n","factory-slack.js":"import { i as defineResource, l as text, n as ResourceGroup } from \"./dist-Bwjh3db-.js\";\nimport { C as variant, _ as pipe, a as OutpostGroup, b as string, d as array, f as literal, h as parse, p as object, s as scopedName, x as union, y as startsWith } from \"./outpost-6-Dvnk0L.js\";\nnew TextEncoder();\n// packages/factory/router/handle.ts\n/** The path that a connection's platform delivers to. `key` is the connection's key, such as `github/gh`. */\nconst webhookPath = (key) => `/webhook/${key}`;\n// packages/slack/lib/app.ts\n/** The Slack calls an app makes. Stubs. */\nconst createApp = async (_params) => {\n\tthrow new Error(\"not implemented: create the app from a manifest, in the browser, and install it to the workspace\");\n};\nconst readApp = async (_key) => {\n\tthrow new Error(\"not implemented: read the app's manifest\");\n};\nconst setRequestUrl = async (_key, _requestUrl) => {\n\tthrow new Error(\"not implemented: set the app's Events API request URL\");\n};\n// packages/slack/resources/app.ts\nconst App = defineResource({\n\ttype: \"slack/apps/App\",\n\tprovider: \"@notation/factory-slack\"\n}).defineSchema({\n\tname: {\n\t\tpropertyType: \"param\",\n\t\tpresence: \"required\",\n\t\timmutable: true,\n\t\tvalue: string()\n\t},\n\tworkspace: {\n\t\tpropertyType: \"param\",\n\t\tpresence: \"required\",\n\t\timmutable: true,\n\t\tvalue: string()\n\t},\n\trequestUrl: {\n\t\tpropertyType: \"param\",\n\t\tpresence: \"required\",\n\t\tvalue: string()\n\t},\n\tappId: {\n\t\tpropertyType: \"computed\",\n\t\tpresence: \"required\",\n\t\tprimaryKey: true,\n\t\tvalue: string()\n\t},\n\t/** The bot token, which installing the app to the workspace issues. */\n\tbotToken: {\n\t\tpropertyType: \"credential\",\n\t\tvalue: string()\n\t},\n\t/** The secret that Slack signs the app's requests with. */\n\tsigningSecret: {\n\t\tpropertyType: \"credential\",\n\t\tvalue: string()\n\t}\n}).defineOperations({\n\tcreate: async (params) => createApp(params),\n\trotateManually: {\n\t\tbotToken: \"Copy the Bot User OAuth Token from the app's OAuth & Permissions page.\",\n\t\tsigningSecret: \"Regenerate the Signing Secret on the app's Basic Information page.\"\n\t},\n\tread: async (key) => readApp(key),\n\tupdate: async (key, _patch, params) => setRequestUrl(key, params.requestUrl),\n\tdelete: async () => {\n\t\tthrow new Error(\"The Slack app is protected: delete it on its settings page\");\n\t}\n});\n// packages/slack/implementations/selectors.ts\n/** Who may start a run. Data, so the router can check it when an event arrives. */\nconst authorSet = variant(\"kind\", [object({\n\tkind: literal(\"group\"),\n\thandle: string()\n}), object({\n\tkind: literal(\"user\"),\n\temail: string()\n})]);\n/** Members of a Slack user group, by handle. */\nconst group = (handle) => ({\n\tkind: \"group\",\n\thandle\n});\n/** One user, by email. */\nconst user = (email) => ({\n\tkind: \"user\",\n\temail\n});\nconst mentionOptions = object({ from: union([authorSet, array(authorSet)]) });\n// packages/slack/implementations/channel.ts\n/** A Slack channel needs naming: there's no default. */\nconst channelConfig = object({ scope: pipe(string(), startsWith(\"#\")) });\n/**\n* One Slack channel on a Slack connection, made by `connection.channel(...)`.\n* Its grant is the bot's membership: `/invite @<app>` in the channel. A\n* conversation is a thread.\n*/\nvar Channel = class extends OutpostGroup {\n\tscope;\n\tconnection;\n\tconstructor(id, { connection, ...config }) {\n\t\tconst { scope } = parse(channelConfig, config);\n\t\tsuper(\"slack/Channel\", id, config);\n\t\tthis.scope = scope;\n\t\tthis.connection = connection;\n\t\tthis.outpost.store.contribute({ channels: { [id]: {\n\t\t\tprovider: \"slack\",\n\t\t\tconnection: this.connection.name,\n\t\t\tscope\n\t\t} } });\n\t}\n\t/** Messages that mention `name`, e.g. `\"@claude\"`. */\n\tmention(name, opts) {\n\t\treturn {\n\t\t\tchannel: this,\n\t\t\tevent: \"app_mention\",\n\t\t\tmatch: {\n\t\t\t\tmention: name,\n\t\t\t\t...parse(mentionOptions, opts)\n\t\t\t}\n\t\t};\n\t}\n};\n// packages/slack/implementations/connection-ref.ts\n/** In an outpost: a Slack connection the infra declares, from `slack.Connection.get(name)`. */\nvar ConnectionRef = class extends ResourceGroup {\n\tname;\n\tconstructor(id, config) {\n\t\tsuper(\"slack/ConnectionRef\", id, config);\n\t\tthis.name = config.name;\n\t}\n\t/** One Slack channel: `scope` is its name, e.g. `\"#ops\"`. */\n\tchannel({ id, ...config }) {\n\t\treturn new Channel(id, {\n\t\t\t...config,\n\t\t\tconnection: this\n\t\t});\n\t}\n};\n// packages/slack/implementations/connection.ts\n/** Slack app names are at most 35 characters. */\nconst SLACK_APP_NAME_MAX_LENGTH = 35;\nconst connectionConfig = object({ \n/** The Slack workspace the app is installed in. */\nworkspace: string() });\n/**\n* `new slack.Connection(...)`: Notation Factory on Slack, as one app whose events go\n* to the router. Its bot token and signing secret go from the app to the\n* router's vault in memory. Slack is a channel only:\n* code still lives on the code host.\n*/\nvar Connection = class extends ResourceGroup {\n\tname;\n\trouter;\n\tapp;\n\tconstructor(id, { router, ...config }) {\n\t\tconst { workspace } = parse(connectionConfig, config);\n\t\tsuper(\"slack/Connection\", id, config);\n\t\tthis.name = id;\n\t\tthis.router = router;\n\t\tconst key = `slack/${id}`;\n\t\tthis.app = this.add(new App(`${id}-app`, { config: {\n\t\t\tname: scopedName(id, SLACK_APP_NAME_MAX_LENGTH),\n\t\t\tworkspace,\n\t\t\trequestUrl: text`${router.url}${webhookPath(key)}`\n\t\t} }));\n\t\tconst botToken = this.router.bind(this.router.vault.secret({\n\t\t\tid: `${id}-bot-token`,\n\t\t\tvalue: this.app.credentials.botToken\n\t\t}));\n\t\tconst signingSecret = this.router.bind(this.router.vault.secret({\n\t\t\tid: `${id}-signing-secret`,\n\t\t\tvalue: this.app.credentials.signingSecret\n\t\t}));\n\t\tthis.router.store.contribute({ connections: { [key]: {\n\t\t\tprovider: \"slack\",\n\t\t\tsource: this.app.outputRef(\"appId\"),\n\t\t\tcredentials: {\n\t\t\t\tbotToken,\n\t\t\t\tsigningSecret\n\t\t\t}\n\t\t} } });\n\t}\n\t/** In an outpost: the connection the infra declares as `name`. */\n\tstatic get(name) {\n\t\treturn new ConnectionRef(name, { name });\n\t}\n};\nexport { Connection, group, user };\n","factory.js":"export { r as Container, i as Outpost, o as OutpostConfig, a as OutpostGroup, n as Policy, t as Trigger, c as bindingName, u as channelConfig, s as scopedName, l as single } from \"./outpost-6-Dvnk0L.js\";\n","dist-Bwjh3db-.js":"// node_modules/.pnpm/@notation+utils@0.28.0/node_modules/@notation/utils/dist/index.js\n/**\n* JSON with the keys of every object sorted, so equal maps always encode to\n* the same string. Arrays keep their order. Like `JSON.stringify`, it drops\n* an `undefined` property and calls `toJSON`.\n*/\nconst sortedJson = {\n\tencode(value) {\n\t\treturn JSON.stringify(value, (_key, entry) => sortKeys(entry)) ?? \"null\";\n\t},\n\tdecode(text) {\n\t\treturn JSON.parse(text);\n\t}\n};\nfunction sortKeys(value) {\n\tif (value === null || typeof value !== \"object\" || Array.isArray(value)) return value;\n\tconst sorted = {};\n\tfor (const key of Object.keys(value).sort()) sorted[key] = value[key];\n\treturn sorted;\n}\n// node_modules/.pnpm/@notation+resource@0.28.0/node_modules/@notation/resource/dist/index.js\n/**\n* Stands in for a param whose value is known only once a dependency has been\n* applied. Compared structurally, so it survives a JSON round trip.\n*/\nconst UNKNOWN_AFTER_APPLY = { $unknown: \"after-apply\" };\nfunction isUnknownAfterApply(value) {\n\treturn value !== null && typeof value === \"object\" && value.$unknown === UNKNOWN_AFTER_APPLY.$unknown;\n}\n/**\n* Keeps the params that take part in a comparison: `param` items that are\n* neither volatile nor hidden. An `undefined` value counts as absent: state\n* is stored as JSON, which drops it, so keeping it would make an unset\n* optional param look changed on every deploy.\n*/\nfunction toComparableParams(schema, values) {\n\tconst comparable = {};\n\tfor (const [key, item] of Object.entries(schema)) {\n\t\tif (!isComparable(item)) continue;\n\t\tif (values[key] !== void 0) comparable[key] = values[key];\n\t}\n\treturn comparable;\n}\nfunction isComparable(item) {\n\treturn item.propertyType === \"param\" && !item.volatile && !item.hidden;\n}\nconst HASH_LENGTH = 8;\nfunction fnv1a(text) {\n\tlet hash = 2166136261;\n\tfor (let i = 0; i < text.length; i++) {\n\t\thash ^= text.charCodeAt(i);\n\t\thash = Math.imul(hash, 16777619);\n\t}\n\treturn (hash >>> 0).toString(16).padStart(HASH_LENGTH, \"0\");\n}\n/**\n* Makes the physical name of a resource: `<app>--<stage>--<name>`, or `name`\n* when there is no scope. App and stage names cannot contain `--`, so the\n* first `--` ends the app and the second ends the stage. Two scopes therefore\n* never produce the same name.\n*\n* When the result is longer than `rule.maxLength`, it is cut short and ends\n* in `-` and the 8 hex characters of the FNV-1a hash of the full name, so\n* shortened names stay unique and the same on every deploy.\n*/\nfunction physicalName(scope, name, rule) {\n\tconst full = scope ? `${scope.app}--${scope.stage}--${name}` : name;\n\tif (full.length <= rule.maxLength) return full;\n\tconst hash = fnv1a(full);\n\tconst room = rule.maxLength - HASH_LENGTH - 1;\n\tif (room < 1) throw new Error(`A maximum length of ${rule.maxLength} leaves no room for a shortened name`);\n\treturn `${full.slice(0, room).replace(/[-_.]+$/, \"\")}-${hash}`;\n}\nfunction ownPhysicalName(field) {\n\treturn { \"~physicalName\": field };\n}\nfunction isOwnPhysicalName(value) {\n\treturn isPlainObject(value) && Object.keys(value).length === 1 && typeof value[\"~physicalName\"] === \"string\";\n}\nfunction isCredentialMarker(value) {\n\tif (!isPlainObject(value)) return false;\n\tconst marker = value.$credential;\n\treturn isPlainObject(marker) && typeof marker.resource === \"string\" && typeof marker.name === \"string\";\n}\nconst loadedKey = Symbol.for(\"@notation/resource/loaded\");\n/**\n* Records that the copy of this package at `url` is loaded, and throws if\n* another copy is. Each copy has its own collection, so resources made\n* through a second copy would be missing from the graph.\n*/\nfunction claimSingleCopy(url) {\n\tconst registry = globalThis;\n\tconst loaded = registry[loadedKey];\n\tif (loaded === void 0) registry[loadedKey] = url;\n\telse if (loaded !== url) throw new Error(`Two versions of @notation/resource were detected at ${loaded} and ${url}. Please install one version (for example with npm dedupe).`);\n}\nclaimSingleCopy(import.meta.url);\nlet activeCollection;\n/**\n* Evaluates infra and returns the resources it made. Once `evaluate` is\n* done, the callbacks registered with `onEvaluationEnd` run in the order they\n* were registered, and then contributions close.\n*\n* `opts.scope` names the deployment's app and stage, which scope the\n* physical names of the resources that `evaluate` declares.\n*/\nasync function collectResourceGraph(evaluate, opts = {}) {\n\tif (activeCollection) throw new Error(\"A resource graph is already being collected.\");\n\tconst collection = {\n\t\tgraph: {\n\t\t\tresourceGroups: [],\n\t\t\tresources: []\n\t\t},\n\t\tclosed: false,\n\t\tevaluationEnded: false,\n\t\tendOfEvaluation: [],\n\t\tpendingValidations: [],\n\t\tdeclarationChecks: opts.declarationChecks ?? true,\n\t\tscope: opts.scope,\n\t\tstores: /* @__PURE__ */ new Map()\n\t};\n\tactiveCollection = collection;\n\ttry {\n\t\tawait evaluate();\n\t\tcollection.evaluationEnded = true;\n\t\twhile (collection.endOfEvaluation.length > 0) await collection.endOfEvaluation.shift()();\n\t\tawait Promise.all(collection.pendingValidations);\n\t\treturn collection.graph;\n\t} finally {\n\t\tcollection.closed = true;\n\t\tactiveCollection = void 0;\n\t}\n}\nfunction getActiveResourceCollection() {\n\treturn activeCollection;\n}\nvar OutputRefStringError = class extends Error {\n\t/**\n\t* @param subject Names the value, such as `Output orders.QueueArn`.\n\t* @param noun What the value is, such as `an output ref`.\n\t*/\n\tconstructor(subject, noun = \"an output ref\") {\n\t\tsuper(`${subject}: ${noun} can't be turned into a string. Place it whole, join it with text\\`…\\`, or compute with it in map().`);\n\t\tthis.name = \"OutputRefStringError\";\n\t}\n};\nconst outputRefBrand = Symbol.for(\"@notation/resource/OutputRef\");\nconst derivedBrand = Symbol.for(\"@notation/resource/Derived\");\nvar Unstringable = class {\n\t[Symbol.toPrimitive]() {\n\t\tthrow this.stringError();\n\t}\n\ttoString() {\n\t\tthrow this.stringError();\n\t}\n\ttoJSON() {\n\t\tthrow this.stringError();\n\t}\n};\nvar RefBase = class RefBase extends Unstringable {\n\tresourceId;\n\tpath;\n\tkind;\n\t[outputRefBrand] = true;\n\tconstructor(resourceId, path, kind) {\n\t\tsuper();\n\t\tthis.resourceId = resourceId;\n\t\tthis.path = path;\n\t\tthis.kind = kind;\n\t}\n\tmap(fn) {\n\t\tconst callSite = captureCallSiteLazily(RefBase.prototype.map, { skipLibraryFrames: true });\n\t\tassertDerivable(this, () => `map() at ${site(callSite)}`);\n\t\treturn mapDerived(this, fn, callSite);\n\t}\n\tstringError() {\n\t\treturn new OutputRefStringError(`Output ${describeOutputRef(this)}`);\n\t}\n};\nvar OutputRefClass = class extends RefBase {\n\tresource;\n\tconstructor(resource, path, kind = \"output\") {\n\t\tsuper(resource.id, path, kind);\n\t\tthis.resource = resource;\n\t}\n};\n/**\n* The class of every ref. `kind` tells an output, a credential and a\n* `~state` ref apart, without reading the resource.\n*/\nconst OutputRef = OutputRefClass;\n/**\n* Makes a `~state` ref. Throws unless only a replace changes the output: a\n* param that is `immutable`, `primaryKey` or `secondaryKey`, or that has\n* `physicalName`. An output that an update changes would be read one\n* deploy late, with no error. Also throws for a `hidden` param, which the\n* state record does not hold, so the ref would always resolve to undefined.\n*/\nfunction stateOutputRef(resource, key) {\n\tconst item = resource.schema[key];\n\tif (item?.propertyType === \"param\" && item.hidden) throw new Error(`Cannot read ${key} of ${resource.id} from state: it is a hidden param, which the state record does not hold`);\n\tif (!(item?.propertyType === \"param\" && (item.immutable || item.primaryKey || item.secondaryKey || item.physicalName))) throw new Error(`Cannot read ${key} of ${resource.id} from state: ~state can read only an output that only a replace changes, which is a param that is immutable, primaryKey or secondaryKey, or that has physicalName`);\n\treturn new OutputRef(resource, [key], \"state\");\n}\n/**\n* Finds `~state` refs in `recorded`. A ref whose target has no record\n* resolves to undefined.\n*/\nfunction recordedLookup(recorded) {\n\treturn (token) => {\n\t\tconst id = token.resourceId;\n\t\tif (!recorded || !(id in recorded)) throw new Error(`Output ${describeOutputRef(token)} is read from state, but the outputs in state were not read for ${id}. Make each ~state ref while infra is evaluated.`);\n\t\treturn {\n\t\t\tknown: true,\n\t\t\tvalue: readPath(recorded[id], token.path)\n\t\t};\n\t};\n}\n/**\n* Whether a ref is from `owner` to its own `physicalName` param. Deploy\n* fills such a ref in when it fills in the name, so it is no dependency.\n*/\nfunction isOwnNameRef(owner, token) {\n\tif (token.resourceId !== owner.id || token.path.length !== 1) return false;\n\tif (token.resource !== owner) return false;\n\tconst item = owner.schema[token.path[0]];\n\treturn item?.propertyType === \"param\" && Boolean(item.physicalName);\n}\n/** Whether the holder of `token` depends on the resource it names. */\nfunction isDependencyRef(holder, token) {\n\treturn !isStateRef(token) && !isOwnNameRef(holder, token);\n}\nfunction isOutputRef(value) {\n\treturn typeof value === \"object\" && value !== null && value[outputRefBrand] === true;\n}\nfunction isCredentialRef(value) {\n\treturn isOutputRef(value) && value.kind === \"credential\";\n}\nfunction isStateRef(value) {\n\treturn isOutputRef(value) && value.kind === \"state\";\n}\nfunction isPlainObject(value) {\n\tif (value === null || typeof value !== \"object\") return false;\n\tconst prototype = Object.getPrototypeOf(value);\n\treturn prototype === Object.prototype || prototype === null;\n}\nfunction isDerived(value) {\n\treturn typeof value === \"object\" && value !== null && value[derivedBrand] === true;\n}\n/**\n* Walks a value and calls `visit` for every output ref in it, including\n* each ref that a derived value reads.\n*/\nfunction forEachOutputRef(value, visit) {\n\tif (isOutputRef(value)) return visit(value);\n\tif (isDerived(value)) {\n\t\tfor (const input of value[\"~inputs\"]) forEachOutputRef(input, visit);\n\t\treturn;\n\t}\n\tif (Array.isArray(value)) {\n\t\tfor (const entry of value) forEachOutputRef(entry, visit);\n\t\treturn;\n\t}\n\tif (isPlainObject(value)) for (const entry of Object.values(value)) forEachOutputRef(entry, visit);\n}\n/**\n* Whether a value holds an output ref. A derived value that reads no ref is\n* not found.\n*/\nfunction containsOutputRef(value) {\n\tlet found = false;\n\tforEachOutputRef(value, () => {\n\t\tfound = true;\n\t});\n\treturn found;\n}\nconst isRefOrDerived = (value) => isOutputRef(value) || isDerived(value);\n/** Whether a value holds an output ref or a derived value. */\nfunction containsRefOrDerived(value) {\n\treturn containsMatch(value, isRefOrDerived);\n}\nfunction containsMatch(value, matches) {\n\tif (matches(value)) return true;\n\treturn (Array.isArray(value) ? value : isPlainObject(value) ? Object.values(value) : []).some((entry) => containsMatch(entry, matches));\n}\n/**\n* Copies a value, replacing every output ref in it with the result of\n* `onToken`, and every derived value with the result of `onDerived`.\n*/\nfunction mapRefs(value, onToken, onDerived) {\n\tif (isOutputRef(value)) return onToken(value);\n\tif (isDerived(value)) return onDerived(value);\n\tif (Array.isArray(value)) return value.map((entry) => mapRefs(entry, onToken, onDerived));\n\tif (isPlainObject(value)) {\n\t\tconst mapped = {};\n\t\tfor (const [key, entry] of Object.entries(value)) mapped[key] = mapRefs(entry, onToken, onDerived);\n\t\treturn mapped;\n\t}\n\treturn value;\n}\n/**\n* Replaces every output ref that `lookup` knows with its value, and computes\n* every derived value whose refs `lookup` knows. Refs and derived values\n* that `lookup` does not know are left in place.\n*/\nfunction resolveOutputRefs(value, lookup) {\n\treturn mapRefs(value, (token) => {\n\t\tconst found = lookup(token);\n\t\treturn found.known ? found.value : token;\n\t}, (derived) => {\n\t\tconst found = resolveDerived(derived, lookup);\n\t\treturn found.known ? found.value : derived;\n\t});\n}\n/**\n* Finds output refs in the resource's output. The output must exist: a\n* resource holding an output ref depends on the resource it came from, so\n* that resource has been deployed first.\n*/\nconst deployLookup = (token) => {\n\tconst output = token.resource.output;\n\tif (output == null) throw new Error(`Output ${describeOutputRef(token)} was read before ${token.resource.id} was deployed`);\n\treturn {\n\t\tknown: true,\n\t\tvalue: readPath(output, token.path)\n\t};\n};\n/**\n* Finds output refs in the resource's output when it has one, such as the\n* output a plan reads from state, and leaves the rest unknown. A required\n* output that the output lacks is unknown too.\n*/\nconst planLookup = (token) => {\n\tconst output = token.resource.output;\n\tif (output == null) return { known: false };\n\tif (isMissingRequiredOutput(token.resource.schema, output, token.path[0])) return { known: false };\n\treturn {\n\t\tknown: true,\n\t\tvalue: readPath(output, token.path)\n\t};\n};\n/**\n* The outputs that the resource's schema requires and `output` lacks. A state\n* record written before an output was added to the resource's type lacks it,\n* and deploy reads the resource again to fill it in.\n*/\nfunction missingRequiredOutputs(resource, output) {\n\treturn Object.keys(resource.schema).filter((key) => isMissingRequiredOutput(resource.schema, output, key));\n}\nfunction isMissingRequiredOutput(schema, output, key) {\n\tconst item = schema[key];\n\treturn item?.propertyType === \"computed\" && item.presence === \"required\" && output[key] === void 0;\n}\nfunction readPath(output, path) {\n\tlet value = output;\n\tfor (const key of path) {\n\t\tif (value === null || value === void 0) return void 0;\n\t\tvalue = value[key];\n\t}\n\treturn value;\n}\n/**\n* Replaces every output ref and derived value with `UNKNOWN_AFTER_APPLY`, at\n* its own path.\n*/\nfunction markUnknownOutputRefs(value) {\n\treturn mapRefs(value, () => UNKNOWN_AFTER_APPLY, () => UNKNOWN_AFTER_APPLY);\n}\n/**\n* Writes output refs and derived values in a form that depends only on the\n* resource ID and path of each ref, and the call site of each function, so\n* contributions sort the same whatever order code ran in, and conflict\n* messages can show them.\n*/\nfunction toCanonicalOutputRefs(value) {\n\treturn mapRefs(value, (token) => `<output ${describeOutputRef(token)}>`, (derived) => derived[\"~describe\"]());\n}\nfunction describeOutputRef(token) {\n\treturn [token.resourceId, ...token.path].join(\".\");\n}\n/**\n* Thrown by a plan view when code reads an output that is not known yet: the\n* output of a dependency that has none, a required output that is missing\n* from a dependency's output, or a value in config that a ref or a derived\n* value gives.\n*/\nvar PendingOutput = class extends Error {\n\tresource;\n\tconstructor(resource, message = `The output of ${resource.id} is not known until it is deployed`) {\n\t\tsuper(message);\n\t\tthis.resource = resource;\n\t\tthis.name = \"PendingOutput\";\n\t}\n};\n/**\n* Gives views of dependencies for code that runs at plan, and the `pending`\n* function for `deriveParamsConfigView`. A view of a dependency has a view of\n* its config from `deriveParamsConfigView`, in which the refs and derived\n* values that plan knows are filled in, and reading one that it doesn't know\n* throws `PendingOutput`. A view of a dependency with no output\n* throws `PendingOutput` when its output is read. A view of a dependency\n* whose output lacks a required output throws it when that output is read.\n* `readPending` is set by such a read, so a plan still knows of it when the\n* code catches the error. A view's methods run on the dependency, so its\n* `outputRef` names the dependency, not the view. Plan resolves refs after\n* the code has returned, outside `tryAtPlan`, so a ref that named the view\n* would throw `PendingOutput` there instead of planning as unknown.\n*/\nfunction createPlanViews() {\n\tconst views = {\n\t\treadPending: false,\n\t\tof(deps) {\n\t\t\tconst viewed = {};\n\t\t\tfor (const [name, dep] of Object.entries(deps)) viewed[name] = dep && planView(dep);\n\t\t\treturn viewed;\n\t\t},\n\t\t/**\n\t\t* Throws `PendingOutput` for the first resource that `unresolved` reads.\n\t\t* `UNKNOWN_AFTER_APPLY` reads no ref, so its error names the resource\n\t\t* whose config holds it.\n\t\t*/\n\t\tpending(unresolved, holder, param) {\n\t\t\tlet resource;\n\t\t\tforEachOutputRef(unresolved, (token) => {\n\t\t\t\tresource ??= token.resource;\n\t\t\t});\n\t\t\tviews.readPending = true;\n\t\t\tthrow resource ? new PendingOutput(resource) : new PendingOutput(holder, `${param} is not known until deploy`);\n\t\t}\n\t};\n\tconst throwPending = (dep) => {\n\t\tviews.readPending = true;\n\t\tthrow new PendingOutput(dep);\n\t};\n\tconst planOutput = (dep) => {\n\t\tconst output = dep.output;\n\t\tif (output == null) return throwPending(dep);\n\t\tconst missing = missingRequiredOutputs(dep, output);\n\t\tif (missing.length === 0) return output;\n\t\treturn Object.defineProperties({ ...output }, Object.fromEntries(missing.map((key) => [key, {\n\t\t\tenumerable: true,\n\t\t\tget: () => throwPending(dep)\n\t\t}])));\n\t};\n\tconst planView = (dep) => dependencyView(dep, {\n\t\toutput: () => planOutput(dep),\n\t\tconfig: () => deriveParamsConfigView(dep, resolveOutputRefs(dep.config, planLookup), views.pending)\n\t});\n\treturn views;\n}\n/**\n* Views of dependencies for `deriveParams` and function contributions at\n* deploy, each with its config filled in. The config is a view from\n* `deriveParamsConfigView`.\n*/\nfunction deployViews(deps) {\n\tconst viewed = {};\n\tfor (const [name, dep] of Object.entries(deps)) viewed[name] = dep && dependencyView(dep, { config: () => deriveParamsConfigView(dep, resolveOutputRefs(dep.config, deployLookup)) });\n\treturn viewed;\n}\nfunction dependencyView(dep, replaced) {\n\tconst view = {\n\t\toutputRef: { value: dep.outputRef.bind(dep) },\n\t\tcredentials: { get: () => dep.credentials },\n\t\t\"~state\": { get: () => dep[\"~state\"] }\n\t};\n\tfor (const key of [\"output\", \"config\"]) {\n\t\tconst make = replaced[key];\n\t\tif (!make) continue;\n\t\tlet made;\n\t\tview[key] = { get: () => (made ??= { value: make() }).value };\n\t}\n\treturn Object.create(dep, view);\n}\n/**\n* A view of the config that `deriveParams` receives, at plan and at deploy.\n* Reading a marker in it throws, as `deriveParams` would compute with the\n* marker in place of the value. An `OwnPhysicalName` stands for a name that\n* deploy decides after the params. A credential marker stands for a value\n* that deploy puts in place of the marker only for the call to an\n* operation. Reading a ref or a derived value that is left in config, which\n* only plan leaves, calls `onPending`. So does reading `UNKNOWN_AFTER_APPLY`,\n* which plan gives for a credential that deploy rotates.\n*/\nfunction deriveParamsConfigView(owner, config, onPending) {\n\tconst guarded = (value) => isOwnPhysicalName(value) || isCredentialMarker(value) || onPending !== void 0 && (isRefOrDerived(value) || isUnknownAfterApply(value));\n\treturn guardedReadView(config, guarded, (value, path) => {\n\t\tconst param = [owner.id, ...path].join(\".\");\n\t\tif (isOwnPhysicalName(value)) throw new Error(`${param} is the physical name of ${owner.id} itself, which deploy decides after the params, so deriveParams can't read it.`);\n\t\tif (isCredentialMarker(value)) {\n\t\t\tconst { resource, name } = value.$credential;\n\t\t\tthrow new Error(`${param} is the credential ${resource}.${name}, which deploy puts in the params only for the call to an operation, so deriveParams can't read it.`);\n\t\t}\n\t\treturn onPending(value, owner, param);\n\t});\n}\nfunction guardedReadView(value, guarded, onRead, path = []) {\n\tif (guarded(value)) return onRead(value, path);\n\tif (!containsMatch(value, guarded)) return value;\n\tconst copy = Array.isArray(value) ? new Array(value.length) : {};\n\tfor (const [key, entry] of Object.entries(value)) {\n\t\tconst at = [...path, key];\n\t\tif (guarded(entry)) Object.defineProperty(copy, key, {\n\t\t\tenumerable: true,\n\t\t\tget: () => onRead(entry, at)\n\t\t});\n\t\telse copy[key] = guardedReadView(entry, guarded, onRead, at);\n\t}\n\treturn copy;\n}\n/**\n* A value computed from refs, which deploy fills in. Made by `text`, `all`\n* and `map`. It holds the values it reads and a function of them. Plan runs\n* the function when every ref it reads is known, and deploy runs it with the\n* values.\n*/\nvar Derived = class Derived extends Unstringable {\n\t[derivedBrand] = true;\n\t/** The refs, derived values and plain values that the function reads. */\n\t\"~inputs\";\n\t\"~compute\";\n\t\"~describe\";\n\tconstructor(options) {\n\t\tsuper();\n\t\tthis[\"~inputs\"] = options.inputs;\n\t\tthis[\"~compute\"] = options.compute;\n\t\tthis[\"~describe\"] = options.describe;\n\t}\n\t/** See `OutputRef.map`. */\n\tmap(fn) {\n\t\tconst callSite = captureCallSiteLazily(Derived.prototype.map, { skipLibraryFrames: true });\n\t\treturn mapDerived(this, fn, callSite);\n\t}\n\tstringError() {\n\t\treturn new OutputRefStringError(`Derived value ${this[\"~describe\"]()}`, \"a derived value\");\n\t}\n};\n/**\n* Joins strings, numbers, refs and derived values into a string that deploy\n* fills in: `` text`${api.url}/callback` ``. Each ref must hold a string or\n* a number when it is filled in. A credential or a `~state` ref can't be\n* joined. Code that runs in a function can't call it.\n* @resource\n*/\nfunction text(strings, ...parts) {\n\tconst callSite = captureCallSiteLazily(text, { skipLibraryFrames: true });\n\tconst where = () => `text\\`…\\` at ${site(callSite)}`;\n\tfor (const part of parts) assertDerivable(part, where);\n\tconst literals = [...strings];\n\treturn new Derived({\n\t\tinputs: parts,\n\t\tcompute: (values) => {\n\t\t\tlet joined = literals[0];\n\t\t\tvalues.forEach((value, index) => {\n\t\t\t\tif (typeof value !== \"string\" && typeof value !== \"number\") throw new Error(`${where()}: ${describeInput(parts[index])} is ${describeType(value)}, not a string or a number`);\n\t\t\t\tjoined += String(value) + literals[index + 1];\n\t\t\t});\n\t\t\treturn joined;\n\t\t},\n\t\tdescribe: () => {\n\t\t\tlet described = literals[0];\n\t\t\tparts.forEach((part, index) => {\n\t\t\t\tdescribed += isOutputRef(part) || isDerived(part) ? toCanonicalOutputRefs(part) : String(part);\n\t\t\t\tdescribed += literals[index + 1];\n\t\t\t});\n\t\t\treturn described;\n\t\t}\n\t});\n}\nfunction mapDerived(input, fn, callSite) {\n\tconst where = () => `The function of map() at ${site(callSite)}`;\n\treturn new Derived({\n\t\tinputs: [input],\n\t\tcompute: ([value]) => {\n\t\t\tlet result;\n\t\t\ttry {\n\t\t\t\tresult = fn(value);\n\t\t\t} catch (error) {\n\t\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\t\tthrow new Error(`${where()} threw: ${message}`, { cause: error });\n\t\t\t}\n\t\t\tassertRecordable(result, where);\n\t\t\treturn result;\n\t\t},\n\t\tdescribe: () => `<map of ${describeInput(input)} at ${site(callSite)}>`\n\t});\n}\nfunction site(callSite) {\n\treturn callSite() ?? \"an unknown call site\";\n}\nfunction assertDerivable(value, where) {\n\tif (isCredentialRef(value)) throw new Error(`${where()} reads the credential ${describeOutputRef(value)}. A credential can only be placed whole, because a value computed from it would be recorded in state as a plain param.`);\n\tif (isStateRef(value)) throw new Error(`${where()} reads the ~state ref ${describeOutputRef(value)}. A ~state ref can only be placed whole in a contribution.`);\n}\nfunction assertRecordable(value, where) {\n\tif ((typeof value === \"object\" || typeof value === \"function\") && value !== null && typeof value.then === \"function\") throw new Error(`${where()} returned a promise. The function must return its value.`);\n\tif (containsRefOrDerived(value)) throw new Error(`${where()} returned a value that holds an output ref or a derived value. Read each ref as an argument, with all() for several.`);\n\tconst found = findUnrecordable(value, []);\n\tif (found) {\n\t\tconst at = found.path.length > 0 ? ` at ${found.path.join(\".\")}` : \"\";\n\t\tthrow new Error(`${where()} returned ${describeUnrecordable(found.value)}${at}, which state can't record.`);\n\t}\n}\nfunction findUnrecordable(value, path) {\n\tif (typeof value === \"function\" || typeof value === \"bigint\" || typeof value === \"symbol\") return {\n\t\tvalue,\n\t\tpath\n\t};\n\tif (typeof value !== \"object\" || value === null) return void 0;\n\tif (!Array.isArray(value) && !isPlainObject(value)) return {\n\t\tvalue,\n\t\tpath\n\t};\n\tfor (const [key, entry] of Object.entries(value)) {\n\t\tconst found = findUnrecordable(entry, [...path, key]);\n\t\tif (found) return found;\n\t}\n}\nfunction describeUnrecordable(value) {\n\tif (typeof value === \"function\") return \"a function\";\n\tif (typeof value === \"bigint\") return \"a bigint\";\n\tif (typeof value === \"symbol\") return \"a symbol\";\n\tconst name = value.constructor?.name;\n\tif (!name) return \"an object of a class\";\n\treturn `${/^[AEIO]/i.test(name) ? \"an\" : \"a\"} ${name}`;\n}\nfunction describeInput(input) {\n\tif (isOutputRef(input)) return describeOutputRef(input);\n\tif (isDerived(input)) return input[\"~describe\"]();\n\treturn JSON.stringify(input) ?? String(input);\n}\nfunction describeType(value) {\n\tif (value === null) return \"null\";\n\tif (Array.isArray(value)) return \"an array\";\n\tif (typeof value === \"object\") return \"an object\";\n\tif (typeof value === \"undefined\") return \"undefined\";\n\treturn `a ${typeof value}`;\n}\n/**\n* Computes a derived value when `lookup` knows every ref it reads. A ref to\n* the own `physicalName` of a resource can't be read: deploy decides the\n* name after the params, and the lookup gives a marker in its place.\n*/\nfunction resolveDerived(derived, lookup) {\n\tconst values = [];\n\tfor (const input of derived[\"~inputs\"]) {\n\t\tlet found;\n\t\tif (isOutputRef(input)) {\n\t\t\tfound = lookup(input);\n\t\t\tif (found.known && isOwnPhysicalName(found.value)) throw new Error(`${derived[\"~describe\"]()} reads ${describeOutputRef(input)}, the physical name of ${input.resourceId} itself. Deploy decides the name after the params, so it can only be placed whole.`);\n\t\t} else if (isDerived(input)) found = resolveDerived(input, lookup);\n\t\telse found = {\n\t\t\tknown: true,\n\t\t\tvalue: input\n\t\t};\n\t\tif (!found.known) return found;\n\t\tif (isUnknownAfterApply(found.value)) return { known: false };\n\t\tvalues.push(found.value);\n\t}\n\treturn {\n\t\tknown: true,\n\t\tvalue: derived[\"~compute\"](values)\n\t};\n}\nvar ContributionConflictError = class extends Error {\n\tresourceId;\n\tpath;\n\tcontributors;\n\tconstructor(resourceId, path, contributors, values) {\n\t\tsuper(`Conflicting contributions to ${resourceId}: ${contributors[0]} and ${contributors[1]} both set ${path}, to ${display(values[0])} and ${display(values[1])}`);\n\t\tthis.resourceId = resourceId;\n\t\tthis.path = path;\n\t\tthis.contributors = contributors;\n\t\tthis.name = \"ContributionConflictError\";\n\t}\n};\nfunction display(value) {\n\treturn sortedJson.encode(toCanonicalOutputRefs(value));\n}\n/**\n* Captures the stack now, and returns a function that finds the call site in\n* it on its first call. V8 formats a captured stack only when it is first\n* read, and formatting is the costly part, most of all with source maps on.\n*/\nfunction captureCallSiteLazily(below, opts = {}) {\n\tconst holder = {};\n\tconst ErrorClass = Error;\n\tconst capture = ErrorClass.captureStackTrace;\n\tif (!capture) return () => void 0;\n\tconst limit = ErrorClass.stackTraceLimit;\n\tif (opts.skipLibraryFrames) ErrorClass.stackTraceLimit = 100;\n\ttry {\n\t\tcapture(holder, below);\n\t} finally {\n\t\tErrorClass.stackTraceLimit = limit;\n\t}\n\tlet found = false;\n\tlet callSite;\n\treturn () => {\n\t\tif (!found) {\n\t\t\tcallSite = findCallSite(holder.stack, opts.skipLibraryFrames);\n\t\t\tfound = true;\n\t\t}\n\t\treturn callSite;\n\t};\n}\nfunction findCallSite(stack, skipLibraryFrames) {\n\tconst sites = (stack?.split(\"\\n\").slice(1) ?? []).map(parseFrame).filter((site) => site !== void 0);\n\tconst site = skipLibraryFrames ? sites.find((site) => !isLibraryFile(site.file)) ?? sites[0] : sites[0];\n\tif (!site) return void 0;\n\tlet file = site.file;\n\tconst cwd = globalThis.process?.cwd?.();\n\tif (cwd && file.startsWith(`${cwd}/`)) file = file.slice(cwd.length + 1);\n\treturn `${file}:${site.line}`;\n}\nfunction parseFrame(frame) {\n\tconst match = frame.match(/\\(?([^\\s()]+):(\\d+):\\d+\\)?\\s*$/);\n\tif (!match) return void 0;\n\tlet file = match[1];\n\tif (file.startsWith(\"file://\")) file = decodeURIComponent(file.slice(7));\n\treturn {\n\t\tfile,\n\t\tline: match[2]\n\t};\n}\nconst notationPackagesDir = (() => {\n\tconst holder = {};\n\tError.captureStackTrace?.(holder);\n\treturn ((parseFrame(holder.stack?.split(\"\\n\")[1] ?? \"\")?.file)?.match(/^(.+)\\/resource\\/(?:src|dist)\\/[^/]+$/))?.[1];\n})();\nfunction isLibraryFile(file) {\n\tif (file.includes(\"/node_modules/\") || file.startsWith(\"node:\")) return true;\n\tif (!notationPackagesDir || !file.startsWith(`${notationPackagesDir}/`)) return false;\n\tconst inPackage = file.slice(notationPackagesDir.length + 1);\n\treturn /^[^/]+\\/(src|dist)\\//.test(inPackage);\n}\n/**\n* Sorts contributions by their content, so the order does not depend on the\n* order code ran in, and moving code to another file changes nothing.\n*/\nfunction sortContributions(items, valueOf) {\n\tconst keyed = items.map((item) => ({\n\t\titem,\n\t\tkey: sortedJson.encode(toCanonicalOutputRefs(valueOf(item)))\n\t}));\n\tkeyed.sort((a, b) => compare(a.key, b.key) || compare(a.item.contributor(), b.item.contributor()));\n\treturn keyed.map(({ item }) => item);\n}\nfunction compare(a, b) {\n\treturn a < b ? -1 : a > b ? 1 : 0;\n}\nfunction cloneMaps(value) {\n\tif (!isPlainObject(value)) return value;\n\tconst cloned = {};\n\tfor (const [key, entry] of Object.entries(value)) cloned[key] = cloneMaps(entry);\n\treturn cloned;\n}\n/**\n* A `collect` rule that merges maps key by key. Two items that set one key\n* to different values conflict, and the error names both contributors. Any\n* value other than a map, including an array, is set whole.\n*\n* A value that holds an output ref is not known yet, so it cannot be\n* compared: the merge keeps it, and a conflict with it is found at deploy,\n* when the output refs have been filled in.\n*/\nfunction mergeContributions(items, context) {\n\tconst root = {};\n\tconst owners = /* @__PURE__ */ new Map();\n\tconst contributorAt = (index) => context.contributors[index]?.() ?? \"an unnamed contributor\";\n\tconst ownerOf = (path) => {\n\t\tfor (let length = path.length; length > 0; length -= 1) {\n\t\t\tconst owner = owners.get(JSON.stringify(path.slice(0, length)));\n\t\t\tif (owner !== void 0) return contributorAt(owner);\n\t\t}\n\t\treturn \"an earlier contributor\";\n\t};\n\tconst mergeInto = (target, source, contributor, path) => {\n\t\tfor (const [key, value] of Object.entries(source)) {\n\t\t\tif (value === void 0) continue;\n\t\t\tconst entryPath = [...path, key];\n\t\t\tconst existing = target[key];\n\t\t\tif (existing === void 0) {\n\t\t\t\ttarget[key] = cloneMaps(value);\n\t\t\t\towners.set(JSON.stringify(entryPath), contributor);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (isPlainObject(existing) && isPlainObject(value)) {\n\t\t\t\tmergeInto(existing, value, contributor, entryPath);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (display(existing) === display(value)) continue;\n\t\t\tif (containsOutputRef(value)) {\n\t\t\t\ttarget[key] = value;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (containsOutputRef(existing)) continue;\n\t\t\tthrow new ContributionConflictError(context.resourceId, entryPath.join(\".\"), [ownerOf(entryPath), contributorAt(contributor)], [existing, value]);\n\t\t}\n\t};\n\titems.forEach((item, index) => {\n\t\tmergeInto(root, { [context.param]: item }, index, []);\n\t});\n\treturn root[context.param];\n}\nconst CHECK_POINTS = /* @__PURE__ */ new Set([\n\t\"declaration\",\n\t\"plan\",\n\t\"deploy\"\n]);\n/** Thrown when a value fails its schema item's validator. */\nvar ValueValidationError = class extends Error {\n\t_tag = \"ValueValidationError\";\n\tresourceId;\n\tresourceType;\n\tfield;\n\tpoint;\n\tdeclaredAt;\n\t/**\n\t* One line per issue the validator reported, prefixed by its path. For a\n\t* sensitive field the line holds a generic message in place of the\n\t* validator's, which can include the value.\n\t*/\n\tissues;\n\tconstructor(opts) {\n\t\tconst resource = `${opts.resourceId} (${opts.resourceType})`;\n\t\tconst site = opts.declaredAt ? `, declared at ${opts.declaredAt}` : \"\";\n\t\tconst subject = opts.point === \"read\" || opts.point === \"create\" || opts.point === \"rotate\" || opts.point === \"load\" ? `The ${opts.point} of ${resource} returned an invalid ${opts.field}${site}` : opts.point === \"declaration\" ? `Invalid ${opts.field} for ${resource} when declared${opts.declaredAt ? ` at ${opts.declaredAt}` : \"\"}` : `Invalid ${opts.field} for ${resource} at ${opts.point}${site}`;\n\t\tsuper(`${subject}: ${opts.issues.join(\"; \")}`);\n\t\tthis.name = \"ValueValidationError\";\n\t\tthis.resourceId = opts.resourceId;\n\t\tthis.resourceType = opts.resourceType;\n\t\tthis.field = opts.field;\n\t\tthis.point = opts.point;\n\t\tthis.declaredAt = opts.declaredAt;\n\t\tthis.issues = opts.issues;\n\t}\n\tstatic is(error) {\n\t\treturn hasTag(error, \"ValueValidationError\");\n\t}\n};\n/**\n* Thrown when values do not have the fields that the schema expects: a param\n* that the schema does not have as a param, a required param that is missing,\n* a create result field that the schema has but not as computed, or a\n* required output that is missing.\n*/\nvar SchemaStructureError = class extends Error {\n\t_tag = \"SchemaStructureError\";\n\tresourceId;\n\tresourceType;\n\tfields;\n\tconstructor(subject, problem, fields, hint) {\n\t\tconst site = subject.declaredAt ? `, declared at ${subject.declaredAt}` : \"\";\n\t\tsuper(`${subject.id} (${subject.type})${site}: ${problem}: ${fields.join(\", \")}` + (hint ? `. ${hint}` : \"\"));\n\t\tthis.name = \"SchemaStructureError\";\n\t\tthis.resourceId = subject.id;\n\t\tthis.resourceType = subject.type;\n\t\tthis.fields = fields;\n\t}\n\tstatic is(error) {\n\t\treturn hasTag(error, \"SchemaStructureError\");\n\t}\n};\n/**\n* Validates each value with the validator of its schema item, and throws\n* `ValueValidationError` for the first that fails. A value that is undefined,\n* or that has no schema item, is not validated. At the points in\n* `ParamChecks`, a value with a check is then validated with the check too.\n*\n* `isUnknown` marks values that stand for something not known yet, such as\n* output refs or values unknown until apply. A value that is unknown as a\n* whole is not validated. A value that holds unknowns is validated with them\n* in place, and the issues they could cause are dropped: an issue at or inside\n* an unknown, and an issue at a parent of one, such as a failed union or\n* object check. An issue with no path is at the root, so it is dropped too.\n* A validator that throws on such a value reports no issues.\n*\n* Returns a promise only when a validator is async, so validation at\n* declaration can throw from the constructor.\n*/\nfunction validateValues(subject, values, point, isUnknown = () => false, options = {}) {\n\tconst pending = [];\n\ttry {\n\t\tfor (const [field, value] of Object.entries(values)) {\n\t\t\tconst item = subject.schema[field];\n\t\t\tif (!item || value === void 0) continue;\n\t\t\tconst unknowns = findUnknownPaths(value, isUnknown);\n\t\t\tif (unknowns.some((path) => path.length === 0)) continue;\n\t\t\tconst check = options.checks !== false && CHECK_POINTS.has(point) && !(point === \"declaration\" && item.propertyType === \"param\" && item.collect) ? subject.checks?.[field] : void 0;\n\t\t\tconst validate = (validator) => {\n\t\t\t\tconst result = runValidator(validator, value, unknowns.length > 0);\n\t\t\t\tif (result instanceof Promise) return result.then((settled) => assertValid(subject, field, point, knownIssues(settled, unknowns)));\n\t\t\t\tassertValid(subject, field, point, knownIssues(result, unknowns));\n\t\t\t};\n\t\t\tlet validated;\n\t\t\tfor (const validator of [item.value, check]) {\n\t\t\t\tif (!validator) continue;\n\t\t\t\tvalidated = validated ? validated.then(() => validate(validator)) : validate(validator);\n\t\t\t}\n\t\t\tif (validated) pending.push(validated);\n\t\t}\n\t} catch (error) {\n\t\tfor (const promise of pending) promise.catch(() => {});\n\t\tthrow error;\n\t}\n\tif (pending.length > 0) return Promise.all(pending).then(() => void 0);\n}\nfunction findUnknownPaths(value, isUnknown, path = [], found = []) {\n\tif (isUnknown(value)) found.push(path);\n\telse if (Array.isArray(value)) value.forEach((entry, index) => findUnknownPaths(entry, isUnknown, [...path, String(index)], found));\n\telse if (isPlainObject(value)) for (const [key, entry] of Object.entries(value)) findUnknownPaths(entry, isUnknown, [...path, key], found);\n\treturn found;\n}\nfunction runValidator(validator, value, hasUnknowns) {\n\tif (!hasUnknowns) return validator[\"~standard\"].validate(value);\n\tconst valid = { value };\n\ttry {\n\t\tconst result = validator[\"~standard\"].validate(value);\n\t\treturn result instanceof Promise ? result.catch(() => valid) : result;\n\t} catch {\n\t\treturn valid;\n\t}\n}\nfunction knownIssues(result, unknowns) {\n\tconst issues = result.issues ?? [];\n\tif (unknowns.length === 0) return issues;\n\treturn issues.filter((issue) => {\n\t\tconst path = issuePath(issue);\n\t\treturn !unknowns.some((unknown) => isPrefixEither(path, unknown));\n\t});\n}\nfunction isPrefixEither(a, b) {\n\tconst length = Math.min(a.length, b.length);\n\tfor (let index = 0; index < length; index++) if (a[index] !== b[index]) return false;\n\treturn true;\n}\nfunction issuePath(issue) {\n\treturn (issue.path ?? []).map((segment) => String(typeof segment === \"object\" ? segment.key : segment));\n}\nfunction assertValid(subject, field, point, issues) {\n\tif (issues.length === 0) return;\n\tconst item = subject.schema[field];\n\tconst sensitive = item?.sensitive === true || item?.propertyType === \"credential\";\n\tthrow new ValueValidationError({\n\t\tresourceId: subject.id,\n\t\tresourceType: subject.type,\n\t\tfield,\n\t\tpoint,\n\t\tdeclaredAt: subject.declaredAt,\n\t\tissues: issues.map((issue) => formatIssue(issue, sensitive))\n\t});\n}\nfunction formatIssue(issue, sensitive) {\n\tconst message = sensitive ? \"Invalid sensitive value\" : issue.message;\n\tconst path = issuePath(issue).join(\".\");\n\treturn path ? `${path}: ${message}` : message;\n}\n/**\n* Throws unless every defined value is a param in the schema, and every\n* check names a param.\n*/\nfunction assertParamFields(subject, params) {\n\tconst notParams = (values) => Object.keys(values).filter((field) => values[field] !== void 0 && subject.schema[field]?.propertyType !== \"param\");\n\tconst checked = notParams(subject.checks ?? {});\n\tif (checked.length > 0) throw new SchemaStructureError(subject, \"these checks name fields that are not params in its schema\", checked);\n\tconst extra = notParams(params);\n\tif (extra.length > 0) throw new SchemaStructureError(subject, \"these fields are not params in its schema\", extra);\n}\nfunction hasTag(error, tag) {\n\treturn typeof error === \"object\" && error !== null && \"_tag\" in error && error._tag === tag;\n}\nvar Resource = class Resource {\n\tkind = \"resource\";\n\tconfig;\n\tchecks;\n\tid;\n\tgroup = null;\n\toutput = null;\n\tdependencies = {};\n\t#collection = getActiveResourceCollection();\n\t#contributions = [];\n\t#addedDependencies = [];\n\t#sealed = false;\n\t#stateRefTarget = false;\n\tfind;\n\trotate;\n\trotateManually;\n\tconstructor(id, { config, dependencies, checks } = {}) {\n\t\tthis.id = id;\n\t\tthis.config = config || {};\n\t\tthis.checks = checks ?? {};\n\t\tthis.dependencies = dependencies || {};\n\t\tthis.#collection?.graph.resources.push(this);\n\t\tconst declaredAt = captureCallSiteLazily(new.target, { skipLibraryFrames: true });\n\t\tObject.defineProperty(this, \"declaredAt\", {\n\t\t\tget: declaredAt,\n\t\t\tenumerable: true\n\t\t});\n\t\treturn this;\n\t}\n\t/**\n\t* Checks config when the resource is declared: every field and every check\n\t* names a param, and every value passes its validator and its check. A\n\t* check of a collected param waits for plan, as config holds only the\n\t* first of its items. The outputs that output refs point at are not known yet, so\n\t* issues that they could cause are left to plan and deploy; see\n\t* `validateValues`. A subclass calls this at the end of its constructor,\n\t* when the schema has been set.\n\t*\n\t* An async validator cannot throw from the constructor. Its result is\n\t* awaited when the resource graph has been collected, and is otherwise\n\t* left to plan and deploy.\n\t*/\n\tcheckDeclaration() {\n\t\tif (this.#collection?.declarationChecks === false) return;\n\t\tconst config = resolveOutputRefs(this.config, () => ({ known: false }));\n\t\tassertParamFields(this, config);\n\t\tconst pending = validateValues(this, config, \"declaration\", (value) => isOutputRef(value) || isDerived(value));\n\t\tif (!pending) return;\n\t\tpending.catch(() => {});\n\t\tif (this.#collection && !this.#collection.closed) this.#collection.pendingValidations.push(pending);\n\t}\n\tget key() {\n\t\treturn this.keyOf(this.output);\n\t}\n\tkeyOf(output) {\n\t\tconst key = {};\n\t\tfor (const [k, v] of Object.entries(this.schema)) if (v.primaryKey || v.secondaryKey) key[k] = output[k];\n\t\treturn key;\n\t}\n\tsetOutput(output) {\n\t\tthis.output = output;\n\t}\n\ttoComparable(output) {\n\t\treturn toComparableParams(this.schema, output);\n\t}\n\ttoState(output) {\n\t\tconst parsed = {};\n\t\tfor (const [k, v] of Object.entries(this.schema)) {\n\t\t\tif (v.hidden) continue;\n\t\t\tif (k in output) parsed[k] = output[k];\n\t\t}\n\t\treturn parsed;\n\t}\n\t/**\n\t* Copies the properties of a provider result that the schema declares.\n\t*/\n\ttoResult(result) {\n\t\tconst declared = {};\n\t\tfor (const key of Object.keys(this.schema)) if (key in result) declared[key] = result[key];\n\t\treturn declared;\n\t}\n\t/**\n\t* Returns a ref to one of the resource's outputs. Place it whole in config\n\t* or in a contribution, join it with `text`, or compute with it in `map`.\n\t* The resource holding it depends on this one, and the real value is\n\t* filled in at deploy. An output that the schema makes optional gives a\n\t* ref to a value that can be undefined.\n\t*/\n\toutputRef(key) {\n\t\tif (this.schema[key]?.propertyType === \"credential\") throw new Error(`${key} of ${this.id} is a credential. Use ${this.id}.credentials.${key} for a ref to it.`);\n\t\treturn new OutputRef(this, [key]);\n\t}\n\t/**\n\t* A ref to each of the resource's credentials. Place it whole in the\n\t* config of the resource that takes the credential. That resource depends\n\t* on this one, and its operations receive the value in their params. State\n\t* holds a marker in place of the value.\n\t*/\n\tget credentials() {\n\t\tconst refs = {};\n\t\tfor (const [key, item] of Object.entries(this.schema)) if (item.propertyType === \"credential\") refs[key] = new OutputRef(this, [key], \"credential\");\n\t\treturn refs;\n\t}\n\tgetOutputRefs() {\n\t\tthis.#sealed = true;\n\t\tconst found = [];\n\t\tforEachOutputRef(this.config, (token) => found.push(token));\n\t\tfor (const contribution of this.#contributions) {\n\t\t\tif (\"compute\" in contribution) continue;\n\t\t\tforEachOutputRef(contribution.values, (token) => found.push(token));\n\t\t}\n\t\treturn found;\n\t}\n\t/**\n\t* Reads outputs from the resource's state record, for the code of a\n\t* resource package. `outputRef(key)` returns a token that resolves to the\n\t* output in the record at the start of the deploy or plan, or to\n\t* undefined when there is no full record. When the deploy replaces this\n\t* resource, the token resolves to the output from before the replace. The\n\t* resource holding the token does not depend on this one. A resumed deploy\n\t* uses the params that it recorded. The token can only be placed in a contribution:\n\t* `getDependencies` throws when config holds one.\n\t*\n\t* `outputRef` can read only a param that is `immutable`, `primaryKey` or\n\t* `secondaryKey`, or that has `physicalName`, and that is not `hidden`.\n\t* It throws for any other key, though the type accepts every output.\n\t*/\n\tget \"~state\"() {\n\t\treturn { outputRef: (key) => {\n\t\t\tconst token = stateOutputRef(this, key);\n\t\t\tthis.#stateRefTarget = true;\n\t\t\treturn token;\n\t\t} };\n\t}\n\tisStateRefTarget() {\n\t\treturn this.#stateRefTarget;\n\t}\n\tcontribute(input, options = {}) {\n\t\tconst callSite = captureCallSiteLazily(Resource.prototype.contribute, { skipLibraryFrames: true });\n\t\tconst contributor = () => callSite() ?? \"an unknown call site\";\n\t\tthis.#assertOpen(\"contribute to\");\n\t\tif (typeof input === \"function\") {\n\t\t\tthis.#contributions.push({\n\t\t\t\tcompute: input,\n\t\t\t\tdeps: options.deps ?? {},\n\t\t\t\tcontributor\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\t\tthis.#contributions.push({\n\t\t\tvalues: this.#checkContribution(input),\n\t\t\tcontributor\n\t\t});\n\t}\n\tdependOn(resource) {\n\t\tthis.#assertOpen(\"add a dependency to\");\n\t\tthis.#addedDependencies.push(resource);\n\t}\n\tgetDependencies() {\n\t\tconst found = new Set(this.getFixedDependencies());\n\t\tfor (const contribution of this.#contributions) for (const dependency of contributionDependencies(this, contribution)) found.add(dependency);\n\t\treturn [...found];\n\t}\n\tgetFixedDependencies() {\n\t\tthis.#sealed = true;\n\t\tconst found = /* @__PURE__ */ new Set();\n\t\tfor (const dependency of Object.values(this.dependencies)) if (dependency) found.add(dependency);\n\t\tfor (const dependency of this.#addedDependencies) found.add(dependency);\n\t\tforEachOutputRef(this.config, (token) => {\n\t\t\tif (isStateRef(token)) throw new Error(`The config of ${this.id} holds a ~state ref to ${token.resourceId}. A ~state ref can only be placed in a contribution.`);\n\t\t\tif (isDependencyRef(this, token)) found.add(token.resource);\n\t\t});\n\t\treturn [...found];\n\t}\n\tgetContributedParams({ from } = {}) {\n\t\tthis.#sealed = true;\n\t\tconst params = /* @__PURE__ */ new Set();\n\t\tfor (const contribution of this.#contributions) {\n\t\t\tif (from && !dependsOnAny(this, contribution, from)) continue;\n\t\t\tconst keys = \"compute\" in contribution ? Object.keys(this.schema).filter((key) => this.schema[key]?.propertyType === \"param\" && Boolean(this.schema[key].collect)) : Object.keys(contribution.values);\n\t\t\tfor (const key of keys) params.add(key);\n\t\t}\n\t\treturn [...params].sort();\n\t}\n\tasync getParams({ excludeContributionsFrom, recordedOutputs } = {}) {\n\t\tthis.#sealed = true;\n\t\tconst config = this.#resolveRefs(this.config, false, recordedOutputs);\n\t\tconst derivedParams = await this.deriveParams({\n\t\t\tid: this.id,\n\t\t\tconfig: deriveParamsConfigView(this, config),\n\t\t\tdeps: deployViews(this.dependencies)\n\t\t});\n\t\treturn await this.#combineParams(config, derivedParams, {\n\t\t\tplan: false,\n\t\t\texcludeContributionsFrom,\n\t\t\trecordedOutputs\n\t\t});\n\t}\n\t/**\n\t* At plan, `deriveParams` receives a view of config, and views of its\n\t* dependencies. Reading a value in config that a ref or a derived value\n\t* gives, when plan does not know it, throws `PendingOutput`. So does\n\t* reading the output of a dependency that has none yet, a required output\n\t* that is missing from a dependency's output, or such a value in the\n\t* config of a dependency. When `deriveParams` reads such a value, the plan\n\t* cannot tell which params are known: every param not set in config is\n\t* unknown. When it reads none, the plan is exact.\n\t*\n\t* A ref to the resource's own `physicalName` param is an `OwnPhysicalName`\n\t* in the result, here and in `getParams`, for the reconciler to fill in.\n\t* A credential is a credential marker. Reading either of them in the\n\t* config that `deriveParams` receives throws.\n\t*/\n\tasync planParams({ recordedOutputs } = {}) {\n\t\tthis.#sealed = true;\n\t\tconst config = this.#resolveRefs(this.config, true, recordedOutputs);\n\t\tconst views = createPlanViews();\n\t\tconst derivedParams = await tryAtPlan(views, () => this.deriveParams({\n\t\t\tid: this.id,\n\t\t\tconfig: deriveParamsConfigView(this, config, views.pending),\n\t\t\tdeps: views.of(this.dependencies)\n\t\t}));\n\t\tif (derivedParams === void 0) return this.#cautiousPlanParams(recordedOutputs);\n\t\treturn markUnknownOutputRefs(withoutUndefined(await this.#combineParams(config, derivedParams, {\n\t\t\tplan: true,\n\t\t\trecordedOutputs\n\t\t})));\n\t}\n\tasync #cautiousPlanParams(recordedOutputs) {\n\t\tconst params = {};\n\t\tconst config = this.config;\n\t\tconst contributions = await this.#evaluateContributions(true);\n\t\tfor (const [key, item] of Object.entries(this.schema)) {\n\t\t\tif (item.propertyType !== \"param\") continue;\n\t\t\tconst value = item.collect ? this.#collect(key, item.collect, config[key], contributions, true, recordedOutputs) : this.#resolveRefs(config[key], true, recordedOutputs);\n\t\t\tparams[key] = value === void 0 ? UNKNOWN_AFTER_APPLY : markUnknownOutputRefs(value);\n\t\t}\n\t\treturn params;\n\t}\n\tasync #combineParams(config, derivedParams, options) {\n\t\tconst { plan, excludeContributionsFrom, recordedOutputs } = options;\n\t\tconst params = {\n\t\t\t...config,\n\t\t\t...derivedParams\n\t\t};\n\t\tconst contributions = await this.#evaluateContributions(plan, excludeContributionsFrom);\n\t\tfor (const [key, item] of Object.entries(this.schema)) {\n\t\t\tif (item.propertyType !== \"param\" || !item.collect) continue;\n\t\t\tparams[key] = this.#collect(key, item.collect, params[key], contributions, plan, recordedOutputs);\n\t\t}\n\t\treturn this.#resolveRefs(params, plan, recordedOutputs);\n\t}\n\t/**\n\t* Fills in the refs in `value` that are known, and computes the derived\n\t* values whose refs are known. A `~state` ref takes its value from\n\t* `recordedOutputs`. A ref to the resource's own\n\t* `physicalName` param becomes an `OwnPhysicalName`, as the name is\n\t* decided after the params.\n\t*/\n\t#resolveRefs(value, plan, recordedOutputs) {\n\t\tconst lookup = plan ? planLookup : deployLookup;\n\t\tconst lookupRecorded = recordedLookup(recordedOutputs);\n\t\treturn resolveOutputRefs(value, (token) => isStateRef(token) ? lookupRecorded(token) : isOwnNameRef(this, token) ? {\n\t\t\tknown: true,\n\t\t\tvalue: ownPhysicalName(token.path[0])\n\t\t} : lookup(token));\n\t}\n\t/**\n\t* Runs function contributions. Each one receives views of its deps, as\n\t* `deriveParams` does. When one reads an output that does not exist yet,\n\t* plan cannot tell which params it would set, so `unknown` is set and\n\t* `#collect` marks every collected param unknown.\n\t*/\n\tasync #evaluateContributions(plan, exclude) {\n\t\tconst evaluated = {\n\t\t\titems: [],\n\t\t\tunknown: false\n\t\t};\n\t\tfor (const contribution of this.#contributions) {\n\t\t\tif (exclude && dependsOnAny(this, contribution, exclude)) continue;\n\t\t\tif (!(\"compute\" in contribution)) {\n\t\t\t\tevaluated.items.push(contribution);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (!plan) {\n\t\t\t\tconst values = contribution.compute({ deps: deployViews(contribution.deps) });\n\t\t\t\tevaluated.items.push({\n\t\t\t\t\tvalues: this.#checkContribution(values),\n\t\t\t\t\tcontributor: contribution.contributor\n\t\t\t\t});\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst views = createPlanViews();\n\t\t\tconst values = await tryAtPlan(views, () => contribution.compute({ deps: views.of(contribution.deps) }));\n\t\t\tif (values === void 0) {\n\t\t\t\tevaluated.unknown = true;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tevaluated.items.push({\n\t\t\t\tvalues: this.#checkContribution(values),\n\t\t\t\tcontributor: contribution.contributor\n\t\t\t});\n\t\t}\n\t\treturn evaluated;\n\t}\n\t/**\n\t* Combines a collected param's value from config with its contributions.\n\t* Output refs are filled in first, so that `collect` compares real\n\t* values wherever they are known.\n\t*/\n\t#collect(key, collect, configured, contributions, plan, recordedOutputs) {\n\t\tif (contributions.unknown) return UNKNOWN_AFTER_APPLY;\n\t\tconst items = sortContributions(contributions.items.filter((contribution) => contribution.values[key] !== void 0).map((contribution) => ({\n\t\t\tvalue: contribution.values[key],\n\t\t\tcontributor: contribution.contributor\n\t\t})), (item) => item.value);\n\t\tif (configured !== void 0) items.unshift({\n\t\t\tvalue: configured,\n\t\t\tcontributor: () => `the config of ${this.id}`\n\t\t});\n\t\tif (items.length === 0) return void 0;\n\t\treturn collect(items.map((item) => this.#resolveRefs(item.value, plan, recordedOutputs)), {\n\t\t\tresourceId: this.id,\n\t\t\tparam: key,\n\t\t\tcontributors: items.map((item) => item.contributor)\n\t\t});\n\t}\n\t#checkContribution(values) {\n\t\tconst recorded = {};\n\t\tfor (const [key, value] of Object.entries(values)) {\n\t\t\tconst item = this.schema[key];\n\t\t\tif (!item || item.propertyType !== \"param\" || !item.collect) throw new Error(`Cannot contribute ${key} to ${this.id}: ${this.type} does not collect it`);\n\t\t\tif (value !== void 0) recorded[key] = value;\n\t\t}\n\t\treturn recorded;\n\t}\n\t#assertOpen(action) {\n\t\tconst reason = this.#collection?.closed ? \"evaluation has ended\" : this.#sealed ? \"its params have already been read\" : void 0;\n\t\tif (!reason) return;\n\t\tthrow new Error(`Cannot ${action} ${this.id}: ${reason}. Contributions are accepted only while infra is being evaluated.`);\n\t}\n};\n/**\n* The deps of a function contribution, or the resources whose output refs\n* a contribution of values holds.\n*/\nfunction contributionDependencies(holder, contribution) {\n\tif (\"compute\" in contribution) return Object.values(contribution.deps);\n\tconst found = [];\n\tforEachOutputRef(contribution.values, (token) => {\n\t\tif (isDependencyRef(holder, token)) found.push(token.resource);\n\t});\n\treturn found;\n}\nfunction dependsOnAny(holder, contribution, resources) {\n\treturn contributionDependencies(holder, contribution).some((dependency) => resources.has(dependency));\n}\nasync function tryAtPlan(views, run) {\n\ttry {\n\t\tconst result = await run();\n\t\treturn views.readPending ? void 0 : result;\n\t} catch (error) {\n\t\tif (views.readPending) return void 0;\n\t\tthrow error;\n\t}\n}\nfunction withoutUndefined(params) {\n\tconst defined = {};\n\tfor (const [key, value] of Object.entries(params)) if (value !== void 0) defined[key] = value;\n\treturn defined;\n}\nfunction defineResource(meta) {\n\treturn { defineSchema(schema) {\n\t\treturn { defineOperations(opts) {\n\t\t\tclass SimpleResource extends Resource {\n\t\t\t\tstatic type = meta.type;\n\t\t\t\tstatic provider = meta.provider;\n\t\t\t\ttype = meta.type;\n\t\t\t\tstatic blocksDeleteOf = meta.blocksDeleteOf ?? [];\n\t\t\t\tdeleteTakesDependents = meta.deleteTakesDependents ?? false;\n\t\t\t\treplaceCreatesFirst = meta.replaceCreatesFirst ?? false;\n\t\t\t\treadLagsCreate = meta.readLagsCreate ?? false;\n\t\t\t\tstatic rejectChange = opts.rejectChange;\n\t\t\t\tget rejectChange() {\n\t\t\t\t\treturn SimpleResource.rejectChange;\n\t\t\t\t}\n\t\t\t\tprovider = meta.provider;\n\t\t\t\tschema = schema;\n\t\t\t\tcreate = opts.create;\n\t\t\t\tfind = opts.find;\n\t\t\t\trotate = opts.rotate;\n\t\t\t\trotateManually = opts.rotateManually;\n\t\t\t\tread = opts.read ? opts.read : void 0;\n\t\t\t\tupdate = opts.update ? opts.update : void 0;\n\t\t\t\tdelete = opts.delete;\n\t\t\t\tconstructor(id, args) {\n\t\t\t\t\tsuper(id, args);\n\t\t\t\t\tthis.checkDeclaration();\n\t\t\t\t}\n\t\t\t\tasync deriveParams(input) {\n\t\t\t\t\tif (!opts.deriveParams) return {};\n\t\t\t\t\treturn await opts.deriveParams({ config: input.config });\n\t\t\t\t}\n\t\t\t\tstatic requireDependencies() {\n\t\t\t\t\treturn { deriveParams(deriveParams) {\n\t\t\t\t\t\treturn class DependencyAwareResource extends SimpleResource {\n\t\t\t\t\t\t\tasync deriveParams(input) {\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t...await super.deriveParams(input),\n\t\t\t\t\t\t\t\t\t...await deriveParams({\n\t\t\t\t\t\t\t\t\t\tid: this.id,\n\t\t\t\t\t\t\t\t\t\tconfig: input.config,\n\t\t\t\t\t\t\t\t\t\tdeps: input.deps\n\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t};\n\t\t\t\t\t} };\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn SimpleResource;\n\t\t} };\n\t} };\n}\nconst resource = defineResource;\nvar ResourceGroup = class ResourceGroup {\n\ttype;\n\tid;\n\tconfig;\n\tresources;\n\t/** The groups that were added to this group. */\n\tgroups;\n\t#graph;\n\t#parent = null;\n\t/**\n\t* @param id Identifies the group across deployments. Must be unique among\n\t* groups of the same type.\n\t*/\n\tconstructor(type, id, config) {\n\t\tconst collection = getActiveResourceCollection();\n\t\tif (collection) assertUniqueGroup(collection.graph, type, id);\n\t\tthis.type = type;\n\t\tthis.id = id;\n\t\tthis.#graph = collection?.graph;\n\t\tthis.config = config || {};\n\t\tthis.resources = [];\n\t\tthis.groups = [];\n\t\tcollection?.graph.resourceGroups.push(this);\n\t\treturn this;\n\t}\n\t/** The group this group was added to, or null if it is at the top level. */\n\tget parent() {\n\t\treturn this.#parent?.ref ?? null;\n\t}\n\t/**\n\t* Identifies the group and its ancestors, ordered from the outermost\n\t* group. Resources in the group record it as `resource.group`.\n\t*/\n\tget ref() {\n\t\tconst parents = [];\n\t\tfor (let group = this.#parent; group; group = group.#parent) parents.unshift({\n\t\t\ttype: group.type,\n\t\t\tid: group.id\n\t\t});\n\t\treturn {\n\t\t\ttype: this.type,\n\t\t\tid: this.id,\n\t\t\tparents\n\t\t};\n\t}\n\t/**\n\t* Puts a resource or a group in this group. A resource that was constructed\n\t* while the graph was being collected is already in the graph; any other\n\t* resource joins the graph here, and so does a group with its contents. A\n\t* resource or a group can be in one group only. A group can't be added to\n\t* itself or to one of the groups it is in.\n\t*/\n\tadd(member) {\n\t\tif (member instanceof ResourceGroup) return this.#addGroup(member);\n\t\tconst resource = member;\n\t\tif (resource.group) throw new Error(`Resource ${resource.type} \"${resource.id}\" has already been registered in group ${resource.group.type} \"${resource.group.id}\".`);\n\t\tif (this.#graph && !this.#graph.resources.includes(resource)) this.#graph.resources.push(resource);\n\t\tresource.group = this.ref;\n\t\tthis.resources.push(resource);\n\t\treturn member;\n\t}\n\t#addGroup(group) {\n\t\tfor (let ancestor = this; ancestor; ancestor = ancestor.#parent) if (ancestor === group) throw new Error(`Group ${group.type} \"${group.id}\" can't be added to ${group === this ? \"itself\" : `group ${this.type} \"${this.id}\", which it contains`}.`);\n\t\tif (group.#parent) throw new Error(`Group ${group.type} \"${group.id}\" has already been added to group ${group.#parent.type} \"${group.#parent.id}\".`);\n\t\tif (this.#graph) group.#join(this.#graph);\n\t\tgroup.#parent = this;\n\t\tgroup.#updateRefs();\n\t\tthis.groups.push(group);\n\t\treturn group;\n\t}\n\t#join(graph) {\n\t\tif (!graph.resourceGroups.includes(this)) {\n\t\t\tassertUniqueGroup(graph, this.type, this.id);\n\t\t\tgraph.resourceGroups.push(this);\n\t\t}\n\t\tthis.#graph = graph;\n\t\tfor (const resource of this.resources) if (!graph.resources.includes(resource)) graph.resources.push(resource);\n\t\tfor (const group of this.groups) group.#join(graph);\n\t}\n\t#updateRefs() {\n\t\tconst ref = this.ref;\n\t\tfor (const resource of this.resources) resource.group = ref;\n\t\tfor (const group of this.groups) group.#updateRefs();\n\t}\n\t/**\n\t* Adds a resource unless the group already has one with the same ID, and\n\t* returns the one the group holds. Use it for resources that bind two\n\t* others, such as an API integration, which several call sites may create.\n\t*/\n\taddOnce(ResourceClass, id, ...args) {\n\t\tconst existing = this.resources.find((r) => r.id === id);\n\t\tif (!existing) return this.add(new ResourceClass(id, ...args));\n\t\tif (existing.constructor !== ResourceClass) throw new Error(`Resource ${id} already exists as ${existing.type} in group ${this.type}.`);\n\t\treturn existing;\n\t}\n};\nfunction assertUniqueGroup(graph, type, id) {\n\tif (graph.resourceGroups.some((group) => group.type === type && group.id === id)) throw new Error(`Duplicate ${type} id \"${id}\": another ${type} group in this deployment already uses it.`);\n}\nexport { getActiveResourceCollection as a, resource as c, defineResource as i, text as l, ResourceGroup as n, mergeContributions as o, collectResourceGraph as r, physicalName as s, ContributionConflictError as t };\n","outpost-6-Dvnk0L.js":"import { a as getActiveResourceCollection, c as resource, n as ResourceGroup, o as mergeContributions, s as physicalName, t as ContributionConflictError } from \"./dist-Bwjh3db-.js\";\nconst DEFAULT_CONFIG = {\n\tlang: void 0,\n\tmessage: void 0,\n\tabortEarly: void 0,\n\tabortPipeEarly: void 0\n};\n/**\n* Returns the global configuration.\n*\n* @param config The config to merge.\n*\n* @returns The configuration.\n*/\n/* @__NO_SIDE_EFFECTS__ */\nfunction getGlobalConfig(config$1) {\n\tif (!config$1 && true) return DEFAULT_CONFIG;\n\treturn {\n\t\tlang: config$1?.lang ?? void 0,\n\t\tmessage: config$1?.message,\n\t\tabortEarly: config$1?.abortEarly ?? void 0,\n\t\tabortPipeEarly: config$1?.abortPipeEarly ?? void 0\n\t};\n}\n/**\n* Stringifies an unknown input to a literal or type string.\n*\n* @param input The unknown input.\n*\n* @returns A literal or type string.\n*\n* @internal\n*/\n/* @__NO_SIDE_EFFECTS__ */\nfunction _stringify(input) {\n\tconst type = typeof input;\n\tif (type === \"string\") return `\"${input}\"`;\n\tif (type === \"number\" || type === \"bigint\" || type === \"boolean\") return `${input}`;\n\tif (type === \"object\" || type === \"function\") return (input && Object.getPrototypeOf(input)?.constructor?.name) ?? \"null\";\n\treturn type;\n}\n/**\n* Adds an issue to the dataset.\n*\n* @param context The issue context.\n* @param label The issue label.\n* @param dataset The input dataset.\n* @param config The configuration.\n* @param other The optional props.\n*\n* @internal\n*/\nfunction _addIssue(context, label, dataset, config$1, other) {\n\tconst input = other && \"input\" in other ? other.input : dataset.value;\n\tconst expected = other?.expected ?? context.expects ?? null;\n\tconst received = other?.received ?? /* @__PURE__ */ _stringify(input);\n\tconst issue = {\n\t\tkind: context.kind,\n\t\ttype: context.type,\n\t\tinput,\n\t\texpected,\n\t\treceived,\n\t\tmessage: `Invalid ${label}: ${expected ? `Expected ${expected} but r` : \"R\"}eceived ${received}`,\n\t\trequirement: context.requirement,\n\t\tpath: other?.path,\n\t\tissues: other?.issues,\n\t\tlang: config$1.lang,\n\t\tabortEarly: config$1.abortEarly,\n\t\tabortPipeEarly: config$1.abortPipeEarly\n\t};\n\tconst isSchema = context.kind === \"schema\";\n\tconst message$1 = other?.message ?? context.message ?? (context.reference, issue.lang, void 0) ?? (isSchema ? (issue.lang, void 0) : null) ?? config$1.message ?? (issue.lang, void 0);\n\tif (message$1 !== void 0) issue.message = typeof message$1 === \"function\" ? message$1(issue) : message$1;\n\tif (isSchema) dataset.typed = false;\n\tif (dataset.issues) dataset.issues.push(issue);\n\telse dataset.issues = [issue];\n}\n/**\n* Compares two values using the SameValueZero algorithm, which treats `NaN`\n* as equal to itself unlike `===`.\n*\n* @param value1 The first value.\n* @param value2 The second value.\n*\n* @returns Whether the values are equal.\n*\n* @internal\n*/\n/* @__NO_SIDE_EFFECTS__ */\nfunction _isSameValueZero(value1, value2) {\n\treturn value1 === value2 || Number.isNaN(value1) && Number.isNaN(value2);\n}\n/**\n* Disallows inherited object properties and prevents object prototype\n* pollution by disallowing certain keys.\n*\n* @param object The object to check.\n* @param key The key to check.\n*\n* @returns Whether the key is allowed.\n*\n* @internal\n*/\n/* @__NO_SIDE_EFFECTS__ */\nfunction _isValidObjectKey(object$1, key) {\n\treturn Object.prototype.hasOwnProperty.call(object$1, key) && key !== \"__proto__\" && key !== \"prototype\" && key !== \"constructor\";\n}\n/**\n* Joins multiple `expects` values with the given separator.\n*\n* @param values The `expects` values.\n* @param separator The separator.\n*\n* @returns The joined `expects` property.\n*\n* @internal\n*/\n/* @__NO_SIDE_EFFECTS__ */\nfunction _joinExpects(values$1, separator) {\n\tconst list = [...new Set(values$1)];\n\tif (list.length > 1) return `(${list.join(` ${separator} `)})`;\n\treturn list[0] ?? \"never\";\n}\n/**\n* Eagerly creates and attaches the Standard Schema properties of a schema.\n*\n* Hint: The contextual `this` type includes the standard properties that are\n* attached before the schema is returned.\n*\n* @param schema The schema to attach standard properties to.\n*\n* @returns The schema with standard properties attached.\n*\n* @internal\n*/\nfunction _standardSchema(schema) {\n\tschema[\"~standard\"] = {\n\t\tversion: 1,\n\t\tvendor: \"valibot\",\n\t\tvalidate: (value$1) => schema[\"~run\"]({ value: value$1 }, /* @__PURE__ */ getGlobalConfig())\n\t};\n\treturn schema;\n}\n/**\n* A Valibot error with useful information.\n*/\nvar ValiError = class extends Error {\n\t/**\n\t* Creates a Valibot error with useful information.\n\t*\n\t* @param issues The error issues.\n\t*/\n\tconstructor(issues) {\n\t\tsuper(issues[0].message);\n\t\tthis.name = \"ValiError\";\n\t\tthis.issues = issues;\n\t}\n};\n/* @__NO_SIDE_EFFECTS__ */\nfunction startsWith(requirement, message$1) {\n\treturn {\n\t\tkind: \"validation\",\n\t\ttype: \"starts_with\",\n\t\treference: startsWith,\n\t\tasync: false,\n\t\texpects: `\"${requirement}\"`,\n\t\trequirement,\n\t\tmessage: message$1,\n\t\t\"~run\"(dataset, config$1) {\n\t\t\tif (dataset.typed && !dataset.value.startsWith(this.requirement)) _addIssue(this, \"start\", dataset, config$1, { received: `\"${dataset.value.slice(0, this.requirement.length)}\"` });\n\t\t\treturn dataset;\n\t\t}\n\t};\n}\nconst ABORT_EARLY_CONFIG = { abortEarly: true };\n/**\n* Returns the fallback value of the schema.\n*\n* @param schema The schema to get it from.\n* @param dataset The output dataset if available.\n* @param config The config if available.\n*\n* @returns The fallback value.\n*/\n/* @__NO_SIDE_EFFECTS__ */\nfunction getFallback(schema, dataset, config$1) {\n\treturn typeof schema.fallback === \"function\" ? schema.fallback(dataset, config$1) : schema.fallback;\n}\n/**\n* Returns the default value of the schema.\n*\n* @param schema The schema to get it from.\n* @param dataset The input dataset if available.\n* @param config The config if available.\n*\n* @returns The default value.\n*/\n/* @__NO_SIDE_EFFECTS__ */\nfunction getDefault(schema, dataset, config$1) {\n\treturn typeof schema.default === \"function\" ? schema.default(dataset, config$1) : schema.default;\n}\n/* @__NO_SIDE_EFFECTS__ */\nfunction array(item, message$1) {\n\treturn _standardSchema({\n\t\tkind: \"schema\",\n\t\ttype: \"array\",\n\t\treference: array,\n\t\texpects: \"Array\",\n\t\tasync: false,\n\t\titem,\n\t\tmessage: message$1,\n\t\t\"~run\"(dataset, config$1) {\n\t\t\tconst input = dataset.value;\n\t\t\tif (Array.isArray(input)) {\n\t\t\t\tdataset.typed = true;\n\t\t\t\tdataset.value = [];\n\t\t\t\tfor (let key = 0; key < input.length; key++) {\n\t\t\t\t\tconst value$1 = input[key];\n\t\t\t\t\tconst itemDataset = this.item[\"~run\"]({ value: value$1 }, config$1);\n\t\t\t\t\tif (itemDataset.issues) {\n\t\t\t\t\t\tconst pathItem = {\n\t\t\t\t\t\t\ttype: \"array\",\n\t\t\t\t\t\t\torigin: \"value\",\n\t\t\t\t\t\t\tinput,\n\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t\tvalue: value$1\n\t\t\t\t\t\t};\n\t\t\t\t\t\tfor (const issue of itemDataset.issues) {\n\t\t\t\t\t\t\tif (issue.path) issue.path.unshift(pathItem);\n\t\t\t\t\t\t\telse issue.path = [pathItem];\n\t\t\t\t\t\t\tdataset.issues?.push(issue);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (!dataset.issues) dataset.issues = itemDataset.issues;\n\t\t\t\t\t\tif (config$1.abortEarly) {\n\t\t\t\t\t\t\tdataset.typed = false;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (!itemDataset.typed) dataset.typed = false;\n\t\t\t\t\tdataset.value.push(itemDataset.value);\n\t\t\t\t}\n\t\t\t} else _addIssue(this, \"type\", dataset, config$1);\n\t\t\treturn dataset;\n\t\t}\n\t});\n}\n/* @__NO_SIDE_EFFECTS__ */\nfunction custom(check$1, message$1) {\n\treturn _standardSchema({\n\t\tkind: \"schema\",\n\t\ttype: \"custom\",\n\t\treference: custom,\n\t\texpects: \"unknown\",\n\t\tasync: false,\n\t\tcheck: check$1,\n\t\tmessage: message$1,\n\t\t\"~run\"(dataset, config$1) {\n\t\t\tif (this.check(dataset.value)) dataset.typed = true;\n\t\t\telse _addIssue(this, \"type\", dataset, config$1);\n\t\t\treturn dataset;\n\t\t}\n\t});\n}\n/* @__NO_SIDE_EFFECTS__ */\nfunction literal(literal_, message$1) {\n\treturn _standardSchema({\n\t\tkind: \"schema\",\n\t\ttype: \"literal\",\n\t\treference: literal,\n\t\texpects: /* @__PURE__ */ _stringify(literal_),\n\t\tasync: false,\n\t\tliteral: literal_,\n\t\tmessage: message$1,\n\t\t\"~run\"(dataset, config$1) {\n\t\t\tif (/* @__PURE__ */ _isSameValueZero(dataset.value, this.literal)) dataset.typed = true;\n\t\t\telse _addIssue(this, \"type\", dataset, config$1);\n\t\t\treturn dataset;\n\t\t}\n\t});\n}\n/* @__NO_SIDE_EFFECTS__ */\nfunction looseObject(entries$1, message$1) {\n\treturn _standardSchema({\n\t\tkind: \"schema\",\n\t\ttype: \"loose_object\",\n\t\treference: looseObject,\n\t\texpects: \"Object\",\n\t\tasync: false,\n\t\tentries: entries$1,\n\t\tmessage: message$1,\n\t\t\"~run\"(dataset, config$1) {\n\t\t\tconst input = dataset.value;\n\t\t\tif (input && typeof input === \"object\") {\n\t\t\t\tdataset.typed = true;\n\t\t\t\tdataset.value = {};\n\t\t\t\tfor (const key in this.entries) {\n\t\t\t\t\tconst valueSchema = this.entries[key];\n\t\t\t\t\tif (key in input || (valueSchema.type === \"exact_optional\" || valueSchema.type === \"optional\" || valueSchema.type === \"nullish\") && valueSchema.default !== void 0) {\n\t\t\t\t\t\tconst value$1 = key in input ? input[key] : /* @__PURE__ */ getDefault(valueSchema);\n\t\t\t\t\t\tconst valueDataset = valueSchema[\"~run\"]({ value: value$1 }, config$1);\n\t\t\t\t\t\tif (valueDataset.issues) {\n\t\t\t\t\t\t\tconst pathItem = {\n\t\t\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\t\t\torigin: \"value\",\n\t\t\t\t\t\t\t\tinput,\n\t\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t\t\tvalue: value$1\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\tfor (const issue of valueDataset.issues) {\n\t\t\t\t\t\t\t\tif (issue.path) issue.path.unshift(pathItem);\n\t\t\t\t\t\t\t\telse issue.path = [pathItem];\n\t\t\t\t\t\t\t\tdataset.issues?.push(issue);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (!dataset.issues) dataset.issues = valueDataset.issues;\n\t\t\t\t\t\t\tif (config$1.abortEarly) {\n\t\t\t\t\t\t\t\tdataset.typed = false;\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (!valueDataset.typed) dataset.typed = false;\n\t\t\t\t\t\tdataset.value[key] = valueDataset.value;\n\t\t\t\t\t} else if (valueSchema.fallback !== void 0) dataset.value[key] = /* @__PURE__ */ getFallback(valueSchema);\n\t\t\t\t\telse if (valueSchema.type !== \"exact_optional\" && valueSchema.type !== \"optional\" && valueSchema.type !== \"nullish\") {\n\t\t\t\t\t\t_addIssue(this, \"key\", dataset, config$1, {\n\t\t\t\t\t\t\tinput: void 0,\n\t\t\t\t\t\t\texpected: `\"${key}\"`,\n\t\t\t\t\t\t\tpath: [{\n\t\t\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\t\t\torigin: \"key\",\n\t\t\t\t\t\t\t\tinput,\n\t\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t\t\tvalue: input[key]\n\t\t\t\t\t\t\t}]\n\t\t\t\t\t\t});\n\t\t\t\t\t\tif (config$1.abortEarly) break;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (!dataset.issues || !config$1.abortEarly) {\n\t\t\t\t\tfor (const key in input) if (/* @__PURE__ */ _isValidObjectKey(input, key) && !Object.prototype.hasOwnProperty.call(this.entries, key)) dataset.value[key] = input[key];\n\t\t\t\t}\n\t\t\t} else _addIssue(this, \"type\", dataset, config$1);\n\t\t\treturn dataset;\n\t\t}\n\t});\n}\n/* @__NO_SIDE_EFFECTS__ */\nfunction object(entries$1, message$1) {\n\treturn _standardSchema({\n\t\tkind: \"schema\",\n\t\ttype: \"object\",\n\t\treference: object,\n\t\texpects: \"Object\",\n\t\tasync: false,\n\t\tentries: entries$1,\n\t\tmessage: message$1,\n\t\t\"~run\"(dataset, config$1) {\n\t\t\tconst input = dataset.value;\n\t\t\tif (input && typeof input === \"object\") {\n\t\t\t\tdataset.typed = true;\n\t\t\t\tdataset.value = {};\n\t\t\t\tfor (const key in this.entries) {\n\t\t\t\t\tconst valueSchema = this.entries[key];\n\t\t\t\t\tif (key in input || (valueSchema.type === \"exact_optional\" || valueSchema.type === \"optional\" || valueSchema.type === \"nullish\") && valueSchema.default !== void 0) {\n\t\t\t\t\t\tconst value$1 = key in input ? input[key] : /* @__PURE__ */ getDefault(valueSchema);\n\t\t\t\t\t\tconst valueDataset = valueSchema[\"~run\"]({ value: value$1 }, config$1);\n\t\t\t\t\t\tif (valueDataset.issues) {\n\t\t\t\t\t\t\tconst pathItem = {\n\t\t\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\t\t\torigin: \"value\",\n\t\t\t\t\t\t\t\tinput,\n\t\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t\t\tvalue: value$1\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\tfor (const issue of valueDataset.issues) {\n\t\t\t\t\t\t\t\tif (issue.path) issue.path.unshift(pathItem);\n\t\t\t\t\t\t\t\telse issue.path = [pathItem];\n\t\t\t\t\t\t\t\tdataset.issues?.push(issue);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (!dataset.issues) dataset.issues = valueDataset.issues;\n\t\t\t\t\t\t\tif (config$1.abortEarly) {\n\t\t\t\t\t\t\t\tdataset.typed = false;\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (!valueDataset.typed) dataset.typed = false;\n\t\t\t\t\t\tdataset.value[key] = valueDataset.value;\n\t\t\t\t\t} else if (valueSchema.fallback !== void 0) dataset.value[key] = /* @__PURE__ */ getFallback(valueSchema);\n\t\t\t\t\telse if (valueSchema.type !== \"exact_optional\" && valueSchema.type !== \"optional\" && valueSchema.type !== \"nullish\") {\n\t\t\t\t\t\t_addIssue(this, \"key\", dataset, config$1, {\n\t\t\t\t\t\t\tinput: void 0,\n\t\t\t\t\t\t\texpected: `\"${key}\"`,\n\t\t\t\t\t\t\tpath: [{\n\t\t\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\t\t\torigin: \"key\",\n\t\t\t\t\t\t\t\tinput,\n\t\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t\t\tvalue: input[key]\n\t\t\t\t\t\t\t}]\n\t\t\t\t\t\t});\n\t\t\t\t\t\tif (config$1.abortEarly) break;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else _addIssue(this, \"type\", dataset, config$1);\n\t\t\treturn dataset;\n\t\t}\n\t});\n}\n/* @__NO_SIDE_EFFECTS__ */\nfunction optional(wrapped, default_) {\n\treturn _standardSchema({\n\t\tkind: \"schema\",\n\t\ttype: \"optional\",\n\t\treference: optional,\n\t\texpects: `(${wrapped.expects} | undefined)`,\n\t\tasync: false,\n\t\twrapped,\n\t\tdefault: default_,\n\t\t\"~run\"(dataset, config$1) {\n\t\t\tif (dataset.value === void 0) {\n\t\t\t\tif (this.default !== void 0) dataset.value = /* @__PURE__ */ getDefault(this, dataset, config$1);\n\t\t\t\tif (dataset.value === void 0) {\n\t\t\t\t\tdataset.typed = true;\n\t\t\t\t\treturn dataset;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn this.wrapped[\"~run\"](dataset, config$1);\n\t\t}\n\t});\n}\n/* @__NO_SIDE_EFFECTS__ */\nfunction picklist(options, message$1) {\n\treturn _standardSchema({\n\t\tkind: \"schema\",\n\t\ttype: \"picklist\",\n\t\treference: picklist,\n\t\texpects: /* @__PURE__ */ _joinExpects(options.map(_stringify), \"|\"),\n\t\tasync: false,\n\t\toptions,\n\t\tmessage: message$1,\n\t\t\"~run\"(dataset, config$1) {\n\t\t\tif (this.options.includes(dataset.value)) dataset.typed = true;\n\t\t\telse _addIssue(this, \"type\", dataset, config$1);\n\t\t\treturn dataset;\n\t\t}\n\t});\n}\n/* @__NO_SIDE_EFFECTS__ */\nfunction record(key, value$1, message$1) {\n\treturn _standardSchema({\n\t\tkind: \"schema\",\n\t\ttype: \"record\",\n\t\treference: record,\n\t\texpects: \"Object\",\n\t\tasync: false,\n\t\tkey,\n\t\tvalue: value$1,\n\t\tmessage: message$1,\n\t\t\"~run\"(dataset, config$1) {\n\t\t\tconst input = dataset.value;\n\t\t\tif (input && typeof input === \"object\") {\n\t\t\t\tdataset.typed = true;\n\t\t\t\tdataset.value = {};\n\t\t\t\tfor (const entryKey in input) if (/* @__PURE__ */ _isValidObjectKey(input, entryKey)) {\n\t\t\t\t\tconst entryValue = input[entryKey];\n\t\t\t\t\tconst keyDataset = this.key[\"~run\"]({ value: entryKey }, config$1);\n\t\t\t\t\tif (keyDataset.issues) {\n\t\t\t\t\t\tconst pathItem = {\n\t\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\t\torigin: \"key\",\n\t\t\t\t\t\t\tinput,\n\t\t\t\t\t\t\tkey: entryKey,\n\t\t\t\t\t\t\tvalue: entryValue\n\t\t\t\t\t\t};\n\t\t\t\t\t\tfor (const issue of keyDataset.issues) {\n\t\t\t\t\t\t\tissue.path = [pathItem];\n\t\t\t\t\t\t\tdataset.issues?.push(issue);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (!dataset.issues) dataset.issues = keyDataset.issues;\n\t\t\t\t\t\tif (config$1.abortEarly) {\n\t\t\t\t\t\t\tdataset.typed = false;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tconst valueDataset = this.value[\"~run\"]({ value: entryValue }, config$1);\n\t\t\t\t\tif (valueDataset.issues) {\n\t\t\t\t\t\tconst pathItem = {\n\t\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\t\torigin: \"value\",\n\t\t\t\t\t\t\tinput,\n\t\t\t\t\t\t\tkey: entryKey,\n\t\t\t\t\t\t\tvalue: entryValue\n\t\t\t\t\t\t};\n\t\t\t\t\t\tfor (const issue of valueDataset.issues) {\n\t\t\t\t\t\t\tif (issue.path) issue.path.unshift(pathItem);\n\t\t\t\t\t\t\telse issue.path = [pathItem];\n\t\t\t\t\t\t\tdataset.issues?.push(issue);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (!dataset.issues) dataset.issues = valueDataset.issues;\n\t\t\t\t\t\tif (config$1.abortEarly) {\n\t\t\t\t\t\t\tdataset.typed = false;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (!keyDataset.typed || !valueDataset.typed) dataset.typed = false;\n\t\t\t\t\tif (keyDataset.typed) dataset.value[keyDataset.value] = valueDataset.value;\n\t\t\t\t}\n\t\t\t} else _addIssue(this, \"type\", dataset, config$1);\n\t\t\treturn dataset;\n\t\t}\n\t});\n}\n/* @__NO_SIDE_EFFECTS__ */\nfunction string(message$1) {\n\treturn _standardSchema({\n\t\tkind: \"schema\",\n\t\ttype: \"string\",\n\t\treference: string,\n\t\texpects: \"string\",\n\t\tasync: false,\n\t\tmessage: message$1,\n\t\t\"~run\"(dataset, config$1) {\n\t\t\tif (typeof dataset.value === \"string\") dataset.typed = true;\n\t\t\telse _addIssue(this, \"type\", dataset, config$1);\n\t\t\treturn dataset;\n\t\t}\n\t});\n}\n/**\n* Returns the sub issues of the provided datasets for the union issue.\n*\n* @param datasets The datasets.\n*\n* @returns The sub issues.\n*\n* @internal\n*/\n/* @__NO_SIDE_EFFECTS__ */\nfunction _subIssues(datasets) {\n\tlet issues;\n\tif (datasets) for (const dataset of datasets) if (issues) for (const issue of dataset.issues) issues.push(issue);\n\telse issues = dataset.issues;\n\treturn issues;\n}\n/* @__NO_SIDE_EFFECTS__ */\nfunction union(options, message$1) {\n\treturn _standardSchema({\n\t\tkind: \"schema\",\n\t\ttype: \"union\",\n\t\treference: union,\n\t\texpects: /* @__PURE__ */ _joinExpects(options.map((option) => option.expects), \"|\"),\n\t\tasync: false,\n\t\toptions,\n\t\tmessage: message$1,\n\t\t\"~run\"(dataset, config$1) {\n\t\t\tlet validDataset;\n\t\t\tlet typedDatasets;\n\t\t\tlet untypedDatasets;\n\t\t\tfor (const schema of this.options) {\n\t\t\t\tconst optionDataset = schema[\"~run\"]({ value: dataset.value }, config$1);\n\t\t\t\tif (optionDataset.typed) if (optionDataset.issues) if (typedDatasets) typedDatasets.push(optionDataset);\n\t\t\t\telse typedDatasets = [optionDataset];\n\t\t\t\telse {\n\t\t\t\t\tvalidDataset = optionDataset;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\telse if (untypedDatasets) untypedDatasets.push(optionDataset);\n\t\t\t\telse untypedDatasets = [optionDataset];\n\t\t\t}\n\t\t\tif (validDataset) return validDataset;\n\t\t\tif (typedDatasets) {\n\t\t\t\tif (typedDatasets.length === 1) return typedDatasets[0];\n\t\t\t\t_addIssue(this, \"type\", dataset, config$1, { issues: /* @__PURE__ */ _subIssues(typedDatasets) });\n\t\t\t\tdataset.typed = true;\n\t\t\t} else if (untypedDatasets?.length === 1) return untypedDatasets[0];\n\t\t\telse _addIssue(this, \"type\", dataset, config$1, { issues: /* @__PURE__ */ _subIssues(untypedDatasets) });\n\t\t\treturn dataset;\n\t\t}\n\t});\n}\n/**\n* Creates a unknown schema.\n*\n* @returns A unknown schema.\n*/\n/* @__NO_SIDE_EFFECTS__ */\nfunction unknown() {\n\treturn _standardSchema({\n\t\tkind: \"schema\",\n\t\ttype: \"unknown\",\n\t\treference: unknown,\n\t\texpects: \"unknown\",\n\t\tasync: false,\n\t\t\"~run\"(dataset) {\n\t\t\tdataset.typed = true;\n\t\t\treturn dataset;\n\t\t}\n\t});\n}\n/* @__NO_SIDE_EFFECTS__ */\nfunction variant(key, options, message$1) {\n\treturn _standardSchema({\n\t\tkind: \"schema\",\n\t\ttype: \"variant\",\n\t\treference: variant,\n\t\texpects: \"Object\",\n\t\tasync: false,\n\t\tkey,\n\t\toptions,\n\t\tmessage: message$1,\n\t\t\"~run\"(dataset, config$1) {\n\t\t\tconst input = dataset.value;\n\t\t\tif (input && typeof input === \"object\") {\n\t\t\t\tlet outputDataset;\n\t\t\t\tlet maxDiscriminatorPriority = 0;\n\t\t\t\tlet invalidDiscriminatorKey = this.key;\n\t\t\t\tlet expectedDiscriminators = [];\n\t\t\t\tconst parseOptions = (variant$1, allKeys) => {\n\t\t\t\t\tfor (const schema of variant$1.options) {\n\t\t\t\t\t\tif (schema.type === \"variant\") parseOptions(schema, new Set(allKeys).add(schema.key));\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tlet keysAreValid = true;\n\t\t\t\t\t\t\tlet currentPriority = 0;\n\t\t\t\t\t\t\tfor (const currentKey of allKeys) {\n\t\t\t\t\t\t\t\tconst discriminatorSchema = schema.entries[currentKey];\n\t\t\t\t\t\t\t\tif (currentKey in input ? discriminatorSchema[\"~run\"]({\n\t\t\t\t\t\t\t\t\ttyped: false,\n\t\t\t\t\t\t\t\t\tvalue: input[currentKey]\n\t\t\t\t\t\t\t\t}, ABORT_EARLY_CONFIG).issues : discriminatorSchema.type !== \"exact_optional\" && discriminatorSchema.type !== \"optional\" && discriminatorSchema.type !== \"nullish\") {\n\t\t\t\t\t\t\t\t\tkeysAreValid = false;\n\t\t\t\t\t\t\t\t\tif (invalidDiscriminatorKey !== currentKey && (maxDiscriminatorPriority < currentPriority || maxDiscriminatorPriority === currentPriority && currentKey in input && !(invalidDiscriminatorKey in input))) {\n\t\t\t\t\t\t\t\t\t\tmaxDiscriminatorPriority = currentPriority;\n\t\t\t\t\t\t\t\t\t\tinvalidDiscriminatorKey = currentKey;\n\t\t\t\t\t\t\t\t\t\texpectedDiscriminators = [];\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tif (invalidDiscriminatorKey === currentKey) expectedDiscriminators.push(schema.entries[currentKey].expects);\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tcurrentPriority++;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (keysAreValid) {\n\t\t\t\t\t\t\t\tconst optionDataset = schema[\"~run\"]({ value: input }, config$1);\n\t\t\t\t\t\t\t\tif (!outputDataset || !outputDataset.typed && optionDataset.typed) outputDataset = optionDataset;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (outputDataset && !outputDataset.issues) break;\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t\tparseOptions(this, /* @__PURE__ */ new Set([this.key]));\n\t\t\t\tif (outputDataset) return outputDataset;\n\t\t\t\t_addIssue(this, \"type\", dataset, config$1, {\n\t\t\t\t\tinput: input[invalidDiscriminatorKey],\n\t\t\t\t\texpected: /* @__PURE__ */ _joinExpects(expectedDiscriminators, \"|\"),\n\t\t\t\t\tpath: [{\n\t\t\t\t\t\ttype: \"object\",\n\t\t\t\t\t\torigin: \"value\",\n\t\t\t\t\t\tinput,\n\t\t\t\t\t\tkey: invalidDiscriminatorKey,\n\t\t\t\t\t\tvalue: input[invalidDiscriminatorKey]\n\t\t\t\t\t}]\n\t\t\t\t});\n\t\t\t} else _addIssue(this, \"type\", dataset, config$1);\n\t\t\treturn dataset;\n\t\t}\n\t});\n}\n/**\n* Parses an unknown input based on a schema.\n*\n* @param schema The schema to be used.\n* @param input The input to be parsed.\n* @param config The parse configuration.\n*\n* @returns The parsed input.\n*/\nfunction parse(schema, input, config$1) {\n\tconst dataset = schema[\"~run\"]({ value: input }, /* @__PURE__ */ getGlobalConfig(config$1));\n\tif (dataset.issues) throw new ValiError(dataset.issues);\n\treturn dataset.value;\n}\n/* @__NO_SIDE_EFFECTS__ */\nfunction pipe(...pipe$1) {\n\treturn _standardSchema({\n\t\t...pipe$1[0],\n\t\tpipe: pipe$1,\n\t\t\"~run\"(dataset, config$1) {\n\t\t\tfor (const item of pipe$1) if (item.kind !== \"metadata\") {\n\t\t\t\tif (dataset.issues && (item.kind === \"schema\" || item.kind === \"transformation\")) {\n\t\t\t\t\tdataset.typed = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif (!dataset.issues || !config$1.abortEarly && !config$1.abortPipeEarly) dataset = item[\"~run\"](dataset, config$1);\n\t\t\t}\n\t\t\treturn dataset;\n\t\t}\n\t});\n}\n// packages/factory/contracts/channel.ts\n/** A channel's config: `scope` is what it covers. Where a provider has a sensible default (GitHub: the outpost's repo), it's optional. */\nconst channelConfig = /* @__PURE__ */ object({ scope: /* @__PURE__ */ optional(/* @__PURE__ */ string()) });\n// packages/factory/lib/collect.ts\n/** A collected param only one contributor may set, e.g. an infra's one code host. */\nconst single = (items, context) => {\n\tif (items.length > 1) throw new ContributionConflictError(context.resourceId, context.param, [context.contributors[0](), context.contributors[1]()], [items[0], items[1]]);\n\treturn items[0];\n};\n// packages/factory/lib/binding-name.ts\n/**\n* Makes a binding name from a secret's id, such as `GH_PRIVATE_KEY` from\n* `gh-private-key`. A binding name is a JavaScript identifier, so each\n* character other than a letter, a digit or `_` becomes `_`.\n*/\nconst bindingName = (id) => {\n\tconst name = id.toUpperCase().replace(/[^A-Z0-9_]/g, \"_\");\n\treturn /^[0-9]/.test(name) ? `_${name}` : name;\n};\n// packages/factory/lib/scoped-name.ts\n/**\n* Makes the name of a resource that Notation doesn't name itself, such as a\n* KV namespace's title: `<app>--<stage>--<name>`, cut to `maxLength` with a\n* hash at the end. Outside a deploy, plan or viz there is no app and stage,\n* and the name is `name`.\n*/\nconst scopedName = (name, maxLength) => physicalName(getActiveResourceCollection()?.scope, name, { maxLength });\n// packages/factory/lib/outpost.ts\n/** The deployer's calls for the outpost of the repo it's deploying. Stubs: the deployer checks the config, builds its containers, and registers its triggers with the router. */\nconst putOutpost = async (_config) => {\n\tthrow new Error(\"not implemented: check the outpost's config, build its containers and register its triggers\");\n};\nconst readOutpost = async () => {\n\tthrow new Error(\"not implemented: read the outpost's deployed config\");\n};\nconst deleteOutpost = async () => {\n\tthrow new Error(\"not implemented: unroute the outpost and put its containers to sleep\");\n};\n// packages/factory/resources/outpost-config.ts\nconst channelEntry = /* @__PURE__ */ object({\n\tprovider: /* @__PURE__ */ string(),\n\tconnection: /* @__PURE__ */ string(),\n\tscope: /* @__PURE__ */ optional(/* @__PURE__ */ string())\n});\nconst containerEntry = /* @__PURE__ */ object({\n\timage: /* @__PURE__ */ string(),\n\truntimes: /* @__PURE__ */ array(/* @__PURE__ */ string()),\n\tpolicies: /* @__PURE__ */ array(/* @__PURE__ */ string()),\n\tfiles: /* @__PURE__ */ record(/* @__PURE__ */ string(), /* @__PURE__ */ union([/* @__PURE__ */ string(), /* @__PURE__ */ record(/* @__PURE__ */ string(), /* @__PURE__ */ unknown())]))\n});\nconst policyEntry = /* @__PURE__ */ looseObject({ provider: /* @__PURE__ */ string() });\nconst agentEntry = /* @__PURE__ */ looseObject({ runtime: /* @__PURE__ */ string() });\nconst triggerEntry = /* @__PURE__ */ object({\n\tchannel: /* @__PURE__ */ string(),\n\tevent: /* @__PURE__ */ string(),\n\tmatch: /* @__PURE__ */ unknown(),\n\tagent: /* @__PURE__ */ string(),\n\tcontainer: /* @__PURE__ */ string(),\n\tworktree: /* @__PURE__ */ optional(/* @__PURE__ */ object({ base: /* @__PURE__ */ optional(/* @__PURE__ */ string()) }))\n});\n/**\n* A repo's outpost, as the one entry the deployer applies. Its channels,\n* containers, policies, agents and triggers each contribute their part. The\n* deployer runs Notation for one repo at a time, and stores the entry under\n* that repo.\n*/\nconst OutpostConfig = resource({\n\ttype: \"factory/deployer/OutpostConfig\",\n\tprovider: \"@notation/factory\"\n}).defineSchema({\n\tchannels: {\n\t\tpropertyType: \"param\",\n\t\tpresence: \"optional\",\n\t\tvalue: /* @__PURE__ */ record(/* @__PURE__ */ string(), channelEntry),\n\t\tcollect: mergeContributions\n\t},\n\tcontainers: {\n\t\tpropertyType: \"param\",\n\t\tpresence: \"optional\",\n\t\tvalue: /* @__PURE__ */ record(/* @__PURE__ */ string(), containerEntry),\n\t\tcollect: mergeContributions\n\t},\n\tpolicies: {\n\t\tpropertyType: \"param\",\n\t\tpresence: \"optional\",\n\t\tvalue: /* @__PURE__ */ record(/* @__PURE__ */ string(), policyEntry),\n\t\tcollect: mergeContributions\n\t},\n\tagents: {\n\t\tpropertyType: \"param\",\n\t\tpresence: \"optional\",\n\t\tvalue: /* @__PURE__ */ record(/* @__PURE__ */ string(), agentEntry),\n\t\tcollect: mergeContributions\n\t},\n\ttriggers: {\n\t\tpropertyType: \"param\",\n\t\tpresence: \"optional\",\n\t\tvalue: /* @__PURE__ */ record(/* @__PURE__ */ string(), triggerEntry),\n\t\tcollect: mergeContributions\n\t}\n}).defineOperations({\n\tcreate: async (config) => putOutpost(config),\n\tread: async () => {\n\t\tawait readOutpost();\n\t\treturn {};\n\t},\n\tupdate: async (_key, _patch, config) => putOutpost(config),\n\tdelete: async () => deleteOutpost()\n});\n// packages/factory/implementations/outpost.ts\n/** A repo's outpost. Its channels, containers, policies, agents and triggers contribute to `store`, the one entry the deployer applies. */\nvar Outpost = class extends ResourceGroup {\n\tstore;\n\tconstructor(id) {\n\t\tsuper(\"factory/Outpost\", id, {});\n\t\tthis.store = this.add(new OutpostConfig(`${id}-config`, { config: {} }));\n\t}\n};\nconst outposts = /* @__PURE__ */ new WeakMap();\n/** The outpost of the graph being collected. The first outpost resource declared makes it. */\nconst currentOutpost = () => {\n\tconst collection = getActiveResourceCollection();\n\tif (!collection) throw new Error(\"Declare outpost resources in .factory/config.ts, which the deployer evaluates with Notation\");\n\tlet outpost = outposts.get(collection);\n\tif (!outpost) {\n\t\toutpost = new Outpost(\"outpost\");\n\t\toutposts.set(collection, outpost);\n\t}\n\treturn outpost;\n};\n/**\n* A group declared in an outpost's config. It contributes to that outpost,\n* without the user passing it.\n*/\nvar OutpostGroup = class extends ResourceGroup {\n\toutpost;\n\tconstructor(type, id, config) {\n\t\tsuper(type, id, config);\n\t\tthis.outpost = currentOutpost();\n\t}\n};\n// packages/factory/implementations/container.ts\nconst containerConfig = /* @__PURE__ */ object({\n\t/**\n\t* The container's Dockerfile, relative to `.factory/`, which builds with\n\t* `.factory/` as its context. Without it, the container gets Factory's\n\t* default image, which has Claude Code and Droid.\n\t*/\n\timage: /* @__PURE__ */ optional(/* @__PURE__ */ string()),\n\truntimes: /* @__PURE__ */ optional(/* @__PURE__ */ array(/* @__PURE__ */ custom((runtime) => typeof runtime === \"object\" && runtime !== null && typeof runtime.id === \"string\", \"A runtime is an object with an id.\")), []),\n\t/** `~/…` paths written to `/data/home` at startup: a string is a file in `.factory/`, an object is written as JSON. */\n\tfiles: /* @__PURE__ */ optional(/* @__PURE__ */ record(/* @__PURE__ */ string(), /* @__PURE__ */ union([/* @__PURE__ */ string(), /* @__PURE__ */ record(/* @__PURE__ */ string(), /* @__PURE__ */ unknown())])), {})\n});\n/** A repo's machine: its image, the runtimes its image installs, and the policies it may mint credentials for. */\nvar Container = class extends OutpostGroup {\n\truntimes;\n\tpolicies;\n\tconstructor(id, { policies = [], ...config }) {\n\t\tconst { image, runtimes, files } = parse(containerConfig, config);\n\t\tconst seen = /* @__PURE__ */ new Set();\n\t\tfor (const runtime of runtimes) {\n\t\t\tif (seen.has(runtime.id)) throw new Error(`container ${id} lists runtime ${runtime.id} twice`);\n\t\t\tseen.add(runtime.id);\n\t\t}\n\t\tsuper(\"factory/Container\", id, config);\n\t\tthis.runtimes = runtimes;\n\t\tthis.policies = policies;\n\t\tthis.outpost.store.contribute({ containers: { [id]: {\n\t\t\t...image && { image },\n\t\t\truntimes: runtimes.map((r) => r.id),\n\t\t\tpolicies: policies.map((p) => p.id),\n\t\t\tfiles\n\t\t} } });\n\t}\n};\n// packages/factory/implementations/policy.ts\nconst policyConfig = /* @__PURE__ */ object({\n\tprovider: /* @__PURE__ */ string(),\n\tscopes: /* @__PURE__ */ optional(/* @__PURE__ */ array(/* @__PURE__ */ string()), [])\n});\n/** A policy for credentials a plugin's `provider` mints. A code host's own policy (e.g. `github.Policy`) is typed by its provider. */\nvar Policy = class extends OutpostGroup {\n\tprovider;\n\tconstructor(id, config) {\n\t\tconst { provider, scopes } = parse(policyConfig, config);\n\t\tsuper(\"factory/Policy\", id, config);\n\t\tthis.provider = provider;\n\t\tthis.outpost.store.contribute({ policies: { [id]: {\n\t\t\tprovider,\n\t\t\tscopes\n\t\t} } });\n\t}\n};\n// packages/factory/implementations/trigger.ts\nconst triggerConfig = /* @__PURE__ */ object({ \n/** Where a worktree's branch is cut from if it doesn't exist yet. Default: the repo's default branch. */\nbase: /* @__PURE__ */ optional(/* @__PURE__ */ string()) });\n/**\n* The whole dispatch rule: this event, from these authors, to this agent, in\n* this container, on the branch `worktree` names. The container is data, so\n* the router knows what to wake. `worktree` isn't data, so it isn't in the\n* outpost's config: the deployer runs the repo's config again to call it\n* with the real event.\n*/\nvar Trigger = class extends OutpostGroup {\n\tagent;\n\tcontainer;\n\tchannel;\n\tconstructor(id, { agent, container, ...config }) {\n\t\tconst { event, worktree } = config;\n\t\tconst { base } = parse(triggerConfig, config);\n\t\tif (base !== void 0 && !worktree) throw new Error(`trigger ${id}: base is only used with a worktree`);\n\t\tif (!container.runtimes.some((r) => r.id === agent.runtime.id)) throw new Error(`trigger ${id}: container ${container.id} doesn't list runtime ${agent.runtime.id}, which agent ${agent.id} needs`);\n\t\tsuper(\"factory/Trigger\", id, config);\n\t\tthis.agent = agent;\n\t\tthis.container = container;\n\t\tthis.channel = event.channel;\n\t\tthis.outpost.store.contribute({ triggers: { [id]: {\n\t\t\tchannel: event.channel.id,\n\t\t\tevent: event.event,\n\t\t\tmatch: event.match,\n\t\t\tagent: agent.id,\n\t\t\tcontainer: container.id,\n\t\t\t...worktree && { worktree: { base } }\n\t\t} } });\n\t}\n};\nexport { variant as C, unknown as S, pipe as _, OutpostGroup as a, string as b, bindingName as c, array as d, literal as f, picklist as g, parse as h, Outpost as i, single as l, optional as m, Policy as n, OutpostConfig as o, object as p, Container as r, scopedName as s, Trigger as t, channelConfig as u, record as v, union as x, startsWith as y };\n"} as Record<string, string>;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * The packages that an outpost's config can import, each with the SDK module
3
+ * it resolves to. The SDK is built from each package's `factory-outpost`
4
+ * export, or its default export.
5
+ */
6
+ export const SDK_PACKAGES = {
7
+ "@notation/factory": "factory",
8
+ "@notation/factory-github": "factory-github",
9
+ "@notation/factory-claude": "factory-claude",
10
+ "@notation/factory-droid": "factory-droid",
11
+ "@notation/factory-slack": "factory-slack",
12
+ } as const;
13
+
14
+ /** The SDK module that runs a config and collects its outpost config. */
15
+ export const SDK_COLLECT = "collect";
16
+
17
+ /** The directory that SDK modules are under, among the modules evaluated. */
18
+ export const SDK_DIR = "sdk";
@@ -0,0 +1,67 @@
1
+ import * as v from "valibot";
2
+ import type { PolicyContract, Runtime } from "../contracts/outpost.ts";
3
+ import { OutpostGroup } from "./outpost.ts";
4
+
5
+ const containerConfig = v.object({
6
+ /**
7
+ * The container's Dockerfile, relative to `.factory/`, which builds with
8
+ * `.factory/` as its context. Without it, the container gets Factory's
9
+ * default image, which has Claude Code and Droid.
10
+ */
11
+ image: v.optional(v.string()),
12
+ runtimes: v.optional(
13
+ v.array(
14
+ v.custom<Runtime>(
15
+ (runtime) =>
16
+ typeof runtime === "object" &&
17
+ runtime !== null &&
18
+ typeof (runtime as { id?: unknown }).id === "string",
19
+ "A runtime is an object with an id.",
20
+ ),
21
+ ),
22
+ [],
23
+ ),
24
+ /** `~/…` paths written to `/data/home` at startup: a string is a file in `.factory/`, an object is written as JSON. */
25
+ files: v.optional(
26
+ v.record(
27
+ v.string(),
28
+ v.union([v.string(), v.record(v.string(), v.unknown())]),
29
+ ),
30
+ {},
31
+ ),
32
+ });
33
+ export type ContainerConfig = v.InferInput<typeof containerConfig>;
34
+
35
+ export type ContainerOptions = ContainerConfig & {
36
+ policies?: PolicyContract[];
37
+ };
38
+
39
+ /** A repo's machine: its image, the runtimes its image installs, and the policies it may mint credentials for. */
40
+ export class Container extends OutpostGroup<ContainerConfig> {
41
+ readonly runtimes: Runtime[];
42
+ readonly policies: PolicyContract[];
43
+
44
+ constructor(id: string, { policies = [], ...config }: ContainerOptions) {
45
+ const { image, runtimes, files } = v.parse(containerConfig, config);
46
+ const seen = new Set<string>();
47
+ for (const runtime of runtimes) {
48
+ if (seen.has(runtime.id)) {
49
+ throw new Error(`container ${id} lists runtime ${runtime.id} twice`);
50
+ }
51
+ seen.add(runtime.id);
52
+ }
53
+ super("factory/Container", id, config);
54
+ this.runtimes = runtimes;
55
+ this.policies = policies;
56
+ this.outpost.store.contribute({
57
+ containers: {
58
+ [id]: {
59
+ ...(image && { image }),
60
+ runtimes: runtimes.map((r) => r.id),
61
+ policies: policies.map((p) => p.id),
62
+ files,
63
+ },
64
+ },
65
+ });
66
+ }
67
+ }
@@ -0,0 +1,50 @@
1
+ import { getActiveResourceCollection, ResourceGroup } from "@notation/resource";
2
+ import {
3
+ OutpostConfig,
4
+ type OutpostConfigInstance,
5
+ } from "../resources/outpost-config.ts";
6
+
7
+ /** A repo's outpost. Its channels, containers, policies, agents and triggers contribute to `store`, the one entry the deployer applies. */
8
+ export class Outpost extends ResourceGroup {
9
+ readonly store: OutpostConfigInstance;
10
+
11
+ constructor(id: string) {
12
+ super("factory/Outpost", id, {});
13
+ this.store = this.add(new OutpostConfig(`${id}-config`, { config: {} }));
14
+ }
15
+ }
16
+
17
+ // One outpost for each collection, so a process can collect more than one
18
+ // outpost's graph.
19
+ const outposts = new WeakMap<object, Outpost>();
20
+
21
+ /** The outpost of the graph being collected. The first outpost resource declared makes it. */
22
+ const currentOutpost = (): Outpost => {
23
+ const collection = getActiveResourceCollection();
24
+ if (!collection) {
25
+ throw new Error(
26
+ "Declare outpost resources in .factory/config.ts, which the deployer evaluates with Notation",
27
+ );
28
+ }
29
+ let outpost = outposts.get(collection);
30
+ if (!outpost) {
31
+ outpost = new Outpost("outpost");
32
+ outposts.set(collection, outpost);
33
+ }
34
+ return outpost;
35
+ };
36
+
37
+ /**
38
+ * A group declared in an outpost's config. It contributes to that outpost,
39
+ * without the user passing it.
40
+ */
41
+ export abstract class OutpostGroup<
42
+ C extends Record<string, any> = Record<string, any>,
43
+ > extends ResourceGroup<C> {
44
+ readonly outpost: Outpost;
45
+
46
+ constructor(type: string, id: string, config?: C) {
47
+ super(type, id, config);
48
+ this.outpost = currentOutpost();
49
+ }
50
+ }
@@ -0,0 +1,26 @@
1
+ import * as v from "valibot";
2
+ import type { PolicyContract } from "../contracts/outpost.ts";
3
+ import { OutpostGroup } from "./outpost.ts";
4
+
5
+ const policyConfig = v.object({
6
+ provider: v.string(),
7
+ scopes: v.optional(v.array(v.string()), []),
8
+ });
9
+ export type PolicyConfig = v.InferInput<typeof policyConfig>;
10
+
11
+ export type PolicyOptions = PolicyConfig;
12
+
13
+ /** A policy for credentials a plugin's `provider` mints. A code host's own policy (e.g. `github.Policy`) is typed by its provider. */
14
+ export class Policy
15
+ extends OutpostGroup<PolicyConfig>
16
+ implements PolicyContract
17
+ {
18
+ readonly provider: string;
19
+
20
+ constructor(id: string, config: PolicyOptions) {
21
+ const { provider, scopes } = v.parse(policyConfig, config);
22
+ super("factory/Policy", id, config);
23
+ this.provider = provider;
24
+ this.outpost.store.contribute({ policies: { [id]: { provider, scopes } } });
25
+ }
26
+ }
@@ -0,0 +1,67 @@
1
+ import * as v from "valibot";
2
+ import type { Channel, Selector } from "../contracts/channel.ts";
3
+ import type { Agent } from "../contracts/outpost.ts";
4
+ import type { Container } from "./container.ts";
5
+ import { OutpostGroup } from "./outpost.ts";
6
+
7
+ const triggerConfig = v.object({
8
+ /** Where a worktree's branch is cut from if it doesn't exist yet. Default: the repo's default branch. */
9
+ base: v.optional(v.string()),
10
+ });
11
+
12
+ export type TriggerConfig<E> = v.InferInput<typeof triggerConfig> & {
13
+ event: Selector<E>;
14
+ /**
15
+ * Names the branch whose worktree the agent runs in, from the event.
16
+ * Returning `undefined`, or leaving it out, means no branch: a scratch
17
+ * worktree per conversation.
18
+ */
19
+ worktree?: (event: E) => string | undefined;
20
+ };
21
+
22
+ export type TriggerOptions<E> = TriggerConfig<E> & {
23
+ agent: Agent;
24
+ container: Container;
25
+ };
26
+
27
+ /**
28
+ * The whole dispatch rule: this event, from these authors, to this agent, in
29
+ * this container, on the branch `worktree` names. The container is data, so
30
+ * the router knows what to wake. `worktree` isn't data, so it isn't in the
31
+ * outpost's config: the deployer runs the repo's config again to call it
32
+ * with the real event.
33
+ */
34
+ export class Trigger<E> extends OutpostGroup<TriggerConfig<E>> {
35
+ readonly agent: Agent;
36
+ readonly container: Container;
37
+ readonly channel: Channel;
38
+
39
+ constructor(id: string, { agent, container, ...config }: TriggerOptions<E>) {
40
+ const { event, worktree } = config;
41
+ const { base } = v.parse(triggerConfig, config);
42
+ if (base !== undefined && !worktree) {
43
+ throw new Error(`trigger ${id}: base is only used with a worktree`);
44
+ }
45
+ if (!container.runtimes.some((r) => r.id === agent.runtime.id)) {
46
+ throw new Error(
47
+ `trigger ${id}: container ${container.id} doesn't list runtime ${agent.runtime.id}, which agent ${agent.id} needs`,
48
+ );
49
+ }
50
+ super("factory/Trigger", id, config);
51
+ this.agent = agent;
52
+ this.container = container;
53
+ this.channel = event.channel;
54
+ this.outpost.store.contribute({
55
+ triggers: {
56
+ [id]: {
57
+ channel: event.channel.id,
58
+ event: event.event,
59
+ match: event.match,
60
+ agent: agent.id,
61
+ container: container.id,
62
+ ...(worktree && { worktree: { base } }),
63
+ },
64
+ },
65
+ });
66
+ }
67
+ }
package/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from "./outpost.ts";
2
+ export { RandomKey, type RandomKeyInstance } from "./resources/random-key.ts";
3
+ export { RouterSync } from "./resources/router-sync.ts";
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Makes a binding name from a secret's id, such as `GH_PRIVATE_KEY` from
3
+ * `gh-private-key`. A binding name is a JavaScript identifier, so each
4
+ * character other than a letter, a digit or `_` becomes `_`.
5
+ */
6
+ export const bindingName = (id: string): string => {
7
+ const name = id.toUpperCase().replace(/[^A-Z0-9_]/g, "_");
8
+ return /^[0-9]/.test(name) ? `_${name}` : name;
9
+ };
package/lib/collect.ts ADDED
@@ -0,0 +1,21 @@
1
+ import {
2
+ type CollectContext,
3
+ ContributionConflictError,
4
+ type DeepPartial,
5
+ } from "@notation/resource";
6
+
7
+ /** A collected param only one contributor may set, e.g. an infra's one code host. */
8
+ export const single = <T>(
9
+ items: DeepPartial<T>[],
10
+ context: CollectContext,
11
+ ): T => {
12
+ if (items.length > 1) {
13
+ throw new ContributionConflictError(
14
+ context.resourceId,
15
+ context.param,
16
+ [context.contributors[0]!(), context.contributors[1]!()],
17
+ [items[0], items[1]],
18
+ );
19
+ }
20
+ return items[0] as T;
21
+ };
package/lib/outpost.ts ADDED
@@ -0,0 +1,17 @@
1
+ /** The deployer's calls for the outpost of the repo it's deploying. Stubs: the deployer checks the config, builds its containers, and registers its triggers with the router. */
2
+
3
+ export const putOutpost = async (_config: unknown): Promise<void> => {
4
+ throw new Error(
5
+ "not implemented: check the outpost's config, build its containers and register its triggers",
6
+ );
7
+ };
8
+
9
+ export const readOutpost = async (): Promise<unknown> => {
10
+ throw new Error("not implemented: read the outpost's deployed config");
11
+ };
12
+
13
+ export const deleteOutpost = async (): Promise<void> => {
14
+ throw new Error(
15
+ "not implemented: unroute the outpost and put its containers to sleep",
16
+ );
17
+ };
@@ -0,0 +1,10 @@
1
+ import { getActiveResourceCollection, physicalName } from "@notation/resource";
2
+
3
+ /**
4
+ * Makes the name of a resource that Notation doesn't name itself, such as a
5
+ * KV namespace's title: `<app>--<stage>--<name>`, cut to `maxLength` with a
6
+ * hash at the end. Outside a deploy, plan or viz there is no app and stage,
7
+ * and the name is `name`.
8
+ */
9
+ export const scopedName = (name: string, maxLength: number): string =>
10
+ physicalName(getActiveResourceCollection()?.scope, name, { maxLength });
package/outpost.ts ADDED
@@ -0,0 +1,12 @@
1
+ export * from "./contracts/index.ts";
2
+ export { single } from "./lib/collect.ts";
3
+ export { bindingName } from "./lib/binding-name.ts";
4
+ export { scopedName } from "./lib/scoped-name.ts";
5
+ export {
6
+ Container,
7
+ type ContainerOptions,
8
+ } from "./implementations/container.ts";
9
+ export { Outpost, OutpostGroup } from "./implementations/outpost.ts";
10
+ export { Policy, type PolicyOptions } from "./implementations/policy.ts";
11
+ export { Trigger, type TriggerOptions } from "./implementations/trigger.ts";
12
+ export { OutpostConfig } from "./resources/outpost-config.ts";