@lunora/config 1.0.0-alpha.44 → 1.0.0-alpha.441
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +135 -0
- package/README.md +3 -3
- package/dist/cli/index.d.mts +2 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.mjs +1 -0
- package/dist/cloudflare/index.d.mts +1336 -0
- package/dist/cloudflare/index.d.ts +1336 -0
- package/dist/cloudflare/index.mjs +1 -0
- package/dist/index.d.mts +962 -974
- package/dist/index.d.ts +962 -974
- package/dist/index.mjs +1 -23
- package/dist/packem_shared/ACCENT-CotPTfv7.mjs +7 -0
- package/dist/packem_shared/AGENT_MODE_ENV-D8MvSwPE.mjs +1 -0
- package/dist/packem_shared/AGENT_RULES_DIR-Bd6JPtNa.mjs +1 -0
- package/dist/packem_shared/ALLOW_FORWARDED_ENV-BUndghJx.mjs +1 -0
- package/dist/packem_shared/BINDING_MANIFEST_VERSION-CfXEYG8e.mjs +1 -0
- package/dist/packem_shared/BUILD_ROOT_ENV-Dg4MV3wY.mjs +1 -0
- package/dist/packem_shared/CLOUDFLARE_CLI_CONFIG_WARNING_ENV-BKMrOuXV.mjs +1 -0
- package/dist/packem_shared/CLOUDFLARE_DRIVER-DJwtY5NT.mjs +1 -0
- package/dist/packem_shared/CLOUDFLARE_TOOLCHAIN_VERSIONS-DV5E_f_q.mjs +1 -0
- package/dist/packem_shared/COMPOSED_WORKER_ENTRY-Ciiba5g_.mjs +1 -0
- package/dist/packem_shared/D1_PLACEHOLDER_ID-ZnDjVymH.mjs +1 -0
- package/dist/packem_shared/DEFAULT_DEPLOY_TARGET-D_krePy-.mjs +1 -0
- package/dist/packem_shared/DEFAULT_OBSERVABILITY-CPLADr5u.mjs +1 -0
- package/dist/packem_shared/DEV_BINDINGS_FILE-C0ZN_XlP.mjs +4 -0
- package/dist/packem_shared/DEV_VARS_EXAMPLE_FILE-CqLorAxT.mjs +6 -0
- package/dist/packem_shared/DEV_WORKER_ENV_VALUE-CgozgOxh.mjs +1 -0
- package/dist/packem_shared/GLOBAL_FETCH_STRICTLY_PUBLIC_FLAG-f8CnJha3.mjs +1 -0
- package/dist/packem_shared/LINKED_PROJECT_DIR-Ba5qPEwo.mjs +2 -0
- package/dist/packem_shared/LUNORA_EVENT_SOURCE-B9ZVohjO.mjs +1 -0
- package/dist/packem_shared/LUNORA_IGNORED_PATHS-U93uPxrW.mjs +19 -0
- package/dist/packem_shared/LUNORA_TAG-DQTGPqcJ.mjs +1 -0
- package/dist/packem_shared/LunoraReporter-f277GLNT.mjs +6 -0
- package/dist/packem_shared/MissingBuildOutputError-BAyekzof.mjs +1 -0
- package/dist/packem_shared/PACKAGE_SECRETS_REGISTRY-ByJhGJMf.mjs +1 -0
- package/dist/packem_shared/POLICY_SCAFFOLD_ENDPOINT-D5PpQPkf.mjs +1 -0
- package/dist/packem_shared/REMOTE_ELIGIBLE_KEYS-DooK0pzs.mjs +1 -0
- package/dist/packem_shared/REQUIRED_COMPATIBILITY_DATE-D4UcOP_t.mjs +1 -0
- package/dist/packem_shared/SCHEMA_EDIT_ENDPOINT-CtxWqfDe.mjs +1 -0
- package/dist/packem_shared/SEED_ENDPOINT-C1fhrehH.mjs +1 -0
- package/dist/packem_shared/STUDIO_PATH-Dc-3nLO6.mjs +1 -0
- package/dist/packem_shared/STUDIO_WRITE_TEMP_SUFFIX-BTTELz3K.mjs +1 -0
- package/dist/packem_shared/UNEXPORTED_CLASS_MARKER-B06-1J8H.mjs +1 -0
- package/dist/packem_shared/WORKERS_CACHE_MIN_DATE-0k9ABJtF.mjs +1 -0
- package/dist/packem_shared/WRANGLER_FILES-UNW-xY5u.mjs +1 -0
- package/dist/packem_shared/acceptsConnection-DHhUYGjT.mjs +2 -0
- package/dist/packem_shared/addArgsFor-CYZKhNIo.mjs +1 -0
- package/dist/packem_shared/applyAdditiveEdit-DEwPKcJg.mjs +6 -0
- package/dist/packem_shared/applyModify-DKP2l6S9.mjs +1 -0
- package/dist/packem_shared/assertBuildTargetMatches-t0UvJp_O.mjs +1 -0
- package/dist/packem_shared/assertWranglerSatisfiesSchema-CNwRRCbB.mjs +3 -0
- package/dist/packem_shared/assetContentType-CUb5bpbI.mjs +1 -0
- package/dist/packem_shared/bindingsNeedingDatabase-6eD6Qtqf.mjs +3 -0
- package/dist/packem_shared/blockingFindingsMessage-CRbg1sla.mjs +1 -0
- package/dist/packem_shared/buildPackageSecretsBlock-GvaLgvFN.mjs +19 -0
- package/dist/packem_shared/canonicalPath-DrfMiT3U.mjs +1 -0
- package/dist/packem_shared/celld-binding-id-9MiUoteo.mjs +1 -0
- package/dist/packem_shared/celld-config-DoBVipuN.mjs +3 -0
- package/dist/packem_shared/classifyPolicyEdit-DJi9Fk8G.mjs +24 -0
- package/dist/packem_shared/clearApiSpecMarker-DMGpP41V.mjs +2 -0
- package/dist/packem_shared/collectExportGaps-B53R2mba.mjs +2 -0
- package/dist/packem_shared/createConfirm-D5mKTMHj.mjs +7 -0
- package/dist/packem_shared/createDiscoveryCache-npJI4uej.mjs +1 -0
- package/dist/packem_shared/createStudioDocumentCache-B3Sf1bIl.mjs +1 -0
- package/dist/packem_shared/deploy-driver.d-BqO40t1Q.d.mts +186 -0
- package/dist/packem_shared/deploy-driver.d-BqO40t1Q.d.ts +186 -0
- package/dist/packem_shared/describePreservedCrons-Bt2rPPeY.mjs +1 -0
- package/dist/packem_shared/describeWithheld-CbyzZjZF.mjs +1 -0
- package/dist/packem_shared/detectFramework-Dfpvu6rD.mjs +1 -0
- package/dist/packem_shared/devVariablesStamp-Cetr3qFz.mjs +1 -0
- package/dist/packem_shared/discover-info-DC2MrAIM.mjs +1 -0
- package/dist/packem_shared/discoverAgentInfo-pqFMJBtJ.mjs +1 -0
- package/dist/packem_shared/discoverContainerInfo-DzXr7Vm3.mjs +1 -0
- package/dist/packem_shared/discoverSchemaInfo-DRPnqgif.mjs +1 -0
- package/dist/packem_shared/discoverWorkflowInfo-zW7Tt0Tn.mjs +1 -0
- package/dist/packem_shared/ensureGitignoreEntries-Tsk8Qkw7.mjs +7 -0
- package/dist/packem_shared/guards-Buu_E7mP.mjs +1 -0
- package/dist/packem_shared/hasCloudflareCredentials-Bak5w1_6.mjs +1 -0
- package/dist/packem_shared/index.d-BuYbPa9W.d.ts +270 -0
- package/dist/packem_shared/index.d-CGlT0loP.d.mts +270 -0
- package/dist/packem_shared/infer-bindings.d-BUdWC3tw.d.mts +323 -0
- package/dist/packem_shared/infer-bindings.d-BUdWC3tw.d.ts +323 -0
- package/dist/packem_shared/inferLunoraBindings-DvB8IpbN.mjs +1 -0
- package/dist/packem_shared/materializeServiceDevConfigs-qUY4_iu1.mjs +1 -0
- package/dist/packem_shared/mergeWranglerEnvironment-D5ekKj5x.mjs +1 -0
- package/dist/packem_shared/package-secrets-registry-UQ_uEAB_.mjs +1 -0
- package/dist/packem_shared/parseSchema-D1Wbr1qv.mjs +1 -0
- package/dist/packem_shared/policy-scaffold.d-D2H4_G01.d.mts +86 -0
- package/dist/packem_shared/policy-scaffold.d-D2H4_G01.d.ts +86 -0
- package/dist/packem_shared/probeCelldToolchain-DxDttfHy.mjs +1 -0
- package/dist/packem_shared/process-tree-once-Ou4SfxKM.mjs +1 -0
- package/dist/packem_shared/readManifest-Cighz3WC.mjs +6 -0
- package/dist/packem_shared/readProjectDependencies-l3uhUKjo.mjs +1 -0
- package/dist/packem_shared/reconcile-services-C4TwY8YH.mjs +1 -0
- package/dist/packem_shared/reconcileBindingsSafely-t02cOkaF.mjs +1 -0
- package/dist/packem_shared/reconcileWranglerCompatibilityDate-hocXEuRA.mjs +1 -0
- package/dist/packem_shared/renderStudioHtml-ByowDtMl.mjs +15 -0
- package/dist/packem_shared/resolveSchemaDirectory-Ca5P6KuP.mjs +1 -0
- package/dist/packem_shared/runPostCodegenHook-Dx3yTsYZ.mjs +1 -0
- package/dist/packem_shared/scanWranglerVariablesForSecrets-DRBYlMYb.mjs +1 -0
- package/dist/packem_shared/sendStudioAsset-XBmVLqiI.mjs +1 -0
- package/dist/packem_shared/serveJsonHandler-B8_GE6QC.mjs +1 -0
- package/dist/packem_shared/startCelldDevSession-BKRiLvt-.mjs +1 -0
- package/dist/packem_shared/streamContainerLogs-0nko1qpv.mjs +2 -0
- package/dist/packem_shared/validate-bindings-PVHSAU6M.mjs +1 -0
- package/dist/packem_shared/withTailConsumer-CF3pk_Ov.mjs +1 -0
- package/dist/packem_shared/worker-entry-checks-AIASCYl7.mjs +1 -0
- package/dist/packem_shared/wranglerCodegenInputs-BZamZrPz.mjs +1 -0
- package/dist/packem_shared/wranglerToAlchemy-CBO2ucRm.mjs +6 -0
- package/dist/packem_shared/write-atomic-DRRKWKF-.mjs +3 -0
- package/dist/studio-host/index.d.mts +358 -136
- package/dist/studio-host/index.d.ts +358 -136
- package/dist/studio-host/index.mjs +1 -7
- package/package.json +32 -7
- package/dist/packem_shared/ACCENT-DW1XJn8i.mjs +0 -40
- package/dist/packem_shared/AGENT_RULES_DIR-lcgC08aE.mjs +0 -40
- package/dist/packem_shared/DEV_VARS_EXAMPLE_FILE-dJPNTEnK.mjs +0 -37
- package/dist/packem_shared/LINKED_PROJECT_DIR-CXwXzV_C.mjs +0 -52
- package/dist/packem_shared/LUNORA_CONFIG_FILE-CtcIcB5-.mjs +0 -34
- package/dist/packem_shared/LUNORA_EVENT_SOURCE-D2fDeGB6.mjs +0 -86
- package/dist/packem_shared/LunoraReporter-Ci-bDCK9.mjs +0 -70
- package/dist/packem_shared/PACKAGE_SECRETS_REGISTRY-B8t_SdoZ.mjs +0 -70
- package/dist/packem_shared/POLICY_SCAFFOLD_ENDPOINT-CiC2IGKx.mjs +0 -103
- package/dist/packem_shared/REMOTE_ELIGIBLE_KEYS-BC7_e9Bz.mjs +0 -105
- package/dist/packem_shared/REQUIRED_COMPATIBILITY_DATE-2YYyWJUq.mjs +0 -561
- package/dist/packem_shared/SCHEMA_EDIT_ENDPOINT-Df-Wrix-.mjs +0 -99
- package/dist/packem_shared/SEED_ENDPOINT-DVCjaGO-.mjs +0 -61
- package/dist/packem_shared/WRANGLER_FILES-DwSuC-Kn.mjs +0 -25
- package/dist/packem_shared/applyAdditiveEdit-C-snTFEV.mjs +0 -228
- package/dist/packem_shared/assetContentType-ByZjeV3D.mjs +0 -72
- package/dist/packem_shared/buildPackageSecretsBlock-BCHtfQ2A.mjs +0 -280
- package/dist/packem_shared/classifyPolicyEdit-BHeAqF8P.mjs +0 -99
- package/dist/packem_shared/createConfirm-fvpdgJ9s.mjs +0 -100
- package/dist/packem_shared/detectFramework-Br-BcPBq.mjs +0 -41
- package/dist/packem_shared/discoverContainerInfo-BXFs6Wav.mjs +0 -19
- package/dist/packem_shared/discoverSchemaInfo-BB-CKlTK.mjs +0 -25
- package/dist/packem_shared/discoverWorkflowInfo-CedvR0mn.mjs +0 -19
- package/dist/packem_shared/inferLunoraBindings-ByMwG-gH.mjs +0 -352
- package/dist/packem_shared/parseDevVariable-CJiq2IwE.mjs +0 -30
- package/dist/packem_shared/parseSchema-DSeyktvG.mjs +0 -107
- package/dist/packem_shared/policy-scaffold.d-DCmwn7zQ.d.mts +0 -74
- package/dist/packem_shared/policy-scaffold.d-DCmwn7zQ.d.ts +0 -74
- package/dist/packem_shared/reconcileWranglerBindings-Cruwwx1M.mjs +0 -334
- package/dist/packem_shared/renderStudioHtml-449Ysn75.mjs +0 -37
- package/dist/packem_shared/serveJsonHandler-B4OLTGLS.mjs +0 -86
- package/dist/packem_shared/streamContainerLogs-BZ4cOZwH.mjs +0 -157
|
@@ -1,334 +0,0 @@
|
|
|
1
|
-
import { writeFileSync } from 'node:fs';
|
|
2
|
-
import { containerBuildTag } from '@lunora/container';
|
|
3
|
-
import { modify, applyEdits } from 'jsonc-parser';
|
|
4
|
-
import { findWranglerFile, readWranglerJsonc } from './WRANGLER_FILES-DwSuC-Kn.mjs';
|
|
5
|
-
|
|
6
|
-
const FORMATTING = { formattingOptions: { insertSpaces: true, tabSize: 4 } };
|
|
7
|
-
const D1_PLACEHOLDER_ID = "<replace-with-d1-create-id>";
|
|
8
|
-
const collectExportGaps = (inferred) => {
|
|
9
|
-
const gaps = [];
|
|
10
|
-
for (const container of inferred.containers) {
|
|
11
|
-
if (!container.exported) {
|
|
12
|
-
gaps.push({ className: container.className, exportName: container.exportName, kind: "container", module: "containers" });
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
for (const workflow of inferred.workflows) {
|
|
16
|
-
if (!workflow.exported) {
|
|
17
|
-
gaps.push({ className: workflow.className, exportName: workflow.exportName, kind: "workflow", module: "workflows" });
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return gaps;
|
|
21
|
-
};
|
|
22
|
-
const collectHintBindingWarnings = (inferred, parsed) => {
|
|
23
|
-
const flagshipBindingMissing = inferred.flagshipBinding !== void 0 && !(parsed?.flagship ?? []).some((entry) => entry.binding === inferred.flagshipBinding);
|
|
24
|
-
const rules = [
|
|
25
|
-
[
|
|
26
|
-
inferred.usesKv && (parsed?.kv_namespaces?.length ?? 0) === 0,
|
|
27
|
-
"@lunora/bindings/kv is used but no kv_namespaces binding exists; add a kv_namespaces entry ({ binding, id }) and pass env.<BINDING> to createKv() — the namespace id can't be auto-provisioned."
|
|
28
|
-
],
|
|
29
|
-
[
|
|
30
|
-
inferred.usesHyperdrive && (parsed?.hyperdrive?.length ?? 0) === 0,
|
|
31
|
-
"@lunora/hyperdrive is used but no hyperdrive binding exists; run 'wrangler hyperdrive create' and add a 'hyperdrive' binding ({ binding, id }) — the id can't be auto-provisioned."
|
|
32
|
-
],
|
|
33
|
-
[
|
|
34
|
-
inferred.usesPipelines && (parsed?.pipelines?.length ?? 0) === 0,
|
|
35
|
-
"ctx.pipelines is used but no pipelines binding exists; run 'wrangler pipelines create <name>' and add a 'pipelines' binding ({ binding, pipeline }) — the pipeline resource can't be auto-provisioned."
|
|
36
|
-
],
|
|
37
|
-
[
|
|
38
|
-
flagshipBindingMissing,
|
|
39
|
-
`lunora/flags.ts uses Flagship in binding mode but no flagship binding "${inferred.flagshipBinding ?? ""}" exists; add a flagship entry ({ binding: "${inferred.flagshipBinding ?? ""}", app_id }) — the app_id can't be auto-provisioned.`
|
|
40
|
-
]
|
|
41
|
-
];
|
|
42
|
-
return rules.filter(([active]) => active).map(([, warning]) => warning);
|
|
43
|
-
};
|
|
44
|
-
const collectWarnings = (inferred, parsed) => {
|
|
45
|
-
const exported = new Set(inferred.durableObjects.map((object) => object.className));
|
|
46
|
-
const warnings = [];
|
|
47
|
-
const hasR2Bucket = (parsed?.r2_buckets?.length ?? 0) > 0;
|
|
48
|
-
const hasSessionStore = (parsed?.d1_databases?.some((binding) => binding.binding === "DB") ?? false) || inferred.needsD1;
|
|
49
|
-
if (inferred.usesStorage && !hasR2Bucket) {
|
|
50
|
-
warnings.push(
|
|
51
|
-
"@lunora/storage is used but R2 bucket bindings have user-defined names; add an r2_buckets entry and pass env.<BINDING> to createStorage()."
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
if (inferred.usesAuth && !exported.has("SessionDO") && !hasSessionStore) {
|
|
55
|
-
warnings.push(
|
|
56
|
-
"@lunora/auth is used but the worker entry exports no SessionDO; sessions are D1-backed, or export SessionDO to enable DO-backed sessions."
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
if (inferred.usesScheduler && !exported.has("SchedulerDO")) {
|
|
60
|
-
warnings.push("@lunora/scheduler is used but the worker entry exports no SchedulerDO; export it so the SCHEDULER binding can be provisioned.");
|
|
61
|
-
}
|
|
62
|
-
for (const container of inferred.containers) {
|
|
63
|
-
if (!container.exported) {
|
|
64
|
-
warnings.push(
|
|
65
|
-
`container "${container.exportName}" is declared but ${container.className} is not exported by the worker entry; add \`export * from "./lunora/_generated/containers"\` so its binding can be provisioned.`
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
for (const workflow of inferred.workflows) {
|
|
70
|
-
if (!workflow.exported) {
|
|
71
|
-
warnings.push(
|
|
72
|
-
`workflow "${workflow.exportName}" is declared but ${workflow.className} is not exported by the worker entry; add \`export * from "./lunora/_generated/workflows"\` so its binding can be provisioned.`
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
if (inferred.containers.length > 0 && parsed?.observability?.enabled === false) {
|
|
77
|
-
warnings.push("containers are declared but observability is explicitly disabled in wrangler.jsonc — container logs will not be captured.");
|
|
78
|
-
}
|
|
79
|
-
if (inferred.usesPayment) {
|
|
80
|
-
warnings.push(
|
|
81
|
-
"@lunora/payment is used; set the provider secrets in .dev.vars — STRIPE_SECRET_KEY + STRIPE_WEBHOOK_SECRET (Stripe) or POLAR_ACCESS_TOKEN + POLAR_WEBHOOK_SECRET (Polar)."
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
warnings.push(...collectHintBindingWarnings(inferred, parsed));
|
|
85
|
-
return warnings;
|
|
86
|
-
};
|
|
87
|
-
const applyModify = (text, path, value) => {
|
|
88
|
-
const edits = modify(text, [...path], value, FORMATTING);
|
|
89
|
-
return edits.length > 0 ? applyEdits(text, edits) : text;
|
|
90
|
-
};
|
|
91
|
-
const nextMigrationTag = (migrations) => {
|
|
92
|
-
const used = new Set(migrations.map((migration) => migration.tag));
|
|
93
|
-
let index = 1;
|
|
94
|
-
while (used.has(`v${String(index)}`)) {
|
|
95
|
-
index += 1;
|
|
96
|
-
}
|
|
97
|
-
return `v${String(index)}`;
|
|
98
|
-
};
|
|
99
|
-
const reconcileDurableObjects = (text, parsed, required) => {
|
|
100
|
-
const existingBindings = parsed.durable_objects?.bindings ?? [];
|
|
101
|
-
const existingNames = new Set(existingBindings.map((binding) => binding.name));
|
|
102
|
-
const missing = required.filter((object) => !existingNames.has(object.binding));
|
|
103
|
-
let nextText = text;
|
|
104
|
-
const added = [];
|
|
105
|
-
if (missing.length > 0) {
|
|
106
|
-
const nextBindings = [
|
|
107
|
-
...existingBindings,
|
|
108
|
-
...missing.map((object) => {
|
|
109
|
-
return { class_name: object.className, name: object.binding };
|
|
110
|
-
})
|
|
111
|
-
];
|
|
112
|
-
nextText = applyModify(nextText, ["durable_objects", "bindings"], nextBindings);
|
|
113
|
-
added.push(...missing.map((object) => `${object.binding}/${object.className}`));
|
|
114
|
-
}
|
|
115
|
-
const migrations = parsed.migrations ?? [];
|
|
116
|
-
const registered = new Set(migrations.flatMap((migration) => [...migration.new_sqlite_classes ?? [], ...migration.new_classes ?? []]));
|
|
117
|
-
const missingClasses = required.map((object) => object.className).filter((className) => !registered.has(className));
|
|
118
|
-
if (missingClasses.length > 0) {
|
|
119
|
-
const nextMigrations = [...migrations, { new_sqlite_classes: missingClasses, tag: nextMigrationTag(migrations) }];
|
|
120
|
-
nextText = applyModify(nextText, ["migrations"], nextMigrations);
|
|
121
|
-
}
|
|
122
|
-
return { added, text: nextText };
|
|
123
|
-
};
|
|
124
|
-
const reconcileD1 = (text, parsed) => {
|
|
125
|
-
const d1Bindings = parsed.d1_databases ?? [];
|
|
126
|
-
if (d1Bindings.some((binding) => binding.binding === "DB")) {
|
|
127
|
-
return { added: [], text };
|
|
128
|
-
}
|
|
129
|
-
const databaseName = typeof parsed.name === "string" && parsed.name.length > 0 ? parsed.name : "lunora";
|
|
130
|
-
const nextD1 = [...d1Bindings, { binding: "DB", database_id: D1_PLACEHOLDER_ID, database_name: databaseName }];
|
|
131
|
-
return { added: ["DB (D1)"], text: applyModify(text, ["d1_databases"], nextD1) };
|
|
132
|
-
};
|
|
133
|
-
const reconcileSelfDescribing = (text, parsed, key, binding, label) => {
|
|
134
|
-
const current = parsed[key]?.binding;
|
|
135
|
-
if (typeof current === "string" && current.length > 0) {
|
|
136
|
-
return { added: [], text };
|
|
137
|
-
}
|
|
138
|
-
return { added: [label], text: applyModify(text, [key], { binding }) };
|
|
139
|
-
};
|
|
140
|
-
const reconcileAnalytics = (text, parsed) => {
|
|
141
|
-
if ((parsed.analytics_engine_datasets?.length ?? 0) > 0) {
|
|
142
|
-
return { added: [], text };
|
|
143
|
-
}
|
|
144
|
-
const nextDatasets = [{ binding: "ANALYTICS", dataset: "ANALYTICS" }];
|
|
145
|
-
return { added: ["ANALYTICS (Analytics Engine)"], text: applyModify(text, ["analytics_engine_datasets"], nextDatasets) };
|
|
146
|
-
};
|
|
147
|
-
const wranglerInstanceType = (instanceType) => {
|
|
148
|
-
if (typeof instanceType === "string") {
|
|
149
|
-
return instanceType;
|
|
150
|
-
}
|
|
151
|
-
const custom = {};
|
|
152
|
-
if (instanceType.diskMb !== void 0) {
|
|
153
|
-
custom.disk_mb = instanceType.diskMb;
|
|
154
|
-
}
|
|
155
|
-
if (instanceType.memoryMib !== void 0) {
|
|
156
|
-
custom.memory_mib = instanceType.memoryMib;
|
|
157
|
-
}
|
|
158
|
-
if (instanceType.vcpu !== void 0) {
|
|
159
|
-
custom.vcpu = instanceType.vcpu;
|
|
160
|
-
}
|
|
161
|
-
return custom;
|
|
162
|
-
};
|
|
163
|
-
const imageRefFor = (container) => {
|
|
164
|
-
if (container.image.kind === "dockerfile") {
|
|
165
|
-
return container.image.dockerfilePath;
|
|
166
|
-
}
|
|
167
|
-
if (container.image.kind === "registry") {
|
|
168
|
-
return container.image.reference;
|
|
169
|
-
}
|
|
170
|
-
return containerBuildTag(container.exportName);
|
|
171
|
-
};
|
|
172
|
-
const containerEntryFor = (container) => {
|
|
173
|
-
const entry = {
|
|
174
|
-
class_name: container.className,
|
|
175
|
-
image: imageRefFor(container)
|
|
176
|
-
};
|
|
177
|
-
if (container.image.kind === "dockerfile") {
|
|
178
|
-
entry.image_build_context = container.image.buildContext;
|
|
179
|
-
}
|
|
180
|
-
if (container.buildArgs !== void 0 && container.image.kind !== "registry") {
|
|
181
|
-
entry.image_vars = container.buildArgs;
|
|
182
|
-
}
|
|
183
|
-
if (container.instanceType !== void 0) {
|
|
184
|
-
entry.instance_type = wranglerInstanceType(container.instanceType);
|
|
185
|
-
}
|
|
186
|
-
if (container.maxInstances !== void 0) {
|
|
187
|
-
entry.max_instances = container.maxInstances;
|
|
188
|
-
}
|
|
189
|
-
if (container.name !== void 0) {
|
|
190
|
-
entry.name = container.name;
|
|
191
|
-
}
|
|
192
|
-
if (container.rollout?.stepPercentage !== void 0) {
|
|
193
|
-
entry.rollout_step_percentage = container.rollout.stepPercentage;
|
|
194
|
-
}
|
|
195
|
-
if (container.rollout?.gracePeriodSeconds !== void 0) {
|
|
196
|
-
entry.rollout_active_grace_period = container.rollout.gracePeriodSeconds;
|
|
197
|
-
}
|
|
198
|
-
return entry;
|
|
199
|
-
};
|
|
200
|
-
const reconcileContainers = (text, parsed, containers) => {
|
|
201
|
-
const existing = parsed.containers ?? [];
|
|
202
|
-
const existingClasses = new Set(existing.map((entry) => entry.class_name));
|
|
203
|
-
const missing = containers.filter((container) => !existingClasses.has(container.className));
|
|
204
|
-
if (missing.length === 0) {
|
|
205
|
-
return { added: [], text };
|
|
206
|
-
}
|
|
207
|
-
const nextText = applyModify(text, ["containers"], [...existing, ...missing.map((container) => containerEntryFor(container))]);
|
|
208
|
-
return { added: missing.map((container) => `containers/${container.className}`), text: nextText };
|
|
209
|
-
};
|
|
210
|
-
const reconcileObservability = (text, parsed) => {
|
|
211
|
-
if (parsed.observability !== void 0) {
|
|
212
|
-
return { added: [], text };
|
|
213
|
-
}
|
|
214
|
-
const nextText = applyModify(text, ["observability"], { enabled: true, head_sampling_rate: 1 });
|
|
215
|
-
return { added: ["observability"], text: nextText };
|
|
216
|
-
};
|
|
217
|
-
const workflowEntryFor = (workflow) => {
|
|
218
|
-
return { binding: workflow.bindingName, class_name: workflow.className, name: workflow.name };
|
|
219
|
-
};
|
|
220
|
-
const reconcileWorkflows = (text, parsed, workflows) => {
|
|
221
|
-
const existing = parsed.workflows ?? [];
|
|
222
|
-
const existingClasses = new Set(existing.map((entry) => entry.class_name));
|
|
223
|
-
const missing = workflows.filter((workflow) => !existingClasses.has(workflow.className));
|
|
224
|
-
if (missing.length === 0) {
|
|
225
|
-
return { added: [], text };
|
|
226
|
-
}
|
|
227
|
-
const nextText = applyModify(text, ["workflows"], [...existing, ...missing.map((workflow) => workflowEntryFor(workflow))]);
|
|
228
|
-
return { added: missing.map((workflow) => `workflows/${workflow.className}`), text: nextText };
|
|
229
|
-
};
|
|
230
|
-
const reconcileQueues = (text, parsed, queues) => {
|
|
231
|
-
const existing = parsed.queues ?? {};
|
|
232
|
-
const existingProducers = existing.producers ?? [];
|
|
233
|
-
const existingConsumers = existing.consumers ?? [];
|
|
234
|
-
const haveProducer = new Set(existingProducers.map((entry) => entry.binding));
|
|
235
|
-
const haveConsumer = new Set(existingConsumers.map((entry) => entry.queue));
|
|
236
|
-
const missingProducers = queues.filter((queue) => !haveProducer.has(queue.bindingName));
|
|
237
|
-
const missingConsumers = queues.filter((queue) => !haveConsumer.has(queue.name));
|
|
238
|
-
if (missingProducers.length === 0 && missingConsumers.length === 0) {
|
|
239
|
-
return { added: [], text };
|
|
240
|
-
}
|
|
241
|
-
const nextProducers = [
|
|
242
|
-
...existingProducers,
|
|
243
|
-
...missingProducers.map((queue) => {
|
|
244
|
-
return { binding: queue.bindingName, queue: queue.name };
|
|
245
|
-
})
|
|
246
|
-
];
|
|
247
|
-
const nextConsumers = [
|
|
248
|
-
...existingConsumers,
|
|
249
|
-
...missingConsumers.map((queue) => {
|
|
250
|
-
const consumer = { queue: queue.name };
|
|
251
|
-
if (queue.mode === "pull") {
|
|
252
|
-
consumer.type = "http_pull";
|
|
253
|
-
}
|
|
254
|
-
if (queue.tuning.maxBatchSize !== void 0) {
|
|
255
|
-
consumer.max_batch_size = queue.tuning.maxBatchSize;
|
|
256
|
-
}
|
|
257
|
-
if (queue.tuning.maxBatchTimeout !== void 0) {
|
|
258
|
-
consumer.max_batch_timeout = queue.tuning.maxBatchTimeout;
|
|
259
|
-
}
|
|
260
|
-
if (queue.tuning.maxRetries !== void 0) {
|
|
261
|
-
consumer.max_retries = queue.tuning.maxRetries;
|
|
262
|
-
}
|
|
263
|
-
if (queue.tuning.deadLetterQueue !== void 0) {
|
|
264
|
-
consumer.dead_letter_queue = queue.tuning.deadLetterQueue;
|
|
265
|
-
}
|
|
266
|
-
if (queue.tuning.retryDelay !== void 0) {
|
|
267
|
-
consumer.retry_delay = queue.tuning.retryDelay;
|
|
268
|
-
}
|
|
269
|
-
return consumer;
|
|
270
|
-
})
|
|
271
|
-
];
|
|
272
|
-
const nextText = applyModify(text, ["queues"], { consumers: nextConsumers, producers: nextProducers });
|
|
273
|
-
return {
|
|
274
|
-
added: [
|
|
275
|
-
...missingProducers.map((queue) => `queues.producers/${queue.bindingName}`),
|
|
276
|
-
...missingConsumers.map((queue) => `queues.consumers/${queue.name}`)
|
|
277
|
-
],
|
|
278
|
-
text: nextText
|
|
279
|
-
};
|
|
280
|
-
};
|
|
281
|
-
const reconcileWranglerBindings = (projectRoot, inferred) => {
|
|
282
|
-
const wranglerPath = findWranglerFile(projectRoot);
|
|
283
|
-
const exportGaps = collectExportGaps(inferred);
|
|
284
|
-
if (!wranglerPath) {
|
|
285
|
-
return { added: [], changed: false, exportGaps, reason: "wrangler.jsonc not found", warnings: collectWarnings(inferred) };
|
|
286
|
-
}
|
|
287
|
-
const { parsed, text: original } = readWranglerJsonc(wranglerPath);
|
|
288
|
-
if (parsed === void 0) {
|
|
289
|
-
return { added: [], changed: false, exportGaps, reason: `failed to parse ${wranglerPath} as JSONC`, warnings: collectWarnings(inferred), wranglerPath };
|
|
290
|
-
}
|
|
291
|
-
const warnings = collectWarnings(inferred, parsed);
|
|
292
|
-
const exportedContainers = inferred.containers.filter((container) => container.exported);
|
|
293
|
-
const requiredDurableObjects = [
|
|
294
|
-
...inferred.durableObjects,
|
|
295
|
-
...exportedContainers.map((container) => {
|
|
296
|
-
return { binding: container.bindingName, className: container.className };
|
|
297
|
-
})
|
|
298
|
-
];
|
|
299
|
-
const exportedWorkflows = inferred.workflows.filter((workflow) => workflow.exported);
|
|
300
|
-
const pipeline = [
|
|
301
|
-
{ enabled: true, run: (text2) => reconcileDurableObjects(text2, parsed, requiredDurableObjects) },
|
|
302
|
-
{ enabled: inferred.needsD1, run: (text2) => reconcileD1(text2, parsed) },
|
|
303
|
-
{ enabled: inferred.usesAi, run: (text2) => reconcileSelfDescribing(text2, parsed, "ai", "AI", "AI (Workers AI)") },
|
|
304
|
-
{ enabled: inferred.usesBrowser, run: (text2) => reconcileSelfDescribing(text2, parsed, "browser", "BROWSER", "BROWSER (Browser Rendering)") },
|
|
305
|
-
{ enabled: inferred.usesImages, run: (text2) => reconcileSelfDescribing(text2, parsed, "images", "IMAGES", "IMAGES (Cloudflare Images)") },
|
|
306
|
-
{ enabled: inferred.usesAnalytics, run: (text2) => reconcileAnalytics(text2, parsed) },
|
|
307
|
-
{ enabled: true, run: (text2) => reconcileObservability(text2, parsed) },
|
|
308
|
-
{ enabled: exportedContainers.length > 0, run: (text2) => reconcileContainers(text2, parsed, exportedContainers) },
|
|
309
|
-
{ enabled: exportedWorkflows.length > 0, run: (text2) => reconcileWorkflows(text2, parsed, exportedWorkflows) },
|
|
310
|
-
{ enabled: inferred.queues.length > 0, run: (text2) => reconcileQueues(text2, parsed, inferred.queues) }
|
|
311
|
-
];
|
|
312
|
-
let text = original;
|
|
313
|
-
const added = [];
|
|
314
|
-
for (const step of pipeline) {
|
|
315
|
-
if (!step.enabled) {
|
|
316
|
-
continue;
|
|
317
|
-
}
|
|
318
|
-
const result = step.run(text);
|
|
319
|
-
text = result.text;
|
|
320
|
-
added.push(...result.added);
|
|
321
|
-
}
|
|
322
|
-
if (added.includes("DB (D1)")) {
|
|
323
|
-
warnings.push(
|
|
324
|
-
`wrote a DB binding with a placeholder database_id ("${D1_PLACEHOLDER_ID}") — run \`wrangler d1 create <name>\` and replace it before deploying.`
|
|
325
|
-
);
|
|
326
|
-
}
|
|
327
|
-
if (text === original) {
|
|
328
|
-
return { added: [], changed: false, exportGaps, reason: "bindings already in sync", warnings, wranglerPath };
|
|
329
|
-
}
|
|
330
|
-
writeFileSync(wranglerPath, text, "utf8");
|
|
331
|
-
return { added, changed: true, exportGaps, warnings, wranglerPath };
|
|
332
|
-
};
|
|
333
|
-
|
|
334
|
-
export { reconcileWranglerBindings };
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
const forInlineScript = (value) => JSON.stringify(value).replaceAll("<", String.raw`\u003c`);
|
|
2
|
-
const forAttribute = (value) => value.replaceAll("&", "&").replaceAll('"', """).replaceAll("<", "<");
|
|
3
|
-
const renderStudioHtml = (config) => {
|
|
4
|
-
const settings = [`window.__LUNORA_BASE_PATH__=${forInlineScript(config.basePath)};`];
|
|
5
|
-
if (config.adminToken !== void 0 && config.adminToken !== "") {
|
|
6
|
-
settings.push(`window.__LUNORA_ADMIN_TOKEN__=${forInlineScript(config.adminToken)};`);
|
|
7
|
-
}
|
|
8
|
-
if (config.dataEditable === true) {
|
|
9
|
-
settings.push("window.__LUNORA_DATA_EDITABLE__=true;");
|
|
10
|
-
}
|
|
11
|
-
if (config.runAsIdentity === true) {
|
|
12
|
-
settings.push("window.__LUNORA_RUN_AS_IDENTITY__=true;");
|
|
13
|
-
}
|
|
14
|
-
if (config.schemaEditable === true) {
|
|
15
|
-
settings.push("window.__LUNORA_SCHEMA_EDITABLE__=true;");
|
|
16
|
-
}
|
|
17
|
-
if (config.rulesInstalled === false) {
|
|
18
|
-
settings.push("window.__LUNORA_RULES_INSTALLED__=false;");
|
|
19
|
-
}
|
|
20
|
-
return `<!doctype html>
|
|
21
|
-
<html lang="en">
|
|
22
|
-
<head>
|
|
23
|
-
<meta charset="UTF-8" />
|
|
24
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
25
|
-
<title>Lunora Studio</title>
|
|
26
|
-
<script>${settings.join("")}<\/script>
|
|
27
|
-
<link rel="stylesheet" href="${forAttribute(config.styleHref)}" />
|
|
28
|
-
</head>
|
|
29
|
-
<body>
|
|
30
|
-
<div id="root"></div>
|
|
31
|
-
<script type="module" src="${forAttribute(config.scriptSrc)}"><\/script>
|
|
32
|
-
</body>
|
|
33
|
-
</html>
|
|
34
|
-
`;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export { renderStudioHtml as default };
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
const MAX_BODY_BYTES = 1e6;
|
|
2
|
-
const readBody = async (request) => await new Promise((resolve, reject) => {
|
|
3
|
-
const chunks = [];
|
|
4
|
-
let size = 0;
|
|
5
|
-
request.on("data", (chunk) => {
|
|
6
|
-
size += chunk.length;
|
|
7
|
-
if (size > MAX_BODY_BYTES) {
|
|
8
|
-
reject(new Error("request body too large"));
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
|
-
chunks.push(chunk);
|
|
12
|
-
});
|
|
13
|
-
request.on("end", () => {
|
|
14
|
-
resolve(Buffer.concat(chunks).toString("utf8"));
|
|
15
|
-
});
|
|
16
|
-
request.on("error", reject);
|
|
17
|
-
});
|
|
18
|
-
const respondJson = (response, status, body) => {
|
|
19
|
-
response.statusCode = status;
|
|
20
|
-
response.setHeader("Content-Type", "application/json; charset=utf-8");
|
|
21
|
-
response.end(JSON.stringify(body));
|
|
22
|
-
};
|
|
23
|
-
const headerValue = (raw) => {
|
|
24
|
-
const value = Array.isArray(raw) ? raw[0] : raw;
|
|
25
|
-
return typeof value === "string" ? value.trim().toLowerCase() : void 0;
|
|
26
|
-
};
|
|
27
|
-
const SAME_SITE_FETCH_VALUES = /* @__PURE__ */ new Set(["none", "same-origin", "same-site"]);
|
|
28
|
-
const originRejectionReason = (request) => {
|
|
29
|
-
const secFetchSite = headerValue(request.headers["sec-fetch-site"]);
|
|
30
|
-
if (secFetchSite !== void 0) {
|
|
31
|
-
return SAME_SITE_FETCH_VALUES.has(secFetchSite) ? void 0 : "cross-origin request rejected";
|
|
32
|
-
}
|
|
33
|
-
const origin = headerValue(request.headers.origin);
|
|
34
|
-
if (origin === void 0 || origin === "null") {
|
|
35
|
-
return void 0;
|
|
36
|
-
}
|
|
37
|
-
let originHost;
|
|
38
|
-
try {
|
|
39
|
-
originHost = new URL(origin).host.toLowerCase();
|
|
40
|
-
} catch {
|
|
41
|
-
return "invalid origin header";
|
|
42
|
-
}
|
|
43
|
-
return originHost === headerValue(request.headers.host) ? void 0 : "cross-origin request rejected";
|
|
44
|
-
};
|
|
45
|
-
const csrfRejectionReason = (request) => {
|
|
46
|
-
const method = (request.method ?? "GET").toUpperCase();
|
|
47
|
-
const isStateChanging = method !== "GET" && method !== "HEAD";
|
|
48
|
-
const originReason = originRejectionReason(request);
|
|
49
|
-
if (originReason !== void 0) {
|
|
50
|
-
return originReason;
|
|
51
|
-
}
|
|
52
|
-
if (isStateChanging) {
|
|
53
|
-
const contentType = headerValue(request.headers["content-type"]);
|
|
54
|
-
if (!contentType?.startsWith("application/json")) {
|
|
55
|
-
return "content-type must be application/json";
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return void 0;
|
|
59
|
-
};
|
|
60
|
-
const serveJsonHandler = (request, response, handle, projectRoot) => {
|
|
61
|
-
const run = async () => {
|
|
62
|
-
try {
|
|
63
|
-
const rejection = csrfRejectionReason(request);
|
|
64
|
-
if (rejection !== void 0) {
|
|
65
|
-
respondJson(response, 403, { error: rejection, ok: false });
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
const raw = request.method === "GET" ? "" : await readBody(request);
|
|
69
|
-
let parsed;
|
|
70
|
-
try {
|
|
71
|
-
parsed = raw === "" ? void 0 : JSON.parse(raw);
|
|
72
|
-
} catch {
|
|
73
|
-
respondJson(response, 400, { error: "invalid-json", ok: false });
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
const result = handle({ body: parsed, method: request.method ?? "POST", projectRoot });
|
|
77
|
-
respondJson(response, result.status, result.body);
|
|
78
|
-
} catch (error) {
|
|
79
|
-
respondJson(response, 500, { error: error instanceof Error ? error.message : String(error), ok: false });
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
run().catch(() => {
|
|
83
|
-
});
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
export { serveJsonHandler };
|
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
import { Writable } from 'node:stream';
|
|
2
|
-
import { StringDecoder } from 'node:string_decoder';
|
|
3
|
-
|
|
4
|
-
const DEV_CONTAINER_IMAGE_PREFIX = "cloudflare-dev/";
|
|
5
|
-
const DEFAULT_POLL_INTERVAL_MS = 1500;
|
|
6
|
-
const createDefaultDocker = async () => {
|
|
7
|
-
const { default: Dockerode } = await import('dockerode');
|
|
8
|
-
return new Dockerode();
|
|
9
|
-
};
|
|
10
|
-
const classFromImage = (image) => {
|
|
11
|
-
if (!image.startsWith(DEV_CONTAINER_IMAGE_PREFIX)) {
|
|
12
|
-
return void 0;
|
|
13
|
-
}
|
|
14
|
-
const [segment] = image.slice(DEV_CONTAINER_IMAGE_PREFIX.length).split(":");
|
|
15
|
-
return segment !== void 0 && segment.length > 0 ? segment : void 0;
|
|
16
|
-
};
|
|
17
|
-
const lineBufferWritable = (emit) => {
|
|
18
|
-
const decoder = new StringDecoder("utf8");
|
|
19
|
-
let buffer = "";
|
|
20
|
-
const flushLine = (line) => {
|
|
21
|
-
emit(line.endsWith("\r") ? line.slice(0, -1) : line);
|
|
22
|
-
};
|
|
23
|
-
return new Writable({
|
|
24
|
-
final(callback) {
|
|
25
|
-
buffer += decoder.end();
|
|
26
|
-
if (buffer.length > 0) {
|
|
27
|
-
flushLine(buffer);
|
|
28
|
-
buffer = "";
|
|
29
|
-
}
|
|
30
|
-
callback();
|
|
31
|
-
},
|
|
32
|
-
write(chunk, _encoding, callback) {
|
|
33
|
-
buffer += decoder.write(chunk);
|
|
34
|
-
const lines = buffer.split("\n");
|
|
35
|
-
buffer = lines.pop() ?? "";
|
|
36
|
-
for (const line of lines) {
|
|
37
|
-
flushLine(line);
|
|
38
|
-
}
|
|
39
|
-
callback();
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
};
|
|
43
|
-
const streamContainerLogs = (options) => {
|
|
44
|
-
const classToExport = new Map(options.containers.map((source) => [source.className.toLowerCase(), source.exportName]));
|
|
45
|
-
if (classToExport.size === 0) {
|
|
46
|
-
return { close: () => {
|
|
47
|
-
} };
|
|
48
|
-
}
|
|
49
|
-
const interval = options.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS;
|
|
50
|
-
const attached = /* @__PURE__ */ new Map();
|
|
51
|
-
let closed = false;
|
|
52
|
-
let unavailableNotified = false;
|
|
53
|
-
let timer;
|
|
54
|
-
let dockerPromise;
|
|
55
|
-
const getDocker = async () => {
|
|
56
|
-
dockerPromise ??= options.docker ? Promise.resolve(options.docker) : createDefaultDocker();
|
|
57
|
-
return dockerPromise;
|
|
58
|
-
};
|
|
59
|
-
const attach = async (docker, id, exportName) => {
|
|
60
|
-
try {
|
|
61
|
-
const stream = await docker.getContainer(id).logs({ follow: true, stderr: true, stdout: true, tail: "all", timestamps: false });
|
|
62
|
-
if (closed) {
|
|
63
|
-
stream.destroy();
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
const stdout = lineBufferWritable((text) => {
|
|
67
|
-
options.onLine({ level: "info", name: exportName, text });
|
|
68
|
-
});
|
|
69
|
-
const stderr = lineBufferWritable((text) => {
|
|
70
|
-
options.onLine({ level: "error", name: exportName, text });
|
|
71
|
-
});
|
|
72
|
-
docker.modem.demuxStream(stream, stdout, stderr);
|
|
73
|
-
stream.on("end", () => {
|
|
74
|
-
stdout.end();
|
|
75
|
-
stderr.end();
|
|
76
|
-
attached.delete(id);
|
|
77
|
-
});
|
|
78
|
-
stream.on("error", () => {
|
|
79
|
-
attached.delete(id);
|
|
80
|
-
});
|
|
81
|
-
attached.set(id, stream);
|
|
82
|
-
} catch {
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
const listRunning = async () => {
|
|
86
|
-
try {
|
|
87
|
-
const docker = await getDocker();
|
|
88
|
-
const running = await docker.listContainers({ filters: { status: ["running"] } });
|
|
89
|
-
unavailableNotified = false;
|
|
90
|
-
return running;
|
|
91
|
-
} catch (error) {
|
|
92
|
-
if (!unavailableNotified) {
|
|
93
|
-
unavailableNotified = true;
|
|
94
|
-
options.onUnavailable?.(error instanceof Error ? error.message : String(error));
|
|
95
|
-
}
|
|
96
|
-
return void 0;
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
const reconcile = async (docker, running) => {
|
|
100
|
-
const live = /* @__PURE__ */ new Set();
|
|
101
|
-
for (const summary of running) {
|
|
102
|
-
const className = classFromImage(summary.Image);
|
|
103
|
-
const exportName = className === void 0 ? void 0 : classToExport.get(className);
|
|
104
|
-
if (exportName === void 0) {
|
|
105
|
-
continue;
|
|
106
|
-
}
|
|
107
|
-
live.add(summary.Id);
|
|
108
|
-
if (!attached.has(summary.Id)) {
|
|
109
|
-
await attach(docker, summary.Id, exportName);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
for (const [id, stream] of attached) {
|
|
113
|
-
if (!live.has(id)) {
|
|
114
|
-
stream.destroy();
|
|
115
|
-
attached.delete(id);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
const poll = async () => {
|
|
120
|
-
if (closed) {
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
const running = await listRunning();
|
|
124
|
-
if (running === void 0) {
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
await reconcile(await getDocker(), running);
|
|
128
|
-
};
|
|
129
|
-
let polling = false;
|
|
130
|
-
const onTick = () => {
|
|
131
|
-
if (polling || closed) {
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
polling = true;
|
|
135
|
-
poll().finally(() => {
|
|
136
|
-
polling = false;
|
|
137
|
-
}).catch(() => void 0);
|
|
138
|
-
};
|
|
139
|
-
timer = setInterval(onTick, interval);
|
|
140
|
-
timer.unref();
|
|
141
|
-
onTick();
|
|
142
|
-
return {
|
|
143
|
-
close: () => {
|
|
144
|
-
closed = true;
|
|
145
|
-
if (timer) {
|
|
146
|
-
clearInterval(timer);
|
|
147
|
-
timer = void 0;
|
|
148
|
-
}
|
|
149
|
-
for (const [id, stream] of attached) {
|
|
150
|
-
stream.destroy();
|
|
151
|
-
attached.delete(id);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
export { streamContainerLogs };
|