freestyle-sandboxes 0.1.37 → 0.1.39

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
@@ -5947,8 +5947,9 @@ function composeVmTemplates(templates) {
5947
5947
  );
5948
5948
  const mergedWith = {};
5949
5949
  for (const template of templates) {
5950
- for (const key in template.with) {
5951
- const builder = template.with[key];
5950
+ const builders = template.with ?? {};
5951
+ for (const key in builders) {
5952
+ const builder = builders[key];
5952
5953
  if (builder) {
5953
5954
  mergedWith[key] = builder;
5954
5955
  }
@@ -5984,8 +5985,9 @@ function composeVmSpecs(specs) {
5984
5985
  const mergedWithDiscriminators = {};
5985
5986
  for (const spec of specs) {
5986
5987
  const builderDiscriminators = spec.getBuilderDiscriminators();
5987
- for (const key in spec.builders) {
5988
- const builder = spec.builders[key];
5988
+ const builders = spec.builders ?? {};
5989
+ for (const key in builders) {
5990
+ const builder = builders[key];
5989
5991
  if (builder) {
5990
5992
  mergedWith[key] = builder;
5991
5993
  mergedWithDiscriminators[key] = builderDiscriminators[key];
@@ -6402,7 +6404,9 @@ class VmSpec {
6402
6404
  }
6403
6405
  snapshot() {
6404
6406
  const { snapshot: existingSnapshot, ...currentLayer } = this.raw;
6405
- const currentBuilders = { ...this.builders };
6407
+ const currentBuilders = {
6408
+ ...this.builders
6409
+ };
6406
6410
  const currentWithDiscriminators = this.getBuilderDiscriminators();
6407
6411
  const innerSnapshot = new VmSpec({
6408
6412
  ...currentLayer,
@@ -6456,6 +6460,14 @@ class VmSpec {
6456
6460
  const existing = this.raw.aptDeps ?? [];
6457
6461
  return this.mergeRaw({ aptDeps: [...existing, ...deps] });
6458
6462
  }
6463
+ users(users) {
6464
+ const existing = this.raw.users ?? [];
6465
+ return this.mergeRaw({ users: [...existing, ...users] });
6466
+ }
6467
+ groups(groups) {
6468
+ const existing = this.raw.groups ?? [];
6469
+ return this.mergeRaw({ groups: [...existing, ...groups] });
6470
+ }
6459
6471
  additionalFiles(files) {
6460
6472
  const existing = this.raw.additionalFiles ?? {};
6461
6473
  this.raw.additionalFiles = {
@@ -6756,7 +6768,11 @@ class VmsNamespace {
6756
6768
  ...rawTemplate ?? {},
6757
6769
  baseImage: serializedBaseImage
6758
6770
  } : rawTemplate;
6759
- const { baseImage: _baseImage, template: _template, ...requestConfig } = config;
6771
+ const {
6772
+ baseImage: _baseImage,
6773
+ template: _template,
6774
+ ...requestConfig
6775
+ } = config;
6760
6776
  const response = await this.freestyle._apiClient.post("/v1/vms", {
6761
6777
  body: {
6762
6778
  ...requestConfig,
package/index.d.cts CHANGED
@@ -12125,12 +12125,25 @@ declare class Systemd {
12125
12125
  * This is the instance attached to the VM after creation.
12126
12126
  */
12127
12127
  declare class VmWithInstance {
12128
- protected vm: Vm;
12128
+ vm: Vm;
12129
12129
  private _init;
12130
12130
  }
12131
- type VmWithDefaultField<B extends VmWith> = B extends VmWith<any, any, infer TDefaultField> ? TDefaultField : string;
12132
- type VmWithDefaultFieldRecord<B extends VmWith> = Record<VmWithDefaultField<B>, B>;
12133
- type VmWithAddedFields<B extends VmWith> = B extends VmWith<any, infer TAddedFields, any> ? TAddedFields : {};
12131
+ interface VmWithLike<TInstance = unknown, TAddedFields extends Record<string, VmWithLike<any, any, any>> = {}, TDefaultField extends string = string> {
12132
+ instance: TInstance;
12133
+ readonly defaultField?: TDefaultField;
12134
+ configure?(existingConfig: any): any;
12135
+ configureSpec?(spec: any): any;
12136
+ configureSnapshotSpec?(spec: any): any;
12137
+ configureBaseImage?(image: any): any;
12138
+ configureTemplate?(template: any): any;
12139
+ configureNestedTemplate?(template: any): any;
12140
+ createInstance(): TInstance;
12141
+ }
12142
+ type VmWithDefaultField<B extends VmWithLike> = B extends {
12143
+ defaultField?: infer TDefaultField;
12144
+ } ? Extract<TDefaultField, string> extends never ? string : Extract<TDefaultField, string> : string;
12145
+ type VmWithDefaultFieldRecord<B extends VmWithLike> = Record<VmWithDefaultField<B>, B>;
12146
+ type VmWithAddedFields<B extends VmWithLike> = B extends VmWith<any, infer TAddedFields, any> ? TAddedFields : {};
12134
12147
  /**
12135
12148
  * Base class for VM configuration builders that act as middleware.
12136
12149
  * Extend this class to create reusable VM components like DevServer, Database, etc.
@@ -12140,7 +12153,7 @@ type VmWithAddedFields<B extends VmWith> = B extends VmWith<any, infer TAddedFie
12140
12153
  * 2. Applies its own configuration
12141
12154
  * 3. Returns merged configuration
12142
12155
  */
12143
- declare abstract class VmWith<TInstance extends VmWithInstance = VmWithInstance, TAddedFields extends Record<string, VmWith> = {}, TDefaultField extends string = string> {
12156
+ declare abstract class VmWith<TInstance = VmWithInstance, TAddedFields extends Record<string, VmWithLike<any, any, any>> = {}, TDefaultField extends string = string> {
12144
12157
  instance: TInstance;
12145
12158
  readonly defaultField?: TDefaultField;
12146
12159
  protected readonly _addedFields?: TAddedFields;
@@ -12406,7 +12419,7 @@ type GitOptions = Omit<NonNullable<CreateSnapshotRequest["template"]["git"]>, "c
12406
12419
  * Template options with SystemdServiceInput support and optional git.config
12407
12420
  */
12408
12421
  type TemplateOptions = Omit<CreateSnapshotRequest["template"], "systemd" | "git"> & {
12409
- template?: VmTemplate<Record<string, VmWith>>;
12422
+ template?: VmTemplate<Record<string, VmWithLike>>;
12410
12423
  baseImage?: VmBaseImage | RawBaseImage | null;
12411
12424
  systemd?: null | {
12412
12425
  services?: SystemdServiceInput[] | null;
@@ -12423,7 +12436,7 @@ declare class VmBaseImage {
12423
12436
  hasFromInstruction(): boolean;
12424
12437
  toRaw(): RawBaseImage;
12425
12438
  }
12426
- declare class VmTemplate<T extends Record<string, VmWith> = {}> {
12439
+ declare class VmTemplate<T extends Record<string, VmWithLike> = {}> {
12427
12440
  raw: TemplateOptions;
12428
12441
  readonly with: Partial<T>;
12429
12442
  constructor(template: TemplateOptions & {
@@ -12433,11 +12446,11 @@ declare class VmTemplate<T extends Record<string, VmWith> = {}> {
12433
12446
  type VmSpecOptions = TemplateOptions & {
12434
12447
  snapshot?: VmSpec;
12435
12448
  };
12436
- type VmSpecWithFn<T extends Record<string, VmWith>> = {
12437
- <K extends string, B extends VmWith>(name: K, builder: B): VmSpec<T & Record<K, B> & VmWithAddedFields<B>>;
12438
- <B extends VmWith>(builder: B): VmSpec<T & Record<VmWithDefaultField<B>, B> & VmWithAddedFields<B>>;
12449
+ type VmSpecWithFn<T extends Record<string, VmWithLike>> = {
12450
+ <K extends string, B extends VmWithLike>(name: K, builder: B): VmSpec<T & Record<K, B> & VmWithAddedFields<B>>;
12451
+ <B extends VmWithLike>(builder: B): VmSpec<T & Record<VmWithDefaultField<B>, B> & VmWithAddedFields<B>>;
12439
12452
  } & Partial<T>;
12440
- declare class VmSpec<T extends Record<string, VmWith> = {}> {
12453
+ declare class VmSpec<T extends Record<string, VmWithLike> = {}> {
12441
12454
  raw: VmSpecOptions;
12442
12455
  readonly with: VmSpecWithFn<T>;
12443
12456
  private withDiscriminators;
@@ -12462,6 +12475,8 @@ declare class VmSpec<T extends Record<string, VmWith> = {}> {
12462
12475
  discriminator(value: string): this;
12463
12476
  workdir(path: string): this;
12464
12477
  aptDeps(...deps: string[]): this;
12478
+ users(users: NonNullable<CreateVmOptions["users"]>): this;
12479
+ groups(groups: NonNullable<CreateVmOptions["groups"]>): this;
12465
12480
  additionalFiles(files: NonNullable<CreateVmOptions["additionalFiles"]>): this;
12466
12481
  runCommands(...commands: string[]): this;
12467
12482
  repo(repo: string, path: string): this;
@@ -12476,14 +12491,14 @@ declare class VmsNamespace {
12476
12491
  * @param options Optional VM configuration
12477
12492
  * @returns A VM instance representing the created VM
12478
12493
  */
12479
- create<T extends Record<string, VmWith>>(spec: VmSpec<T>): Promise<Omit<ResponsePostV1Vms200, "consoleUrl"> & {
12494
+ create<T extends Record<string, VmWithLike>>(spec: VmSpec<T>): Promise<Omit<ResponsePostV1Vms200, "consoleUrl"> & {
12480
12495
  vmId: string;
12481
12496
  vm: Vm & {
12482
12497
  [K in keyof T]: ReturnType<T[K]["createInstance"]>;
12483
12498
  };
12484
12499
  domains: string[];
12485
12500
  }>;
12486
- create<T extends Record<string, VmWith>>(options: CreateVmOptions & {
12501
+ create<T extends Record<string, VmWithLike>>(options: CreateVmOptions & {
12487
12502
  with?: T;
12488
12503
  template?: VmTemplate<T>;
12489
12504
  spec?: VmSpec<T>;
@@ -12506,7 +12521,7 @@ declare class VmsNamespace {
12506
12521
  * @param spec Optional spec to attach builders to the returned VM
12507
12522
  * @returns The VM instance configured with builders from the spec
12508
12523
  */
12509
- get<T extends Record<string, VmWith>>({ vmId, spec, }: {
12524
+ get<T extends Record<string, VmWithLike>>({ vmId, spec, }: {
12510
12525
  vmId: string;
12511
12526
  spec?: VmSpec<T>;
12512
12527
  }): Promise<{
@@ -12518,7 +12533,7 @@ declare class VmsNamespace {
12518
12533
  /**
12519
12534
  * Create a VM instance by ID without making an api call.
12520
12535
  */
12521
- ref<T extends Record<string, VmWith>>({ vmId, spec, }: {
12536
+ ref<T extends Record<string, VmWithLike>>({ vmId, spec, }: {
12522
12537
  vmId: string;
12523
12538
  spec?: VmSpec<T>;
12524
12539
  }): Vm & {
@@ -12531,7 +12546,7 @@ declare class VmsNamespace {
12531
12546
  declare class VmSnapshotsNamespace {
12532
12547
  private apiClient;
12533
12548
  constructor(apiClient: ApiClient);
12534
- ensure<T extends Record<string, VmWith>>(options: Omit<PostV1VmsSnapshotsRequestBody, "template"> & {
12549
+ ensure<T extends Record<string, VmWithLike>>(options: Omit<PostV1VmsSnapshotsRequestBody, "template"> & {
12535
12550
  template?: VmTemplate<T> | PostV1VmsSnapshotsRequestBody["template"];
12536
12551
  spec?: VmSpec<T>;
12537
12552
  snapshot?: VmSpec<T>;
package/index.d.mts CHANGED
@@ -12125,12 +12125,25 @@ declare class Systemd {
12125
12125
  * This is the instance attached to the VM after creation.
12126
12126
  */
12127
12127
  declare class VmWithInstance {
12128
- protected vm: Vm;
12128
+ vm: Vm;
12129
12129
  private _init;
12130
12130
  }
12131
- type VmWithDefaultField<B extends VmWith> = B extends VmWith<any, any, infer TDefaultField> ? TDefaultField : string;
12132
- type VmWithDefaultFieldRecord<B extends VmWith> = Record<VmWithDefaultField<B>, B>;
12133
- type VmWithAddedFields<B extends VmWith> = B extends VmWith<any, infer TAddedFields, any> ? TAddedFields : {};
12131
+ interface VmWithLike<TInstance = unknown, TAddedFields extends Record<string, VmWithLike<any, any, any>> = {}, TDefaultField extends string = string> {
12132
+ instance: TInstance;
12133
+ readonly defaultField?: TDefaultField;
12134
+ configure?(existingConfig: any): any;
12135
+ configureSpec?(spec: any): any;
12136
+ configureSnapshotSpec?(spec: any): any;
12137
+ configureBaseImage?(image: any): any;
12138
+ configureTemplate?(template: any): any;
12139
+ configureNestedTemplate?(template: any): any;
12140
+ createInstance(): TInstance;
12141
+ }
12142
+ type VmWithDefaultField<B extends VmWithLike> = B extends {
12143
+ defaultField?: infer TDefaultField;
12144
+ } ? Extract<TDefaultField, string> extends never ? string : Extract<TDefaultField, string> : string;
12145
+ type VmWithDefaultFieldRecord<B extends VmWithLike> = Record<VmWithDefaultField<B>, B>;
12146
+ type VmWithAddedFields<B extends VmWithLike> = B extends VmWith<any, infer TAddedFields, any> ? TAddedFields : {};
12134
12147
  /**
12135
12148
  * Base class for VM configuration builders that act as middleware.
12136
12149
  * Extend this class to create reusable VM components like DevServer, Database, etc.
@@ -12140,7 +12153,7 @@ type VmWithAddedFields<B extends VmWith> = B extends VmWith<any, infer TAddedFie
12140
12153
  * 2. Applies its own configuration
12141
12154
  * 3. Returns merged configuration
12142
12155
  */
12143
- declare abstract class VmWith<TInstance extends VmWithInstance = VmWithInstance, TAddedFields extends Record<string, VmWith> = {}, TDefaultField extends string = string> {
12156
+ declare abstract class VmWith<TInstance = VmWithInstance, TAddedFields extends Record<string, VmWithLike<any, any, any>> = {}, TDefaultField extends string = string> {
12144
12157
  instance: TInstance;
12145
12158
  readonly defaultField?: TDefaultField;
12146
12159
  protected readonly _addedFields?: TAddedFields;
@@ -12406,7 +12419,7 @@ type GitOptions = Omit<NonNullable<CreateSnapshotRequest["template"]["git"]>, "c
12406
12419
  * Template options with SystemdServiceInput support and optional git.config
12407
12420
  */
12408
12421
  type TemplateOptions = Omit<CreateSnapshotRequest["template"], "systemd" | "git"> & {
12409
- template?: VmTemplate<Record<string, VmWith>>;
12422
+ template?: VmTemplate<Record<string, VmWithLike>>;
12410
12423
  baseImage?: VmBaseImage | RawBaseImage | null;
12411
12424
  systemd?: null | {
12412
12425
  services?: SystemdServiceInput[] | null;
@@ -12423,7 +12436,7 @@ declare class VmBaseImage {
12423
12436
  hasFromInstruction(): boolean;
12424
12437
  toRaw(): RawBaseImage;
12425
12438
  }
12426
- declare class VmTemplate<T extends Record<string, VmWith> = {}> {
12439
+ declare class VmTemplate<T extends Record<string, VmWithLike> = {}> {
12427
12440
  raw: TemplateOptions;
12428
12441
  readonly with: Partial<T>;
12429
12442
  constructor(template: TemplateOptions & {
@@ -12433,11 +12446,11 @@ declare class VmTemplate<T extends Record<string, VmWith> = {}> {
12433
12446
  type VmSpecOptions = TemplateOptions & {
12434
12447
  snapshot?: VmSpec;
12435
12448
  };
12436
- type VmSpecWithFn<T extends Record<string, VmWith>> = {
12437
- <K extends string, B extends VmWith>(name: K, builder: B): VmSpec<T & Record<K, B> & VmWithAddedFields<B>>;
12438
- <B extends VmWith>(builder: B): VmSpec<T & Record<VmWithDefaultField<B>, B> & VmWithAddedFields<B>>;
12449
+ type VmSpecWithFn<T extends Record<string, VmWithLike>> = {
12450
+ <K extends string, B extends VmWithLike>(name: K, builder: B): VmSpec<T & Record<K, B> & VmWithAddedFields<B>>;
12451
+ <B extends VmWithLike>(builder: B): VmSpec<T & Record<VmWithDefaultField<B>, B> & VmWithAddedFields<B>>;
12439
12452
  } & Partial<T>;
12440
- declare class VmSpec<T extends Record<string, VmWith> = {}> {
12453
+ declare class VmSpec<T extends Record<string, VmWithLike> = {}> {
12441
12454
  raw: VmSpecOptions;
12442
12455
  readonly with: VmSpecWithFn<T>;
12443
12456
  private withDiscriminators;
@@ -12462,6 +12475,8 @@ declare class VmSpec<T extends Record<string, VmWith> = {}> {
12462
12475
  discriminator(value: string): this;
12463
12476
  workdir(path: string): this;
12464
12477
  aptDeps(...deps: string[]): this;
12478
+ users(users: NonNullable<CreateVmOptions["users"]>): this;
12479
+ groups(groups: NonNullable<CreateVmOptions["groups"]>): this;
12465
12480
  additionalFiles(files: NonNullable<CreateVmOptions["additionalFiles"]>): this;
12466
12481
  runCommands(...commands: string[]): this;
12467
12482
  repo(repo: string, path: string): this;
@@ -12476,14 +12491,14 @@ declare class VmsNamespace {
12476
12491
  * @param options Optional VM configuration
12477
12492
  * @returns A VM instance representing the created VM
12478
12493
  */
12479
- create<T extends Record<string, VmWith>>(spec: VmSpec<T>): Promise<Omit<ResponsePostV1Vms200, "consoleUrl"> & {
12494
+ create<T extends Record<string, VmWithLike>>(spec: VmSpec<T>): Promise<Omit<ResponsePostV1Vms200, "consoleUrl"> & {
12480
12495
  vmId: string;
12481
12496
  vm: Vm & {
12482
12497
  [K in keyof T]: ReturnType<T[K]["createInstance"]>;
12483
12498
  };
12484
12499
  domains: string[];
12485
12500
  }>;
12486
- create<T extends Record<string, VmWith>>(options: CreateVmOptions & {
12501
+ create<T extends Record<string, VmWithLike>>(options: CreateVmOptions & {
12487
12502
  with?: T;
12488
12503
  template?: VmTemplate<T>;
12489
12504
  spec?: VmSpec<T>;
@@ -12506,7 +12521,7 @@ declare class VmsNamespace {
12506
12521
  * @param spec Optional spec to attach builders to the returned VM
12507
12522
  * @returns The VM instance configured with builders from the spec
12508
12523
  */
12509
- get<T extends Record<string, VmWith>>({ vmId, spec, }: {
12524
+ get<T extends Record<string, VmWithLike>>({ vmId, spec, }: {
12510
12525
  vmId: string;
12511
12526
  spec?: VmSpec<T>;
12512
12527
  }): Promise<{
@@ -12518,7 +12533,7 @@ declare class VmsNamespace {
12518
12533
  /**
12519
12534
  * Create a VM instance by ID without making an api call.
12520
12535
  */
12521
- ref<T extends Record<string, VmWith>>({ vmId, spec, }: {
12536
+ ref<T extends Record<string, VmWithLike>>({ vmId, spec, }: {
12522
12537
  vmId: string;
12523
12538
  spec?: VmSpec<T>;
12524
12539
  }): Vm & {
@@ -12531,7 +12546,7 @@ declare class VmsNamespace {
12531
12546
  declare class VmSnapshotsNamespace {
12532
12547
  private apiClient;
12533
12548
  constructor(apiClient: ApiClient);
12534
- ensure<T extends Record<string, VmWith>>(options: Omit<PostV1VmsSnapshotsRequestBody, "template"> & {
12549
+ ensure<T extends Record<string, VmWithLike>>(options: Omit<PostV1VmsSnapshotsRequestBody, "template"> & {
12535
12550
  template?: VmTemplate<T> | PostV1VmsSnapshotsRequestBody["template"];
12536
12551
  spec?: VmSpec<T>;
12537
12552
  snapshot?: VmSpec<T>;
package/index.mjs CHANGED
@@ -5945,8 +5945,9 @@ function composeVmTemplates(templates) {
5945
5945
  );
5946
5946
  const mergedWith = {};
5947
5947
  for (const template of templates) {
5948
- for (const key in template.with) {
5949
- const builder = template.with[key];
5948
+ const builders = template.with ?? {};
5949
+ for (const key in builders) {
5950
+ const builder = builders[key];
5950
5951
  if (builder) {
5951
5952
  mergedWith[key] = builder;
5952
5953
  }
@@ -5982,8 +5983,9 @@ function composeVmSpecs(specs) {
5982
5983
  const mergedWithDiscriminators = {};
5983
5984
  for (const spec of specs) {
5984
5985
  const builderDiscriminators = spec.getBuilderDiscriminators();
5985
- for (const key in spec.builders) {
5986
- const builder = spec.builders[key];
5986
+ const builders = spec.builders ?? {};
5987
+ for (const key in builders) {
5988
+ const builder = builders[key];
5987
5989
  if (builder) {
5988
5990
  mergedWith[key] = builder;
5989
5991
  mergedWithDiscriminators[key] = builderDiscriminators[key];
@@ -6400,7 +6402,9 @@ class VmSpec {
6400
6402
  }
6401
6403
  snapshot() {
6402
6404
  const { snapshot: existingSnapshot, ...currentLayer } = this.raw;
6403
- const currentBuilders = { ...this.builders };
6405
+ const currentBuilders = {
6406
+ ...this.builders
6407
+ };
6404
6408
  const currentWithDiscriminators = this.getBuilderDiscriminators();
6405
6409
  const innerSnapshot = new VmSpec({
6406
6410
  ...currentLayer,
@@ -6454,6 +6458,14 @@ class VmSpec {
6454
6458
  const existing = this.raw.aptDeps ?? [];
6455
6459
  return this.mergeRaw({ aptDeps: [...existing, ...deps] });
6456
6460
  }
6461
+ users(users) {
6462
+ const existing = this.raw.users ?? [];
6463
+ return this.mergeRaw({ users: [...existing, ...users] });
6464
+ }
6465
+ groups(groups) {
6466
+ const existing = this.raw.groups ?? [];
6467
+ return this.mergeRaw({ groups: [...existing, ...groups] });
6468
+ }
6457
6469
  additionalFiles(files) {
6458
6470
  const existing = this.raw.additionalFiles ?? {};
6459
6471
  this.raw.additionalFiles = {
@@ -6754,7 +6766,11 @@ class VmsNamespace {
6754
6766
  ...rawTemplate ?? {},
6755
6767
  baseImage: serializedBaseImage
6756
6768
  } : rawTemplate;
6757
- const { baseImage: _baseImage, template: _template, ...requestConfig } = config;
6769
+ const {
6770
+ baseImage: _baseImage,
6771
+ template: _template,
6772
+ ...requestConfig
6773
+ } = config;
6758
6774
  const response = await this.freestyle._apiClient.post("/v1/vms", {
6759
6775
  body: {
6760
6776
  ...requestConfig,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "freestyle-sandboxes",
3
- "version": "0.1.37",
3
+ "version": "0.1.39",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  "require": {