turnzero 0.21.5 → 0.21.6-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2520,18 +2520,32 @@ function workspacePatterns(manifest, steps) {
2520
2520
  excluded: excluded.map((pattern) => pattern.segments).filter((segments) => segments.length > 0)
2521
2521
  };
2522
2522
  }
2523
- function workspaceMembersOf(manifest, nested) {
2523
+ var READ_YIELD_MATCH_STEPS = 1e5;
2524
+ function* workspaceMembersSteps(manifest, nested) {
2524
2525
  const steps = { taken: 0 };
2525
2526
  const { included, excluded } = workspacePatterns(manifest, steps);
2526
2527
  if (included.length === 0) return [];
2527
2528
  const members = [];
2529
+ let read2 = 0;
2530
+ let stepsAtYield = 0;
2528
2531
  for (const path of nested) {
2532
+ read2 += 1;
2533
+ if (read2 % READ_YIELD_ENTRIES === 0 || steps.taken - stepsAtYield >= READ_YIELD_MATCH_STEPS) {
2534
+ stepsAtYield = steps.taken;
2535
+ yield;
2536
+ }
2529
2537
  if (!isNestedPackageJson(path)) continue;
2530
2538
  const folder = path.slice(0, -"/package.json".length).split("/");
2531
2539
  if (included.some((pattern) => patternMatches(pattern, folder, steps)) && !excluded.some((pattern) => patternMatches(pattern, folder, steps))) members.push(path);
2532
2540
  }
2533
2541
  return members;
2534
2542
  }
2543
+ var READ_YIELD_ENTRIES = 1024;
2544
+ function stepsSync(steps) {
2545
+ let step = steps.next();
2546
+ while (!step.done) step = steps.next();
2547
+ return step.value;
2548
+ }
2535
2549
  var REFUSED_ENTRY_SHOWN_CHARS = 200;
2536
2550
  var shownEntry = (name) => JSON.stringify(name.length > REFUSED_ENTRY_SHOWN_CHARS ? `${name.slice(0, REFUSED_ENTRY_SHOWN_CHARS)}\u2026` : name);
2537
2551
  function entryNameOf(stored) {
@@ -2646,15 +2660,18 @@ function nameRefusal(stored) {
2646
2660
  if (path === ".." || path.startsWith("../")) return { cause: "climbing", reason: "climbs out of the artifact's folder" };
2647
2661
  return null;
2648
2662
  }
2649
- function artifactEntryRefusal(stored) {
2663
+ function* artifactEntryRefusalSteps(stored) {
2664
+ let passed = 0;
2650
2665
  let segments = 0;
2651
2666
  for (const entry of stored) {
2667
+ if (++passed % READ_YIELD_ENTRIES === 0) yield;
2652
2668
  const bounded = nameBoundRefusal(entry);
2653
2669
  if (bounded !== null) return { entry, ...bounded };
2654
2670
  segments += segmentCount(entry);
2655
2671
  if (segments > ARTIFACT_SEGMENTS_MAX) return { entry, cause: "too_many_segments", reason: `brings the zip's names past the ${ARTIFACT_SEGMENTS_MAX} segments the image build reads in all` };
2656
2672
  }
2657
2673
  for (const entry of stored) {
2674
+ if (++passed % READ_YIELD_ENTRIES === 0) yield;
2658
2675
  const refusal = nameRefusal(entry);
2659
2676
  if (refusal !== null) return { entry, ...refusal };
2660
2677
  }
@@ -2673,6 +2690,7 @@ function artifactEntryRefusal(stored) {
2673
2690
  return node;
2674
2691
  };
2675
2692
  for (const entry of stored) {
2693
+ if (++passed % READ_YIELD_ENTRIES === 0) yield;
2676
2694
  const { path, folder } = entryNameOf(entry);
2677
2695
  const key = path.replace(/\/$/, "");
2678
2696
  const segments2 = key === "" ? [] : key.split("/");
@@ -2697,7 +2715,7 @@ var isRecord = (value) => typeof value === "object" && value !== null && !Array.
2697
2715
  var ROOT_FILE_MAX_BYTES = 1024 * 1024;
2698
2716
  var MEMBER_FILE_MAX_BYTES = 64 * 1024;
2699
2717
  var MEMBER_FILES_READ_MAX = 50;
2700
- function readArtifact(bytes) {
2718
+ function* readArtifactSteps(bytes) {
2701
2719
  const stored = [];
2702
2720
  const names = [];
2703
2721
  const rootIndex = /* @__PURE__ */ new Map();
@@ -2719,6 +2737,7 @@ function readArtifact(bytes) {
2719
2737
  }
2720
2738
  const { records, past: pastEntries } = listing;
2721
2739
  for (const [index, record] of records.entries()) {
2740
+ if ((index + 1) % READ_YIELD_ENTRIES === 0) yield;
2722
2741
  const { path: name, folder } = entryNameOf(record.name);
2723
2742
  stored.push(record.name);
2724
2743
  names.push(name);
@@ -2741,7 +2760,7 @@ function readArtifact(bytes) {
2741
2760
  }
2742
2761
  const bounded = artifactBoundRefusal(pastEntries ? ARTIFACT_ENTRIES_MAX + 1 : stored.length, declaredBytes);
2743
2762
  if (bounded !== null) throw layoutRefusal(`The zip ${bounded}: deploy the application's own files alone, without node_modules or build caches, and deploy again`);
2744
- const refusedName = artifactEntryRefusal(stored);
2763
+ const refusedName = yield* artifactEntryRefusalSteps(stored);
2745
2764
  if (refusedName !== null) throw layoutRefusal(entryRefusalDetail(refusedName));
2746
2765
  const texts = /* @__PURE__ */ new Map();
2747
2766
  for (const index of [...rootIndex.values(), ...[...nestedIndex.values()].filter((chosen) => chosen !== null)]) {
@@ -2751,13 +2770,14 @@ function readArtifact(bytes) {
2751
2770
  if (!(error instanceof ZipUnreadable)) throw error;
2752
2771
  throw new DeployRefusal(400, "artifact_unreadable", `The zip's ${error.message}: zip the application's folder again, and deploy again (PLD-L0-63).`);
2753
2772
  }
2773
+ yield;
2754
2774
  }
2755
2775
  const textAt = (index) => index === null || index === void 0 ? null : texts.get(index) ?? null;
2756
2776
  const packageJson = textAt(rootIndex.get("package.json"));
2757
2777
  const nested = [...nestedIndex].map(([path, index]) => ({ path, text: textAt(index) }));
2758
2778
  let members = [];
2759
2779
  try {
2760
- if (packageJson !== null) members = workspaceMembersOf(parsePackageJson(packageJson), nestedIndex.keys());
2780
+ if (packageJson !== null) members = yield* workspaceMembersSteps(parsePackageJson(packageJson), nestedIndex.keys());
2761
2781
  } catch (error) {
2762
2782
  if (!(error instanceof WorkspaceRefusal)) throw error;
2763
2783
  throw layoutRefusal(`The zip's ${error.message.replace(/^the /, "")}. Write each pattern of literal segments, * within a segment, and ** segments, with each ! pattern after every other, and deploy again`);
@@ -2914,7 +2934,10 @@ function clientBoundRefusal(reading) {
2914
2934
  return null;
2915
2935
  }
2916
2936
  function checkArtifact(bytes) {
2917
- const reading = readArtifact(bytes);
2937
+ return stepsSync(checkArtifactSteps(bytes));
2938
+ }
2939
+ function* checkArtifactSteps(bytes) {
2940
+ const reading = yield* readArtifactSteps(bytes);
2918
2941
  const packageJson = artifactLayoutOf(reading);
2919
2942
  manifestCopyDepthRefusal(reading);
2920
2943
  const client = clientReadingOf(reading.records);
@@ -6557,11 +6580,9 @@ var SCAFFOLD_TEMPLATE_FILES = Object.freeze({
6557
6580
  ].join("\n")],
6558
6581
  ["src/db.mjs", [
6559
6582
  "// src/db.mjs",
6560
- "import { readdirSync, readFileSync } from 'node:fs';",
6561
- "import { join } from 'node:path';",
6562
6583
  "import { fileURLToPath } from 'node:url';",
6563
6584
  "import pg from 'pg';",
6564
- "import { bootWalk, createFailoverPool } from '@turnzero/database';",
6585
+ "import { bootWalk, createFailoverPool, migrationsFrom } from '@turnzero/database';",
6565
6586
  "",
6566
6587
  "const MIGRATIONS = fileURLToPath(new URL('../migrations/', import.meta.url));",
6567
6588
  "const HEALTH_READ_MS = 2_000;",
@@ -6586,8 +6607,7 @@ var SCAFFOLD_TEMPLATE_FILES = Object.freeze({
6586
6607
  "// The migrations through the package's boot walk: a lost connection retried",
6587
6608
  "// every second for up to 120 seconds, and any other failure ends the start.",
6588
6609
  "export function migrate(pool) {",
6589
- " const files = { list: () => readdirSync(MIGRATIONS), read: (name) => readFileSync(join(MIGRATIONS, name), 'utf8') };",
6590
- " return bootWalk(pool, files, {",
6610
+ " return bootWalk(pool, migrationsFrom(MIGRATIONS), {",
6591
6611
  " onRetry: (error, attempt) => {",
6592
6612
  " if (attempt === 1) console.warn('database unreachable at start; retrying:', error.message);",
6593
6613
  " },",
@@ -7417,11 +7437,9 @@ var SCAFFOLD_TEMPLATE_FILES = Object.freeze({
7417
7437
  ].join("\n")],
7418
7438
  ["src/db.mjs", [
7419
7439
  "// src/db.mjs",
7420
- "import { readdirSync, readFileSync } from 'node:fs';",
7421
- "import { join } from 'node:path';",
7422
7440
  "import { fileURLToPath } from 'node:url';",
7423
7441
  "import pg from 'pg';",
7424
- "import { bootWalk, createFailoverPool } from '@turnzero/database';",
7442
+ "import { bootWalk, createFailoverPool, migrationsFrom } from '@turnzero/database';",
7425
7443
  "",
7426
7444
  "const MIGRATIONS = fileURLToPath(new URL('../migrations/', import.meta.url));",
7427
7445
  "const HEALTH_READ_MS = 2_000;",
@@ -7446,8 +7464,7 @@ var SCAFFOLD_TEMPLATE_FILES = Object.freeze({
7446
7464
  "// The migrations through the package's boot walk: a lost connection retried",
7447
7465
  "// every second for up to 120 seconds, and any other failure ends the start.",
7448
7466
  "export function migrate(pool) {",
7449
- " const files = { list: () => readdirSync(MIGRATIONS), read: (name) => readFileSync(join(MIGRATIONS, name), 'utf8') };",
7450
- " return bootWalk(pool, files, {",
7467
+ " return bootWalk(pool, migrationsFrom(MIGRATIONS), {",
7451
7468
  " onRetry: (error, attempt) => {",
7452
7469
  " if (attempt === 1) console.warn('database unreachable at start; retrying:', error.message);",
7453
7470
  " },",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "turnzero",
3
- "version": "0.21.5",
3
+ "version": "0.21.6-next.1",
4
4
  "type": "module",
5
5
  "description": "The Turn Zero Cloud command, which an AI coding tool runs on your machine to deploy an application, store a secret, upload a file, download an export, take a library entry, write a local run's settings, start the application locally, and scaffold a new service from a template.",
6
6
  "license": "Apache-2.0",