devflare 1.0.0-next.23 → 1.0.0-next.24

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.
Files changed (47) hide show
  1. package/LLM.md +77 -2
  2. package/dist/account-5nm1xn0v.js +475 -0
  3. package/dist/browser.d.ts +22 -2
  4. package/dist/browser.d.ts.map +1 -1
  5. package/dist/build-vctfnmsf.js +54 -0
  6. package/dist/cli/commands/deploy/prepare.d.ts.map +1 -1
  7. package/dist/cli/commands/deploy.d.ts.map +1 -1
  8. package/dist/cli/index.js +1 -1
  9. package/dist/config/schema-env.d.ts +22 -2
  10. package/dist/config/schema-env.d.ts.map +1 -1
  11. package/dist/config/schema-runtime.d.ts +11 -1
  12. package/dist/config/schema-runtime.d.ts.map +1 -1
  13. package/dist/config/schema-types-runtime.d.ts +3 -0
  14. package/dist/config/schema-types-runtime.d.ts.map +1 -1
  15. package/dist/config/schema-types.d.ts +2 -2
  16. package/dist/config/schema.d.ts +33 -3
  17. package/dist/config/schema.d.ts.map +1 -1
  18. package/dist/config-rq32csms.js +105 -0
  19. package/dist/deploy-krj3k9zm.js +1055 -0
  20. package/dist/deploy-mem96qyn.js +1066 -0
  21. package/dist/dev-apkr7cfv.js +2597 -0
  22. package/dist/doctor-9asw8x18.js +259 -0
  23. package/dist/index-4j9ah79n.js +1033 -0
  24. package/dist/index-bfjpjs07.js +581 -0
  25. package/dist/index-cna43592.js +1573 -0
  26. package/dist/index-d00njc1f.js +147 -0
  27. package/dist/index-dgeamyfk.js +1426 -0
  28. package/dist/index-ftf7yqhs.js +74 -0
  29. package/dist/index-h332fg62.js +1205 -0
  30. package/dist/index-ja2rdbt0.js +476 -0
  31. package/dist/index-kc207nyr.js +52 -0
  32. package/dist/index-meq8ydc0.js +895 -0
  33. package/dist/index-myfjejs0.js +185 -0
  34. package/dist/index-qkfvd3cs.js +109 -0
  35. package/dist/index-rnz879kf.js +1426 -0
  36. package/dist/index-s96e5dd9.js +699 -0
  37. package/dist/index.js +3 -3
  38. package/dist/login-g9rb7dj3.js +77 -0
  39. package/dist/previews-ykamw25e.js +1337 -0
  40. package/dist/productions-4m1pd6ts.js +505 -0
  41. package/dist/secrets-gywxctdh.js +91 -0
  42. package/dist/sveltekit/index.js +3 -3
  43. package/dist/test/index.js +6 -6
  44. package/dist/types-17kkqw37.js +705 -0
  45. package/dist/vite/index.js +4 -4
  46. package/dist/worker-4fd49jm0.js +513 -0
  47. package/package.json +1 -1
@@ -0,0 +1,185 @@
1
+ import {
2
+ resolveConfigForEnvironment
3
+ } from "./index-cna43592.js";
4
+
5
+ // src/cli/commands/previews-support/family.ts
6
+ function compareConfiguredWorkerFamilies(left, right) {
7
+ if (left.role === "primary" && right.role !== "primary") {
8
+ return -1;
9
+ }
10
+ if (left.role !== "primary" && right.role === "primary") {
11
+ return 1;
12
+ }
13
+ return left.baseName.localeCompare(right.baseName);
14
+ }
15
+ function comparePreviewScopeRows(left, right) {
16
+ const leftTime = left.updatedAt?.getTime() ?? 0;
17
+ const rightTime = right.updatedAt?.getTime() ?? 0;
18
+ if (rightTime !== leftTime) {
19
+ return rightTime - leftTime;
20
+ }
21
+ return left.scope.localeCompare(right.scope);
22
+ }
23
+ function collectConfiguredWorkerFamilies(config, environment) {
24
+ const resolvedConfig = resolveConfigForEnvironment(config, environment);
25
+ const families = new Map;
26
+ families.set(resolvedConfig.name, {
27
+ baseName: resolvedConfig.name,
28
+ roleLabel: "primary",
29
+ role: "primary"
30
+ });
31
+ for (const [bindingName, binding] of Object.entries(resolvedConfig.bindings?.services ?? {})) {
32
+ const existing = families.get(binding.service);
33
+ if (existing) {
34
+ continue;
35
+ }
36
+ families.set(binding.service, {
37
+ baseName: binding.service,
38
+ roleLabel: bindingName,
39
+ role: "service"
40
+ });
41
+ }
42
+ return Array.from(families.values()).sort(compareConfiguredWorkerFamilies);
43
+ }
44
+ function getWorkerUrl(workerName, workersSubdomain) {
45
+ if (!workersSubdomain) {
46
+ return;
47
+ }
48
+ return `https://${workerName}.${workersSubdomain}.workers.dev`;
49
+ }
50
+ function getWorkerScopeSuffix(workerName, baseName) {
51
+ if (!workerName.startsWith(`${baseName}-`)) {
52
+ return;
53
+ }
54
+ const suffix = workerName.slice(baseName.length + 1).trim();
55
+ return suffix || undefined;
56
+ }
57
+ function buildStableWorkerRowsFromLiveWorkers(families, workers, workersSubdomain) {
58
+ const workersByName = new Map(workers.map((worker) => [worker.name, worker]));
59
+ return families.map((family) => {
60
+ const worker = workersByName.get(family.baseName);
61
+ const status = worker ? "active" : "missing";
62
+ return {
63
+ workerName: family.baseName,
64
+ role: family.roleLabel,
65
+ status,
66
+ updatedAt: worker?.modifiedOn,
67
+ url: worker ? getWorkerUrl(family.baseName, workersSubdomain) : undefined
68
+ };
69
+ });
70
+ }
71
+ function getDedicatedPreviewFamilyNamesFromWorkers(families, workers) {
72
+ const familyNames = new Set;
73
+ const workerNames = workers.map((worker) => worker.name);
74
+ for (const family of families) {
75
+ if (family.role === "primary") {
76
+ familyNames.add(family.baseName);
77
+ continue;
78
+ }
79
+ if (workerNames.some((workerName) => Boolean(getWorkerScopeSuffix(workerName, family.baseName)))) {
80
+ familyNames.add(family.baseName);
81
+ }
82
+ }
83
+ return familyNames;
84
+ }
85
+ function buildPreviewScopeRowsFromLiveWorkers(families, workers, workersSubdomain) {
86
+ const workersByName = new Map(workers.map((worker) => [worker.name, worker]));
87
+ const previewFamilyNames = getDedicatedPreviewFamilyNamesFromWorkers(families, workers);
88
+ const expectedFamilies = families.filter((family) => previewFamilyNames.has(family.baseName));
89
+ const workerCandidatesByScope = buildPreviewWorkerCandidatesByScope(families, workers);
90
+ return Array.from(workerCandidatesByScope.keys()).map((scope) => {
91
+ const resolvedFamilies = expectedFamilies.map((family) => ({
92
+ family,
93
+ worker: workersByName.get(`${family.baseName}-${scope}`)
94
+ }));
95
+ const presentFamilies = resolvedFamilies.filter((entry) => entry.worker);
96
+ const updatedAt = presentFamilies.reduce((latest, entry) => {
97
+ const currentDate = entry.worker?.modifiedOn;
98
+ if (!currentDate) {
99
+ return latest;
100
+ }
101
+ if (!latest || currentDate.getTime() > latest.getTime()) {
102
+ return currentDate;
103
+ }
104
+ return latest;
105
+ }, undefined);
106
+ const primaryEntry = resolvedFamilies.find((entry) => entry.family.role === "primary");
107
+ const entryWorker = primaryEntry?.worker ?? presentFamilies[0]?.worker;
108
+ const missingLabels = resolvedFamilies.filter((entry) => !entry.worker).map((entry) => entry.family.role === "primary" ? "primary" : entry.family.roleLabel);
109
+ const notes = [];
110
+ if (missingLabels.length > 0) {
111
+ notes.push(`missing ${missingLabels.join(", ")}`);
112
+ }
113
+ const strategy = "dedicated workers";
114
+ const status = presentFamilies.length === resolvedFamilies.length ? "ready" : "partial";
115
+ return {
116
+ scope,
117
+ strategy,
118
+ workersLabel: `${presentFamilies.length}/${resolvedFamilies.length}`,
119
+ status,
120
+ updatedAt,
121
+ notes: notes.length > 0 ? notes.join(" · ") : undefined,
122
+ entryUrl: entryWorker ? getWorkerUrl(entryWorker.name, workersSubdomain) : undefined
123
+ };
124
+ }).sort(comparePreviewScopeRows);
125
+ }
126
+ function buildPreviewWorkerCandidatesByScope(families, workers) {
127
+ const candidates = new Map;
128
+ for (const worker of workers) {
129
+ for (const family of families) {
130
+ const scope = getWorkerScopeSuffix(worker.name, family.baseName);
131
+ if (!scope) {
132
+ continue;
133
+ }
134
+ const names = candidates.get(scope) ?? new Set;
135
+ names.add(worker.name);
136
+ candidates.set(scope, names);
137
+ }
138
+ }
139
+ return new Map(Array.from(candidates.entries()).map(([scope, workerNames]) => {
140
+ return [scope, Array.from(workerNames).sort((left, right) => left.localeCompare(right))];
141
+ }));
142
+ }
143
+ function orderPreviewWorkerNamesForDeletion(workerNames, scope, families) {
144
+ const familyPriority = new Map;
145
+ for (const family of families) {
146
+ familyPriority.set(family.baseName, {
147
+ priority: family.role === "primary" ? 0 : 1,
148
+ roleLabel: family.roleLabel
149
+ });
150
+ }
151
+ const resolveFamilyForWorker = (workerName) => {
152
+ for (const family of families) {
153
+ if (getWorkerScopeSuffix(workerName, family.baseName) === scope) {
154
+ const resolved = familyPriority.get(family.baseName);
155
+ if (resolved) {
156
+ return {
157
+ priority: resolved.priority,
158
+ roleLabel: resolved.roleLabel,
159
+ baseName: family.baseName
160
+ };
161
+ }
162
+ }
163
+ }
164
+ return {
165
+ priority: 2,
166
+ roleLabel: workerName
167
+ };
168
+ };
169
+ return [...workerNames].sort((left, right) => {
170
+ const leftFamily = resolveFamilyForWorker(left);
171
+ const rightFamily = resolveFamilyForWorker(right);
172
+ if (leftFamily.priority !== rightFamily.priority) {
173
+ return leftFamily.priority - rightFamily.priority;
174
+ }
175
+ if (leftFamily.roleLabel !== rightFamily.roleLabel) {
176
+ return leftFamily.roleLabel.localeCompare(rightFamily.roleLabel);
177
+ }
178
+ if (leftFamily.baseName && rightFamily.baseName && leftFamily.baseName !== rightFamily.baseName) {
179
+ return leftFamily.baseName.localeCompare(rightFamily.baseName);
180
+ }
181
+ return left.localeCompare(right);
182
+ });
183
+ }
184
+
185
+ export { collectConfiguredWorkerFamilies, buildStableWorkerRowsFromLiveWorkers, buildPreviewScopeRowsFromLiveWorkers, buildPreviewWorkerCandidatesByScope, orderPreviewWorkerNamesForDeletion };
@@ -0,0 +1,109 @@
1
+ import {
2
+ bundleWorkerEntry
3
+ } from "./index-meq8ydc0.js";
4
+ import {
5
+ DEFAULT_WORKFLOW_PATTERN,
6
+ findFiles
7
+ } from "./index-qwgr4q7s.js";
8
+ import {
9
+ normalizeWorkflowBinding
10
+ } from "./index-cna43592.js";
11
+
12
+ // src/workflows/local-workflow-entrypoints.ts
13
+ import { mkdir, readFile, writeFile } from "node:fs/promises";
14
+ import { join, relative, resolve } from "pathe";
15
+ function findExportedClasses(code) {
16
+ const classes = [];
17
+ const classPattern = /export\s+class\s+(\w+)/g;
18
+ let match;
19
+ while ((match = classPattern.exec(code)) !== null) {
20
+ classes.push(match[1]);
21
+ }
22
+ return classes;
23
+ }
24
+ function toImportSpecifier(fromDir, filePath) {
25
+ const relativePath = relative(fromDir, filePath).replace(/\\/g, "/");
26
+ return relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
27
+ }
28
+ async function discoverWorkflowClasses(config, configDir) {
29
+ const classToFilePath = new Map;
30
+ const workflowPatternConfig = config.files?.workflows;
31
+ const workflowPattern = typeof workflowPatternConfig === "string" ? workflowPatternConfig : DEFAULT_WORKFLOW_PATTERN;
32
+ if (workflowPatternConfig === false) {
33
+ return classToFilePath;
34
+ }
35
+ const files = await findFiles(workflowPattern, { cwd: configDir });
36
+ for (const filePath of files) {
37
+ try {
38
+ const code = await readFile(filePath, "utf-8");
39
+ for (const className of findExportedClasses(code)) {
40
+ classToFilePath.set(className, filePath);
41
+ }
42
+ } catch {}
43
+ }
44
+ return classToFilePath;
45
+ }
46
+ async function resolveLocalWorkflowEntrypoints(config, configDir) {
47
+ const workflows = config.bindings?.workflows;
48
+ if (!workflows || Object.keys(workflows).length === 0) {
49
+ return [];
50
+ }
51
+ const classToFilePath = await discoverWorkflowClasses(config, configDir);
52
+ const entrypoints = [];
53
+ for (const [bindingName, binding] of Object.entries(workflows)) {
54
+ const normalized = normalizeWorkflowBinding(binding);
55
+ if (normalized.scriptName) {
56
+ continue;
57
+ }
58
+ const scriptPath = classToFilePath.get(normalized.className);
59
+ if (!scriptPath) {
60
+ throw new Error(`Workflow binding ${bindingName} (className: '${normalized.className}') not found.
61
+ ` + `Either set files.workflows to match the workflow source file, or set scriptName when the workflow lives in another worker.`);
62
+ }
63
+ entrypoints.push({
64
+ bindingName,
65
+ className: normalized.className,
66
+ scriptPath
67
+ });
68
+ }
69
+ return entrypoints;
70
+ }
71
+ function buildWorkflowVirtualEntry(entrypoints, entryDir) {
72
+ const imports = entrypoints.map((entrypoint, index) => {
73
+ const importName = `__DevflareWorkflow${index}`;
74
+ const importPath = toImportSpecifier(entryDir, entrypoint.scriptPath);
75
+ return {
76
+ importName,
77
+ className: entrypoint.className,
78
+ line: `import { ${entrypoint.className} as ${importName} } from '${importPath}'`
79
+ };
80
+ });
81
+ const exports = imports.map((entrypoint) => {
82
+ return `export { ${entrypoint.importName} as ${entrypoint.className} }`;
83
+ });
84
+ return [...imports.map((entrypoint) => entrypoint.line), "", ...exports].join(`
85
+ `);
86
+ }
87
+ async function bundleWorkflowEntrypointScript(config, configDir, options = {}) {
88
+ const entrypoints = await resolveLocalWorkflowEntrypoints(config, configDir);
89
+ if (entrypoints.length === 0) {
90
+ return "";
91
+ }
92
+ const entryDir = resolve(configDir, ".devflare", "workflow-entrypoints");
93
+ const entryPath = join(entryDir, "__entry.ts");
94
+ const outFile = join(entryDir, "index.js");
95
+ await mkdir(entryDir, { recursive: true });
96
+ await writeFile(entryPath, buildWorkflowVirtualEntry(entrypoints, entryDir));
97
+ await bundleWorkerEntry({
98
+ cwd: configDir,
99
+ inputFile: entryPath,
100
+ outFile,
101
+ rolldownOptions: config.rolldown?.options,
102
+ sourcemap: config.rolldown?.sourcemap,
103
+ minify: config.rolldown?.minify,
104
+ logger: options.logger
105
+ });
106
+ return await readFile(outFile, "utf-8");
107
+ }
108
+
109
+ export { bundleWorkflowEntrypointScript };