freestyle-sandboxes 0.1.25 → 0.1.27

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/index.cjs CHANGED
@@ -6325,8 +6325,14 @@ class VmSpec {
6325
6325
  this.with = withBuilders ?? {};
6326
6326
  }
6327
6327
  }
6328
+ function isVmSpecLike(value) {
6329
+ return !!value && typeof value === "object" && "raw" in value && "with" in value;
6330
+ }
6331
+ function isVmTemplateLike(value) {
6332
+ return !!value && typeof value === "object" && "raw" in value && "with" in value;
6333
+ }
6328
6334
  async function convertSpecSnapshotsToTemplates(spec, processBuilders = true) {
6329
- if (!spec.raw.snapshot) {
6335
+ if (!isVmSpecLike(spec.raw.snapshot)) {
6330
6336
  return void 0;
6331
6337
  }
6332
6338
  let innerSpec = spec.raw.snapshot;
@@ -6335,7 +6341,7 @@ async function convertSpecSnapshotsToTemplates(spec, processBuilders = true) {
6335
6341
  }
6336
6342
  const { snapshot: nestedSnapshot, ...innerRaw } = innerSpec.raw;
6337
6343
  let nestedTemplate;
6338
- if (nestedSnapshot instanceof VmSpec) {
6344
+ if (isVmSpecLike(nestedSnapshot)) {
6339
6345
  nestedTemplate = await convertSpecSnapshotsToTemplates(innerSpec, false);
6340
6346
  }
6341
6347
  return new VmTemplate({
@@ -6353,7 +6359,7 @@ async function processOuterSpecBuilders(spec) {
6353
6359
  }
6354
6360
  if (builder.configureSnapshotSpec) {
6355
6361
  let snapshotSpec;
6356
- if (spec.raw.snapshot instanceof VmSpec) {
6362
+ if (isVmSpecLike(spec.raw.snapshot)) {
6357
6363
  snapshotSpec = spec.raw.snapshot;
6358
6364
  } else {
6359
6365
  snapshotSpec = new VmSpec({});
@@ -6374,7 +6380,7 @@ async function processSpecTree(spec) {
6374
6380
  }
6375
6381
  if (builder.configureSnapshotSpec) {
6376
6382
  let snapshotSpec;
6377
- if (spec.raw.snapshot instanceof VmSpec) {
6383
+ if (isVmSpecLike(spec.raw.snapshot)) {
6378
6384
  snapshotSpec = spec.raw.snapshot;
6379
6385
  } else {
6380
6386
  snapshotSpec = new VmSpec({});
@@ -6384,14 +6390,14 @@ async function processSpecTree(spec) {
6384
6390
  }
6385
6391
  }
6386
6392
  }
6387
- if (spec.raw.snapshot instanceof VmSpec) {
6393
+ if (isVmSpecLike(spec.raw.snapshot)) {
6388
6394
  spec.raw.snapshot = await processSpecTree(spec.raw.snapshot);
6389
6395
  }
6390
6396
  return spec;
6391
6397
  }
6392
6398
  function collectSpecBuilders(spec) {
6393
6399
  let builders = {};
6394
- if (spec.raw.snapshot instanceof VmSpec) {
6400
+ if (isVmSpecLike(spec.raw.snapshot)) {
6395
6401
  builders = collectSpecBuilders(spec.raw.snapshot);
6396
6402
  }
6397
6403
  if (spec.with) {
@@ -6427,8 +6433,8 @@ class VmsNamespace {
6427
6433
  * @returns A VM instance representing the created VM
6428
6434
  */
6429
6435
  async create(options = {}) {
6430
- if (options.snapshot instanceof VmSpec) {
6431
- if (options.spec instanceof VmSpec) {
6436
+ if (isVmSpecLike(options.snapshot)) {
6437
+ if (isVmSpecLike(options.spec)) {
6432
6438
  if (!options.spec.raw.snapshot) {
6433
6439
  options.spec.raw.snapshot = options.snapshot;
6434
6440
  }
@@ -6478,10 +6484,10 @@ class VmsNamespace {
6478
6484
  const { snapshot: _snapshot, ...rest } = options;
6479
6485
  options = rest;
6480
6486
  }
6481
- if (options.spec instanceof VmSpec && options.with) {
6487
+ if (isVmSpecLike(options.spec) && options.with) {
6482
6488
  options.spec = mergeWithBuildersIntoSpec(options.spec, options.with);
6483
6489
  }
6484
- if (options.spec instanceof VmSpec) {
6490
+ if (isVmSpecLike(options.spec)) {
6485
6491
  let spec = options.spec;
6486
6492
  spec = await processOuterSpecBuilders(spec);
6487
6493
  const { snapshot, ...outerSpecOptions } = spec.raw;
@@ -6501,19 +6507,19 @@ class VmsNamespace {
6501
6507
  options.with = spec.with;
6502
6508
  }
6503
6509
  }
6504
- const specBuilders = options.spec instanceof VmSpec ? collectSpecBuilders(options.spec) : void 0;
6505
- const templateBuilders = options.template instanceof VmTemplate ? options.template.with : void 0;
6510
+ const specBuilders = isVmSpecLike(options.spec) ? collectSpecBuilders(options.spec) : void 0;
6511
+ const templateBuilders = isVmTemplateLike(options.template) ? options.template.with : void 0;
6506
6512
  const builders = {
6507
6513
  ...templateBuilders || {},
6508
6514
  ...specBuilders || {},
6509
6515
  ...options.with || {}
6510
6516
  };
6511
- const { with: _, ...baseConfig } = options;
6517
+ const { with: _, spec: _spec, ...baseConfig } = options;
6512
6518
  let config = baseConfig;
6513
- if (config.template instanceof VmTemplate) {
6519
+ if (isVmTemplateLike(config.template)) {
6514
6520
  config.template = await processTemplateTree(config.template);
6515
6521
  }
6516
- if (config.template instanceof VmTemplate) {
6522
+ if (isVmTemplateLike(config.template)) {
6517
6523
  config.template = await ensureNestedTemplates(
6518
6524
  config.template,
6519
6525
  this.snapshots
@@ -6566,7 +6572,7 @@ class VmsNamespace {
6566
6572
  const response = await this.freestyle._apiClient.post("/v1/vms", {
6567
6573
  body: {
6568
6574
  ...config,
6569
- template: config.template instanceof VmTemplate ? config.template["raw"] : config.template,
6575
+ template: isVmTemplateLike(config.template) ? config.template["raw"] : config.template,
6570
6576
  // Cast systemd since we've processed SystemdServiceInput[] to RawSystemdService[]
6571
6577
  systemd: config.systemd,
6572
6578
  // Normalize git options - default config to {}
@@ -6667,8 +6673,8 @@ class VmSnapshotsNamespace {
6667
6673
  }
6668
6674
  async ensure(options) {
6669
6675
  let requestOptions = options;
6670
- if (requestOptions.snapshot instanceof VmSpec) {
6671
- if (requestOptions.spec instanceof VmSpec) {
6676
+ if (isVmSpecLike(requestOptions.snapshot)) {
6677
+ if (isVmSpecLike(requestOptions.spec)) {
6672
6678
  if (!requestOptions.spec.raw.snapshot) {
6673
6679
  requestOptions.spec.raw.snapshot = requestOptions.snapshot;
6674
6680
  }
@@ -6680,7 +6686,7 @@ class VmSnapshotsNamespace {
6680
6686
  const { snapshot: _snapshot, ...rest } = requestOptions;
6681
6687
  requestOptions = rest;
6682
6688
  }
6683
- if (requestOptions.spec instanceof VmSpec) {
6689
+ if (isVmSpecLike(requestOptions.spec)) {
6684
6690
  let spec = requestOptions.spec;
6685
6691
  spec = await processSpecTree(spec);
6686
6692
  const { snapshot: _snapshotSpec, ...outerSpecOptions } = spec.raw;
@@ -6695,12 +6701,12 @@ class VmSnapshotsNamespace {
6695
6701
  const { spec: _spec, ...rest } = requestOptions;
6696
6702
  requestOptions = rest;
6697
6703
  }
6698
- if (requestOptions.template instanceof VmTemplate) {
6704
+ if (isVmTemplateLike(requestOptions.template)) {
6699
6705
  const processedTemplate = await processTemplateTree(
6700
6706
  requestOptions.template
6701
6707
  );
6702
6708
  requestOptions.template = processedTemplate;
6703
- if (processedTemplate.raw.template instanceof VmTemplate) {
6709
+ if (isVmTemplateLike(processedTemplate.raw.template)) {
6704
6710
  requestOptions.template = await ensureNestedTemplates(
6705
6711
  processedTemplate,
6706
6712
  this
@@ -6715,7 +6721,7 @@ class VmSnapshotsNamespace {
6715
6721
  return this.apiClient.post("/v1/vms/snapshots", {
6716
6722
  body: {
6717
6723
  ...requestOptions,
6718
- template: requestOptions.template instanceof VmTemplate ? requestOptions.template.raw : requestOptions.template
6724
+ template: isVmTemplateLike(requestOptions.template) ? requestOptions.template.raw : requestOptions.template
6719
6725
  }
6720
6726
  }).catch((e) => {
6721
6727
  enhanceError(e);
@@ -6757,7 +6763,7 @@ async function processTemplateTree(template) {
6757
6763
  }
6758
6764
  if (builder.configureNestedTemplate) {
6759
6765
  let nestedTemplate;
6760
- if (template.raw.template instanceof VmTemplate) {
6766
+ if (isVmTemplateLike(template.raw.template)) {
6761
6767
  nestedTemplate = template.raw.template;
6762
6768
  } else {
6763
6769
  nestedTemplate = new VmTemplate({});
@@ -6808,7 +6814,7 @@ async function processTemplateTree(template) {
6808
6814
  })
6809
6815
  );
6810
6816
  }
6811
- if (template.raw.template instanceof VmTemplate) {
6817
+ if (isVmTemplateLike(template.raw.template)) {
6812
6818
  template.raw.template = await processTemplateTree(
6813
6819
  template.raw.template
6814
6820
  );
@@ -6817,7 +6823,7 @@ async function processTemplateTree(template) {
6817
6823
  }
6818
6824
  async function ensureNestedTemplates(template, snapshots) {
6819
6825
  const templates = [template];
6820
- while (templates.at(-1)?.raw.template instanceof VmTemplate) {
6826
+ while (isVmTemplateLike(templates.at(-1)?.raw.template)) {
6821
6827
  const innerTemplate = templates.at(-1).raw.template;
6822
6828
  templates.at(-1).raw.template = void 0;
6823
6829
  templates.push(innerTemplate);
@@ -7004,6 +7010,51 @@ async function readFiles(directory) {
7004
7010
  return files;
7005
7011
  }
7006
7012
 
7013
+ async function debugCreateRequests(freestyle, options = {}) {
7014
+ const requests = [];
7015
+ let snapshotCounter = 0;
7016
+ let vmCounter = 0;
7017
+ const apiClient = freestyle._apiClient;
7018
+ const originalPost = apiClient.post.bind(freestyle._apiClient);
7019
+ const mockPost = (async (path, ...args) => {
7020
+ const rawBody = args[0] && "body" in args[0] ? args[0].body : void 0;
7021
+ const clonedBody = JSON.parse(JSON.stringify(rawBody ?? null));
7022
+ if (path === "/v1/vms/snapshots") {
7023
+ requests.push({
7024
+ path: "/v1/vms/snapshots",
7025
+ body: clonedBody
7026
+ });
7027
+ snapshotCounter += 1;
7028
+ return {
7029
+ snapshotId: `__debug_snapshot_${snapshotCounter}__`
7030
+ };
7031
+ }
7032
+ if (path === "/v1/vms") {
7033
+ requests.push({
7034
+ path: "/v1/vms",
7035
+ body: clonedBody
7036
+ });
7037
+ vmCounter += 1;
7038
+ return {
7039
+ id: `__debug_vm_${vmCounter}__`,
7040
+ domains: [],
7041
+ consoleUrl: "https://debug.local/console"
7042
+ };
7043
+ }
7044
+ return originalPost(
7045
+ path,
7046
+ ...args
7047
+ );
7048
+ });
7049
+ apiClient.post = mockPost;
7050
+ try {
7051
+ await freestyle.vms.create(options);
7052
+ } finally {
7053
+ apiClient.post = originalPost;
7054
+ }
7055
+ return requests;
7056
+ }
7057
+
7007
7058
  class Freestyle {
7008
7059
  /**
7009
7060
  * @internal
@@ -7089,5 +7140,6 @@ exports.VmSpec = VmSpec;
7089
7140
  exports.VmTemplate = VmTemplate;
7090
7141
  exports.VmWith = VmWith;
7091
7142
  exports.VmWithInstance = VmWithInstance;
7143
+ exports.debugCreateRequests = debugCreateRequests;
7092
7144
  exports.freestyle = freestyle;
7093
7145
  exports.readFiles = readFiles;
package/index.d.cts CHANGED
@@ -13835,6 +13835,21 @@ declare function readFiles(directory: string): Promise<{
13835
13835
  encoding: string;
13836
13836
  }[]>;
13837
13837
 
13838
+ type DebugCreateApiRequest = {
13839
+ path: "/v1/vms/snapshots" | "/v1/vms";
13840
+ body: unknown;
13841
+ };
13842
+ /**
13843
+ * Simulate what the SDK would POST during `freestyle.vms.create(...)` and
13844
+ * return all request bodies in execution order without network calls.
13845
+ */
13846
+ declare function debugCreateRequests<T extends Record<string, VmWith>>(freestyle: Freestyle, options?: CreateVmOptions & {
13847
+ with?: T;
13848
+ template?: VmTemplate<T>;
13849
+ spec?: VmSpec<T>;
13850
+ snapshot?: VmSpec<T>;
13851
+ }): Promise<DebugCreateApiRequest[]>;
13852
+
13838
13853
  type FreestyleOptions = ApiClientConfig;
13839
13854
  declare class Freestyle {
13840
13855
  readonly domains: DomainsNamespace;
@@ -13856,5 +13871,5 @@ declare class Freestyle {
13856
13871
  */
13857
13872
  declare const freestyle: Freestyle;
13858
13873
 
13859
- export { CronNamespace, Deployment, errors as Errors, FileSystem, Freestyle, GitRepo, Identity, requests as Requests, responses as Responses, Systemd, SystemdService, Vm, VmBuilder, VmService, VmSpec, VmTemplate, VmWith, VmWithInstance, freestyle, readFiles };
13874
+ export { CronNamespace, Deployment, errors as Errors, FileSystem, Freestyle, GitRepo, Identity, requests as Requests, responses as Responses, Systemd, SystemdService, Vm, VmBuilder, VmService, VmSpec, VmTemplate, VmWith, VmWithInstance, debugCreateRequests, freestyle, readFiles };
13860
13875
  export type { CreateVmOptions, CronSchedule, FreestyleOptions, SystemdServiceInput };
package/index.d.mts CHANGED
@@ -13835,6 +13835,21 @@ declare function readFiles(directory: string): Promise<{
13835
13835
  encoding: string;
13836
13836
  }[]>;
13837
13837
 
13838
+ type DebugCreateApiRequest = {
13839
+ path: "/v1/vms/snapshots" | "/v1/vms";
13840
+ body: unknown;
13841
+ };
13842
+ /**
13843
+ * Simulate what the SDK would POST during `freestyle.vms.create(...)` and
13844
+ * return all request bodies in execution order without network calls.
13845
+ */
13846
+ declare function debugCreateRequests<T extends Record<string, VmWith>>(freestyle: Freestyle, options?: CreateVmOptions & {
13847
+ with?: T;
13848
+ template?: VmTemplate<T>;
13849
+ spec?: VmSpec<T>;
13850
+ snapshot?: VmSpec<T>;
13851
+ }): Promise<DebugCreateApiRequest[]>;
13852
+
13838
13853
  type FreestyleOptions = ApiClientConfig;
13839
13854
  declare class Freestyle {
13840
13855
  readonly domains: DomainsNamespace;
@@ -13856,5 +13871,5 @@ declare class Freestyle {
13856
13871
  */
13857
13872
  declare const freestyle: Freestyle;
13858
13873
 
13859
- export { CronNamespace, Deployment, errors as Errors, FileSystem, Freestyle, GitRepo, Identity, requests as Requests, responses as Responses, Systemd, SystemdService, Vm, VmBuilder, VmService, VmSpec, VmTemplate, VmWith, VmWithInstance, freestyle, readFiles };
13874
+ export { CronNamespace, Deployment, errors as Errors, FileSystem, Freestyle, GitRepo, Identity, requests as Requests, responses as Responses, Systemd, SystemdService, Vm, VmBuilder, VmService, VmSpec, VmTemplate, VmWith, VmWithInstance, debugCreateRequests, freestyle, readFiles };
13860
13875
  export type { CreateVmOptions, CronSchedule, FreestyleOptions, SystemdServiceInput };
package/index.mjs CHANGED
@@ -6323,8 +6323,14 @@ class VmSpec {
6323
6323
  this.with = withBuilders ?? {};
6324
6324
  }
6325
6325
  }
6326
+ function isVmSpecLike(value) {
6327
+ return !!value && typeof value === "object" && "raw" in value && "with" in value;
6328
+ }
6329
+ function isVmTemplateLike(value) {
6330
+ return !!value && typeof value === "object" && "raw" in value && "with" in value;
6331
+ }
6326
6332
  async function convertSpecSnapshotsToTemplates(spec, processBuilders = true) {
6327
- if (!spec.raw.snapshot) {
6333
+ if (!isVmSpecLike(spec.raw.snapshot)) {
6328
6334
  return void 0;
6329
6335
  }
6330
6336
  let innerSpec = spec.raw.snapshot;
@@ -6333,7 +6339,7 @@ async function convertSpecSnapshotsToTemplates(spec, processBuilders = true) {
6333
6339
  }
6334
6340
  const { snapshot: nestedSnapshot, ...innerRaw } = innerSpec.raw;
6335
6341
  let nestedTemplate;
6336
- if (nestedSnapshot instanceof VmSpec) {
6342
+ if (isVmSpecLike(nestedSnapshot)) {
6337
6343
  nestedTemplate = await convertSpecSnapshotsToTemplates(innerSpec, false);
6338
6344
  }
6339
6345
  return new VmTemplate({
@@ -6351,7 +6357,7 @@ async function processOuterSpecBuilders(spec) {
6351
6357
  }
6352
6358
  if (builder.configureSnapshotSpec) {
6353
6359
  let snapshotSpec;
6354
- if (spec.raw.snapshot instanceof VmSpec) {
6360
+ if (isVmSpecLike(spec.raw.snapshot)) {
6355
6361
  snapshotSpec = spec.raw.snapshot;
6356
6362
  } else {
6357
6363
  snapshotSpec = new VmSpec({});
@@ -6372,7 +6378,7 @@ async function processSpecTree(spec) {
6372
6378
  }
6373
6379
  if (builder.configureSnapshotSpec) {
6374
6380
  let snapshotSpec;
6375
- if (spec.raw.snapshot instanceof VmSpec) {
6381
+ if (isVmSpecLike(spec.raw.snapshot)) {
6376
6382
  snapshotSpec = spec.raw.snapshot;
6377
6383
  } else {
6378
6384
  snapshotSpec = new VmSpec({});
@@ -6382,14 +6388,14 @@ async function processSpecTree(spec) {
6382
6388
  }
6383
6389
  }
6384
6390
  }
6385
- if (spec.raw.snapshot instanceof VmSpec) {
6391
+ if (isVmSpecLike(spec.raw.snapshot)) {
6386
6392
  spec.raw.snapshot = await processSpecTree(spec.raw.snapshot);
6387
6393
  }
6388
6394
  return spec;
6389
6395
  }
6390
6396
  function collectSpecBuilders(spec) {
6391
6397
  let builders = {};
6392
- if (spec.raw.snapshot instanceof VmSpec) {
6398
+ if (isVmSpecLike(spec.raw.snapshot)) {
6393
6399
  builders = collectSpecBuilders(spec.raw.snapshot);
6394
6400
  }
6395
6401
  if (spec.with) {
@@ -6425,8 +6431,8 @@ class VmsNamespace {
6425
6431
  * @returns A VM instance representing the created VM
6426
6432
  */
6427
6433
  async create(options = {}) {
6428
- if (options.snapshot instanceof VmSpec) {
6429
- if (options.spec instanceof VmSpec) {
6434
+ if (isVmSpecLike(options.snapshot)) {
6435
+ if (isVmSpecLike(options.spec)) {
6430
6436
  if (!options.spec.raw.snapshot) {
6431
6437
  options.spec.raw.snapshot = options.snapshot;
6432
6438
  }
@@ -6476,10 +6482,10 @@ class VmsNamespace {
6476
6482
  const { snapshot: _snapshot, ...rest } = options;
6477
6483
  options = rest;
6478
6484
  }
6479
- if (options.spec instanceof VmSpec && options.with) {
6485
+ if (isVmSpecLike(options.spec) && options.with) {
6480
6486
  options.spec = mergeWithBuildersIntoSpec(options.spec, options.with);
6481
6487
  }
6482
- if (options.spec instanceof VmSpec) {
6488
+ if (isVmSpecLike(options.spec)) {
6483
6489
  let spec = options.spec;
6484
6490
  spec = await processOuterSpecBuilders(spec);
6485
6491
  const { snapshot, ...outerSpecOptions } = spec.raw;
@@ -6499,19 +6505,19 @@ class VmsNamespace {
6499
6505
  options.with = spec.with;
6500
6506
  }
6501
6507
  }
6502
- const specBuilders = options.spec instanceof VmSpec ? collectSpecBuilders(options.spec) : void 0;
6503
- const templateBuilders = options.template instanceof VmTemplate ? options.template.with : void 0;
6508
+ const specBuilders = isVmSpecLike(options.spec) ? collectSpecBuilders(options.spec) : void 0;
6509
+ const templateBuilders = isVmTemplateLike(options.template) ? options.template.with : void 0;
6504
6510
  const builders = {
6505
6511
  ...templateBuilders || {},
6506
6512
  ...specBuilders || {},
6507
6513
  ...options.with || {}
6508
6514
  };
6509
- const { with: _, ...baseConfig } = options;
6515
+ const { with: _, spec: _spec, ...baseConfig } = options;
6510
6516
  let config = baseConfig;
6511
- if (config.template instanceof VmTemplate) {
6517
+ if (isVmTemplateLike(config.template)) {
6512
6518
  config.template = await processTemplateTree(config.template);
6513
6519
  }
6514
- if (config.template instanceof VmTemplate) {
6520
+ if (isVmTemplateLike(config.template)) {
6515
6521
  config.template = await ensureNestedTemplates(
6516
6522
  config.template,
6517
6523
  this.snapshots
@@ -6564,7 +6570,7 @@ class VmsNamespace {
6564
6570
  const response = await this.freestyle._apiClient.post("/v1/vms", {
6565
6571
  body: {
6566
6572
  ...config,
6567
- template: config.template instanceof VmTemplate ? config.template["raw"] : config.template,
6573
+ template: isVmTemplateLike(config.template) ? config.template["raw"] : config.template,
6568
6574
  // Cast systemd since we've processed SystemdServiceInput[] to RawSystemdService[]
6569
6575
  systemd: config.systemd,
6570
6576
  // Normalize git options - default config to {}
@@ -6665,8 +6671,8 @@ class VmSnapshotsNamespace {
6665
6671
  }
6666
6672
  async ensure(options) {
6667
6673
  let requestOptions = options;
6668
- if (requestOptions.snapshot instanceof VmSpec) {
6669
- if (requestOptions.spec instanceof VmSpec) {
6674
+ if (isVmSpecLike(requestOptions.snapshot)) {
6675
+ if (isVmSpecLike(requestOptions.spec)) {
6670
6676
  if (!requestOptions.spec.raw.snapshot) {
6671
6677
  requestOptions.spec.raw.snapshot = requestOptions.snapshot;
6672
6678
  }
@@ -6678,7 +6684,7 @@ class VmSnapshotsNamespace {
6678
6684
  const { snapshot: _snapshot, ...rest } = requestOptions;
6679
6685
  requestOptions = rest;
6680
6686
  }
6681
- if (requestOptions.spec instanceof VmSpec) {
6687
+ if (isVmSpecLike(requestOptions.spec)) {
6682
6688
  let spec = requestOptions.spec;
6683
6689
  spec = await processSpecTree(spec);
6684
6690
  const { snapshot: _snapshotSpec, ...outerSpecOptions } = spec.raw;
@@ -6693,12 +6699,12 @@ class VmSnapshotsNamespace {
6693
6699
  const { spec: _spec, ...rest } = requestOptions;
6694
6700
  requestOptions = rest;
6695
6701
  }
6696
- if (requestOptions.template instanceof VmTemplate) {
6702
+ if (isVmTemplateLike(requestOptions.template)) {
6697
6703
  const processedTemplate = await processTemplateTree(
6698
6704
  requestOptions.template
6699
6705
  );
6700
6706
  requestOptions.template = processedTemplate;
6701
- if (processedTemplate.raw.template instanceof VmTemplate) {
6707
+ if (isVmTemplateLike(processedTemplate.raw.template)) {
6702
6708
  requestOptions.template = await ensureNestedTemplates(
6703
6709
  processedTemplate,
6704
6710
  this
@@ -6713,7 +6719,7 @@ class VmSnapshotsNamespace {
6713
6719
  return this.apiClient.post("/v1/vms/snapshots", {
6714
6720
  body: {
6715
6721
  ...requestOptions,
6716
- template: requestOptions.template instanceof VmTemplate ? requestOptions.template.raw : requestOptions.template
6722
+ template: isVmTemplateLike(requestOptions.template) ? requestOptions.template.raw : requestOptions.template
6717
6723
  }
6718
6724
  }).catch((e) => {
6719
6725
  enhanceError(e);
@@ -6755,7 +6761,7 @@ async function processTemplateTree(template) {
6755
6761
  }
6756
6762
  if (builder.configureNestedTemplate) {
6757
6763
  let nestedTemplate;
6758
- if (template.raw.template instanceof VmTemplate) {
6764
+ if (isVmTemplateLike(template.raw.template)) {
6759
6765
  nestedTemplate = template.raw.template;
6760
6766
  } else {
6761
6767
  nestedTemplate = new VmTemplate({});
@@ -6806,7 +6812,7 @@ async function processTemplateTree(template) {
6806
6812
  })
6807
6813
  );
6808
6814
  }
6809
- if (template.raw.template instanceof VmTemplate) {
6815
+ if (isVmTemplateLike(template.raw.template)) {
6810
6816
  template.raw.template = await processTemplateTree(
6811
6817
  template.raw.template
6812
6818
  );
@@ -6815,7 +6821,7 @@ async function processTemplateTree(template) {
6815
6821
  }
6816
6822
  async function ensureNestedTemplates(template, snapshots) {
6817
6823
  const templates = [template];
6818
- while (templates.at(-1)?.raw.template instanceof VmTemplate) {
6824
+ while (isVmTemplateLike(templates.at(-1)?.raw.template)) {
6819
6825
  const innerTemplate = templates.at(-1).raw.template;
6820
6826
  templates.at(-1).raw.template = void 0;
6821
6827
  templates.push(innerTemplate);
@@ -7002,6 +7008,51 @@ async function readFiles(directory) {
7002
7008
  return files;
7003
7009
  }
7004
7010
 
7011
+ async function debugCreateRequests(freestyle, options = {}) {
7012
+ const requests = [];
7013
+ let snapshotCounter = 0;
7014
+ let vmCounter = 0;
7015
+ const apiClient = freestyle._apiClient;
7016
+ const originalPost = apiClient.post.bind(freestyle._apiClient);
7017
+ const mockPost = (async (path, ...args) => {
7018
+ const rawBody = args[0] && "body" in args[0] ? args[0].body : void 0;
7019
+ const clonedBody = JSON.parse(JSON.stringify(rawBody ?? null));
7020
+ if (path === "/v1/vms/snapshots") {
7021
+ requests.push({
7022
+ path: "/v1/vms/snapshots",
7023
+ body: clonedBody
7024
+ });
7025
+ snapshotCounter += 1;
7026
+ return {
7027
+ snapshotId: `__debug_snapshot_${snapshotCounter}__`
7028
+ };
7029
+ }
7030
+ if (path === "/v1/vms") {
7031
+ requests.push({
7032
+ path: "/v1/vms",
7033
+ body: clonedBody
7034
+ });
7035
+ vmCounter += 1;
7036
+ return {
7037
+ id: `__debug_vm_${vmCounter}__`,
7038
+ domains: [],
7039
+ consoleUrl: "https://debug.local/console"
7040
+ };
7041
+ }
7042
+ return originalPost(
7043
+ path,
7044
+ ...args
7045
+ );
7046
+ });
7047
+ apiClient.post = mockPost;
7048
+ try {
7049
+ await freestyle.vms.create(options);
7050
+ } finally {
7051
+ apiClient.post = originalPost;
7052
+ }
7053
+ return requests;
7054
+ }
7055
+
7005
7056
  class Freestyle {
7006
7057
  /**
7007
7058
  * @internal
@@ -7071,4 +7122,4 @@ function createLazyFreestyle(options = {}) {
7071
7122
  }
7072
7123
  const freestyle = createLazyFreestyle();
7073
7124
 
7074
- export { CronNamespace, Deployment, errors as Errors, FileSystem, Freestyle, GitRepo, Identity, Systemd, SystemdService, Vm, VmBuilder, VmService, VmSpec, VmTemplate, VmWith, VmWithInstance, freestyle, readFiles };
7125
+ export { CronNamespace, Deployment, errors as Errors, FileSystem, Freestyle, GitRepo, Identity, Systemd, SystemdService, Vm, VmBuilder, VmService, VmSpec, VmTemplate, VmWith, VmWithInstance, debugCreateRequests, freestyle, readFiles };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "freestyle-sandboxes",
3
- "version": "0.1.25",
3
+ "version": "0.1.27",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  "require": {