@builder-builder/builder 0.0.15 → 0.0.17

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 (52) hide show
  1. package/dist/bb.d.ts +7 -5
  2. package/dist/bb.js +11 -9
  3. package/dist/entities/builder/builder.d.ts +14 -10
  4. package/dist/entities/builder/builder.js +9 -6
  5. package/dist/entities/builder/index.d.ts +1 -2
  6. package/dist/entities/builder/index.js +1 -2
  7. package/dist/entities/index.d.ts +2 -2
  8. package/dist/entities/index.js +1 -1
  9. package/dist/entities/kind.d.ts +1 -1
  10. package/dist/entities/model/methods.d.ts +3 -3
  11. package/dist/entities/pricing/expression.d.ts +70 -0
  12. package/dist/entities/pricing/expression.js +43 -0
  13. package/dist/entities/pricing/index.d.ts +6 -0
  14. package/dist/entities/pricing/index.js +3 -0
  15. package/dist/entities/pricing/pricing.d.ts +17 -0
  16. package/dist/entities/pricing/pricing.js +21 -0
  17. package/dist/entities/pricing/rates.d.ts +3 -0
  18. package/dist/entities/pricing/rates.js +3 -0
  19. package/dist/entities/serialise.d.ts +519 -543
  20. package/dist/entities/serialise.js +38 -33
  21. package/dist/entities/validated.d.ts +3 -3
  22. package/dist/environment.d.ts +1 -1
  23. package/dist/index.d.ts +3 -3
  24. package/dist/index.js +1 -1
  25. package/dist/mappers/index.d.ts +2 -2
  26. package/dist/mappers/index.js +1 -1
  27. package/dist/mappers/price.d.ts +3 -0
  28. package/dist/mappers/price.js +111 -0
  29. package/dist/validate/builder.js +15 -10
  30. package/dist/validate/errors.d.ts +13 -3
  31. package/dist/validate/errors.js +11 -3
  32. package/dist/validate/index.d.ts +1 -1
  33. package/dist/validate/model.js +5 -62
  34. package/dist/validate/paths.d.ts +5 -0
  35. package/dist/validate/paths.js +68 -0
  36. package/dist/validate/pricing.d.ts +5 -3
  37. package/dist/validate/pricing.js +95 -39
  38. package/dist/validate/ui.js +59 -1
  39. package/dist/validate/variants.js +4 -0
  40. package/package.json +1 -10
  41. package/dist/cli.d.ts +0 -2
  42. package/dist/cli.js +0 -53
  43. package/dist/codegen/index.d.ts +0 -7
  44. package/dist/codegen/index.js +0 -212
  45. package/dist/codegen/template.d.ts +0 -5
  46. package/dist/codegen/template.js +0 -17
  47. package/dist/entities/builder/factory.d.ts +0 -7
  48. package/dist/entities/builder/factory.js +0 -4
  49. package/dist/entities/pricing.d.ts +0 -64
  50. package/dist/entities/pricing.js +0 -48
  51. package/dist/mappers/pricing.d.ts +0 -3
  52. package/dist/mappers/pricing.js +0 -101
package/dist/bb.d.ts CHANGED
@@ -19,12 +19,14 @@ export type BB<Env extends BuilderEnvironment = 'production'> = {
19
19
  instance(entity: BuilderValidated | BuilderModelValidated, partial?: BuilderInstanceInput): BuilderInstance;
20
20
  render(builder: BuilderValidated, instance: BuilderInstanceValidated): BuilderRenderResult;
21
21
  order(model: BuilderModelValidated, instance: BuilderInstanceValidated, variants: BuilderComponentVariantsValidated): BuilderOrder;
22
- pricing(builder: BuilderValidated, order: BuilderOrder): number;
22
+ price(pricing: BuilderPricingValidated, order: BuilderOrder): number | null;
23
23
  variants(entity: BuilderValidated | BuilderModelValidated): BuilderComponentVariants;
24
24
  };
25
- export declare const bb: typeof bbProd & {
26
- dev: typeof bbDev;
25
+ export declare const bb: typeof bbProduction & {
26
+ development: typeof bbDevelopment;
27
+ staging: typeof bbProduction;
28
+ production: typeof bbProduction;
27
29
  };
28
- declare function bbProd(options?: BBOptions): BB<'production'>;
29
- declare function bbDev(options?: BBOptions): BB<'development'>;
30
+ declare function bbProduction(options?: BBOptions): BB<'production'>;
31
+ declare function bbDevelopment(options?: BBOptions): BB<'development'>;
30
32
  export {};
package/dist/bb.js CHANGED
@@ -1,12 +1,14 @@
1
1
  import { BuilderException } from './exception.js';
2
- import { assertValidated, createInstance, createVariants, order, pricing, render, validateBuilder, validateInstance, validateModel, validatePricing, validateUI, validateVariants } from './mappers/index.js';
3
- export const bb = Object.assign(bbProd, {
4
- dev: bbDev
2
+ import { assertValidated, createInstance, createVariants, order, price, render, validateBuilder, validateInstance, validateModel, validatePricing, validateUI, validateVariants } from './mappers/index.js';
3
+ export const bb = Object.assign(bbProduction, {
4
+ development: bbDevelopment,
5
+ staging: bbProduction,
6
+ production: bbProduction
5
7
  });
6
- function bbProd(options = {}) {
8
+ function bbProduction(options = {}) {
7
9
  return bbFactory('production', options.references);
8
10
  }
9
- function bbDev(options = {}) {
11
+ function bbDevelopment(options = {}) {
10
12
  return bbFactory('development', options.references);
11
13
  }
12
14
  function bbFactory(environment, references = []) {
@@ -14,7 +16,7 @@ function bbFactory(environment, references = []) {
14
16
  validate: {
15
17
  builder: (input) => throwInProd(validateBuilder(input, references)),
16
18
  model: (input) => throwInProd(validateModel(input, references)),
17
- pricing: (input) => throwInProd(validatePricing(input)),
19
+ pricing: (input) => throwInProd(validatePricing(input, references)),
18
20
  ui: (input) => throwInProd(validateUI(input, references)),
19
21
  instance: (model, instance) => throwInProd(validateInstance(model, instance)),
20
22
  variants: (model, input, variantOptions) => throwInProd(validateVariants(model, input, variantOptions))
@@ -34,9 +36,9 @@ function bbFactory(environment, references = []) {
34
36
  assertValidated(variants);
35
37
  return order(model, instance, variants, references);
36
38
  },
37
- pricing: (builder, orderResult) => {
38
- assertValidated(builder);
39
- return pricing(builder.model, builder.pricing, orderResult, references);
39
+ price: (pricing, order) => {
40
+ assertValidated(pricing);
41
+ return price(pricing, order);
40
42
  },
41
43
  variants: (entity) => {
42
44
  assertValidated(entity);
@@ -1,12 +1,14 @@
1
+ import type { BuilderModelSerialised } from '../model/model';
1
2
  import type { BuilderModelBindings, BuilderModelBoundState } from '../model/bind';
2
3
  import type { BuilderModelState } from '../model/state';
3
- import type { BuilderPricing } from '../pricing';
4
+ import type { BuilderPricingSerialised } from '../pricing/index';
4
5
  import type { BuilderTags } from '../tags';
5
- import type { Paramable, ParamableSerialised } from '../../references';
6
+ import type { BuilderUISerialised } from '../ui/ui';
6
7
  import type { BuilderBindings, BuilderBindingsSerialised } from './bind';
7
8
  import * as v from 'valibot';
8
- import { BuilderModel, BuilderModelSerialisedSchema } from '../model/index.js';
9
- import { BuilderUI, BuilderUISerialisedSchema } from '../ui/index.js';
9
+ import { BuilderModel } from '../model/index.js';
10
+ import { BuilderPricing } from '../pricing/index.js';
11
+ import { BuilderUI } from '../ui/index.js';
10
12
  export declare class Builder<State extends BuilderModelState = BuilderModelState> {
11
13
  #private;
12
14
  readonly type: 'builder';
@@ -14,18 +16,20 @@ export declare class Builder<State extends BuilderModelState = BuilderModelState
14
16
  readonly ui: BuilderUI;
15
17
  readonly bindings: BuilderBindings;
16
18
  readonly tags?: BuilderTags;
17
- readonly pricing?: Paramable<BuilderPricing>;
18
- constructor(model?: BuilderModel<State>, ui?: BuilderUI<import("..").BuilderModelGeneric>, bindings?: BuilderBindings, tags?: BuilderTags, pricing?: Paramable<BuilderPricing>);
19
+ readonly pricing: BuilderPricing;
20
+ constructor(model?: BuilderModel<State>, ui?: BuilderUI<import("..").BuilderModelGeneric>, pricing?: BuilderPricing, bindings?: BuilderBindings, tags?: BuilderTags);
19
21
  bind<const Bindings extends BuilderBindings>(extra: Bindings): Bindings extends BuilderModelBindings<State> ? Builder<BuilderModelBoundState<State, Bindings>> : Builder<State>;
20
22
  tag(...tags: Array<string>): Builder<State>;
21
- priced(pricing: Paramable<BuilderPricing>): Builder<State>;
23
+ priced(pricing: BuilderPricing): Builder<State>;
22
24
  }
23
25
  export declare const BuilderSchema: v.InstanceSchema<typeof Builder, undefined>;
26
+ export declare function builder(): Builder<BuilderModelState>;
27
+ export declare function builder<const State extends BuilderModelState>(model: BuilderModel<State>, ui?: BuilderUI, pricing?: BuilderPricing): Builder<State>;
24
28
  export interface BuilderSerialised {
25
- readonly model: v.InferOutput<typeof BuilderModelSerialisedSchema>;
26
- readonly ui: v.InferOutput<typeof BuilderUISerialisedSchema>;
29
+ readonly model: BuilderModelSerialised;
30
+ readonly ui: BuilderUISerialised;
27
31
  readonly bindings: BuilderBindingsSerialised;
28
32
  readonly tags?: BuilderTags;
29
- readonly pricing?: ParamableSerialised<BuilderPricing>;
33
+ readonly pricing: BuilderPricingSerialised;
30
34
  }
31
35
  export declare const BuilderSerialisedSchema: v.GenericSchema<BuilderSerialised>;
@@ -1,8 +1,8 @@
1
1
  import * as v from 'valibot';
2
- import { BuilderRefSerialisedSchema, paramable } from '../../references.js';
2
+ import { BuilderRefSerialisedSchema } from '../../references.js';
3
3
  import { serialisable } from '../../serialisable.js';
4
4
  import { BuilderModel, BuilderModelSerialisedSchema } from '../model/index.js';
5
- import { BuilderPricingSchema } from '../pricing.js';
5
+ import { BuilderPricing, BuilderPricingSerialisedSchema } from '../pricing/index.js';
6
6
  import { BuilderTagsSchema } from '../tags.js';
7
7
  import { BuilderUI, BuilderUISerialisedSchema } from '../ui/index.js';
8
8
  export class Builder {
@@ -11,15 +11,15 @@ export class Builder {
11
11
  bindings;
12
12
  tags;
13
13
  pricing;
14
- constructor(model = new BuilderModel(), ui = new BuilderUI([], [], []), bindings = {}, tags, pricing) {
14
+ constructor(model = new BuilderModel(), ui = new BuilderUI([], [], []), pricing = new BuilderPricing(), bindings = {}, tags) {
15
15
  this.model = model;
16
16
  this.ui = ui;
17
+ this.pricing = pricing;
17
18
  this.bindings = bindings;
18
19
  this.tags = tags;
19
- this.pricing = pricing;
20
20
  }
21
21
  #next(patch) {
22
- return new Builder(this.model, this.ui, patch.bindings ?? this.bindings, patch.tags ?? this.tags, patch.pricing ?? this.pricing);
22
+ return new Builder(this.model, this.ui, patch.pricing ?? this.pricing, patch.bindings ?? this.bindings, patch.tags ?? this.tags);
23
23
  }
24
24
  bind(extra) {
25
25
  return this.#next({
@@ -34,10 +34,13 @@ export class Builder {
34
34
  }
35
35
  }
36
36
  export const BuilderSchema = v.instance(Builder);
37
+ export function builder(model, ui, pricing) {
38
+ return new Builder(model, ui, pricing);
39
+ }
37
40
  export const BuilderSerialisedSchema = serialisable(v.object({
38
41
  model: BuilderModelSerialisedSchema,
39
42
  ui: BuilderUISerialisedSchema,
40
43
  bindings: v.pipe(v.record(v.string(), v.union([BuilderRefSerialisedSchema, v.unknown()])), v.readonly()),
41
44
  tags: v.optional(BuilderTagsSchema),
42
- pricing: v.optional(paramable(BuilderPricingSchema))
45
+ pricing: BuilderPricingSerialisedSchema
43
46
  }));
@@ -1,4 +1,3 @@
1
1
  export type { BuilderBindings, BuilderBindingsSerialised } from './bind';
2
2
  export type { BuilderSerialised } from './builder';
3
- export { Builder, BuilderSchema, BuilderSerialisedSchema } from './builder.js';
4
- export { builder } from './factory.js';
3
+ export { Builder, builder, BuilderSchema, BuilderSerialisedSchema } from './builder.js';
@@ -1,2 +1 @@
1
- export { Builder, BuilderSchema, BuilderSerialisedSchema } from './builder.js';
2
- export { builder } from './factory.js';
1
+ export { Builder, builder, BuilderSchema, BuilderSerialisedSchema } from './builder.js';
@@ -7,7 +7,7 @@ export type { BuilderModelEntrySerialised } from './entry';
7
7
  export type { BuilderInstanceOf, BuilderModelGeneric, BuilderModels, BuilderModelSerialised, BuilderModelState, BuilderModelStateEmpty, BuilderModelStateOf } from './model/index';
8
8
  export { BuilderModel, BuilderModelSchema, BuilderModelSerialisedSchema, model, modelsMerge } from './model/index.js';
9
9
  export type { BuilderOptionPayload, BuilderOptions, BuilderOptionSerialised, BuilderOptionsSerialised, BuilderOptionValues, BuilderOptionValuesSerialised, BuilderOptionWhen, BuilderOptionWhenSerialised, BuilderSelectTypeLabels, BuilderSelectTypeSerialised, BuilderSelectTypeValues, BuilderToggleTypeSerialised, BuilderToggleValueType } from './option/index';
10
- export type { BuilderPricing, BuilderPricingExpression, BuilderPricingReduce, BuilderPricingTagExpression } from './pricing';
10
+ export type { BuilderPricingExpression, BuilderPricingLookupKey, BuilderPricingReduce, BuilderPricingSerialised, BuilderRates } from './pricing/index';
11
11
  export type { BuilderRefEntities, BuilderRefEntity } from './refs.js';
12
12
  export type { BuilderTags } from './tags';
13
13
  export type { BuilderDescription, BuilderDescriptionItem, BuilderUIDescribeSerialised, BuilderUIInputMetadata, BuilderUIInputMetadataSerialised, BuilderUIInputs, BuilderUIInputsSerialised, BuilderUIInputSerialised, BuilderUIItem, BuilderUIItems, BuilderUIItemSerialised, BuilderUIItemsSerialised, BuilderUIPageSerialised, BuilderUIPagesSerialised, BuilderUIs, BuilderUIsSerialised, BuilderUISerialised } from './ui/index';
@@ -17,7 +17,7 @@ export { Builder, builder, BuilderSchema, BuilderSerialisedSchema } from './buil
17
17
  export { BuilderCollection, BuilderCollectionConfig, BuilderCollectionConfigSchema, BuilderCollectionConfigSerialisedSchema, BuilderCollectionSchema, BuilderCollectionSelectMapSerialisedSchema, BuilderCollectionSerialisedSchema, BuilderCollectionsSerialisedSchema, BuilderCollectionWhenSerialisedSchema, collectionConfig, collectionExpectation, collectionWhen } from './collection/index.js';
18
18
  export { BuilderComponent, BuilderComponentDetails, BuilderComponentDetailsSchema, BuilderComponentDetailsSerialisedSchema, BuilderComponentField, BuilderComponentFieldSchema, BuilderComponentFieldSerialisedSchema, BuilderComponentFieldsSchema, BuilderComponentFieldsSerialisedSchema, BuilderComponentFieldValueTypeSchema, BuilderComponentSchema, BuilderComponentSelectMapSerialisedSchema, BuilderComponentSerialisedSchema, BuilderComponentsSerialisedSchema, BuilderComponentWhenSerialisedSchema, componentDetails, componentExpectation, componentWhen, detailBoolean, detailNumber, detailString, detailValueSchema } from './component/index.js';
19
19
  export { parameter, ref } from '../references.js';
20
- export { BuilderPricingExpressionSchema, BuilderPricingReduceSchema, BuilderPricingSchema, BuilderPricingTagExpressionSchema } from './pricing.js';
20
+ export { BuilderPricing, BuilderPricingExpressionSchema, BuilderPricingLookupKeySchema, BuilderPricingReduceSchema, BuilderPricingSchema, BuilderPricingSerialisedSchema, BuilderRatesSchema, pricing } from './pricing/index.js';
21
21
  export { BuilderTagsSchema } from './tags.js';
22
22
  export { BuilderExpectation, BuilderExpectationKindSchema, BuilderExpectationSchema, BuilderExpectationSerialisedSchema, BuilderExpectationsSchema, BuilderExpectationsSerialisedSchema } from './expectation.js';
23
23
  export { BuilderEntityKindSchema, BuilderEntitySerialisedSchema } from './kind.js';
@@ -3,7 +3,7 @@ export { Builder, builder, BuilderSchema, BuilderSerialisedSchema } from './buil
3
3
  export { BuilderCollection, BuilderCollectionConfig, BuilderCollectionConfigSchema, BuilderCollectionConfigSerialisedSchema, BuilderCollectionSchema, BuilderCollectionSelectMapSerialisedSchema, BuilderCollectionSerialisedSchema, BuilderCollectionsSerialisedSchema, BuilderCollectionWhenSerialisedSchema, collectionConfig, collectionExpectation, collectionWhen } from './collection/index.js';
4
4
  export { BuilderComponent, BuilderComponentDetails, BuilderComponentDetailsSchema, BuilderComponentDetailsSerialisedSchema, BuilderComponentField, BuilderComponentFieldSchema, BuilderComponentFieldSerialisedSchema, BuilderComponentFieldsSchema, BuilderComponentFieldsSerialisedSchema, BuilderComponentFieldValueTypeSchema, BuilderComponentSchema, BuilderComponentSelectMapSerialisedSchema, BuilderComponentSerialisedSchema, BuilderComponentsSerialisedSchema, BuilderComponentWhenSerialisedSchema, componentDetails, componentExpectation, componentWhen, detailBoolean, detailNumber, detailString, detailValueSchema } from './component/index.js';
5
5
  export { parameter, ref } from '../references.js';
6
- export { BuilderPricingExpressionSchema, BuilderPricingReduceSchema, BuilderPricingSchema, BuilderPricingTagExpressionSchema } from './pricing.js';
6
+ export { BuilderPricing, BuilderPricingExpressionSchema, BuilderPricingLookupKeySchema, BuilderPricingReduceSchema, BuilderPricingSchema, BuilderPricingSerialisedSchema, BuilderRatesSchema, pricing } from './pricing/index.js';
7
7
  export { BuilderTagsSchema } from './tags.js';
8
8
  export { BuilderExpectation, BuilderExpectationKindSchema, BuilderExpectationSchema, BuilderExpectationSerialisedSchema, BuilderExpectationsSchema, BuilderExpectationsSerialisedSchema } from './expectation.js';
9
9
  export { BuilderEntityKindSchema, BuilderEntitySerialisedSchema } from './kind.js';
@@ -2,7 +2,7 @@ import type { EntitiesMap } from './serialise';
2
2
  import * as v from 'valibot';
3
3
  import { entitiesMap } from './serialise.js';
4
4
  export type BuilderEntityKind = keyof typeof entitiesMap;
5
- export declare const BuilderEntityKindSchema: v.PicklistSchema<readonly ("string" | "number" | "boolean" | "builder" | "model" | "pricing" | "ui" | "select" | "toggle" | "path" | "uiPage" | "uiDescribe" | "uiPages" | "uiInput" | "componentDetails" | "collectionConfig" | "expectations" | "uiItems" | "optionWhen" | "componentWhen" | "collectionWhen" | "optionSelectMap" | "componentSelectMap" | "collectionSelectMap" | "paths")[], undefined>;
5
+ export declare const BuilderEntityKindSchema: v.PicklistSchema<readonly ("string" | "number" | "boolean" | "builder" | "model" | "pricing" | "ui" | "select" | "toggle" | "path" | "optionSelectMap" | "optionWhen" | "componentDetails" | "componentSelectMap" | "componentWhen" | "collectionConfig" | "collectionSelectMap" | "collectionWhen" | "uiDescribe" | "uiItems" | "uiPage" | "uiPages" | "uiInput" | "pricingRates" | "expectations" | "paths")[], undefined>;
6
6
  export type BuilderEntitySerialised = {
7
7
  [Kind in keyof EntitiesMap]: v.InferOutput<EntitiesMap[Kind]['serialised']>;
8
8
  }[keyof EntitiesMap];
@@ -46,12 +46,12 @@ type CollectionInstanceOf<Collection extends BuilderCollection> = [Collection['p
46
46
  type CollectionShape<Collection extends BuilderCollection, Item> = Collection['payload'] extends BuilderCollectionConfig ? Collection['payload']['min'] extends number ? Collection['payload']['max'] extends number ? number extends Collection['payload']['min'] ? ReadonlyArray<Item> : number extends Collection['payload']['max'] ? ReadonlyArray<Item> : Collection['payload']['min'] extends Collection['payload']['max'] ? CollectionTuple<Item, Collection['payload']['min']> : ReadonlyArray<Item> : ReadonlyArray<Item> : ReadonlyArray<Item> : ReadonlyArray<Item>;
47
47
  type CollectionTuple<Item, Length extends number, Result extends ReadonlyArray<Item> = []> = Result['length'] extends Length ? Result : CollectionTuple<Item, Length, [...Result, Item]>;
48
48
  export declare function builderOptionMethod(): ((name: string, payload: Paramable<BuilderOptionValues>) => BuilderOption<string, Paramable<import("..").BuilderSelectType<readonly [string, ...string[]], import("valibot").GenericSchema<string | null>> | import("..").BuilderToggleType<import("valibot").GenericSchema<string | number | boolean | null>>>, Paramable<readonly (readonly (string | number)[])[]>>) & {
49
- when(paths: Paramable<BuilderPaths>, name: string, payload: Paramable<BuilderOptionWhen>): BuilderOption<string, Paramable<BuilderOptionWhen>, readonly (readonly (string | number)[])[] | import("../..").BuilderRef | BuilderParameter<string>>;
49
+ when(paths: Paramable<BuilderPaths>, name: string, payload: Paramable<BuilderOptionWhen>): BuilderOption<string, Paramable<BuilderOptionWhen>, readonly (readonly (string | number)[])[] | BuilderParameter<string> | import("../..").BuilderRef>;
50
50
  };
51
51
  export declare function builderComponentMethod(): ((name: string, payload?: Paramable<BuilderComponentDetails>) => BuilderComponent<string, Paramable<BuilderComponentDetails<Paramable<readonly import("..").BuilderComponentField<string, import("valibot").GenericSchema<string | number | boolean | null>>[]>>>, Paramable<readonly (readonly (string | number)[])[]>>) & {
52
- when(paths: Paramable<BuilderPaths>, name: string, payload?: Paramable<BuilderComponentWhen>): BuilderComponent<string, Paramable<BuilderComponentWhen>, readonly (readonly (string | number)[])[] | import("../..").BuilderRef | BuilderParameter<string>>;
52
+ when(paths: Paramable<BuilderPaths>, name: string, payload?: Paramable<BuilderComponentWhen>): BuilderComponent<string, Paramable<BuilderComponentWhen>, readonly (readonly (string | number)[])[] | BuilderParameter<string> | import("../..").BuilderRef>;
53
53
  };
54
54
  export declare function builderCollectionMethod(): ((name: string, payload: Paramable<BuilderCollectionConfig>) => BuilderCollection<string, Paramable<BuilderCollectionConfig<Paramable<import("./model").BuilderModelGeneric>, Paramable<number>, Paramable<number>>>, Paramable<readonly (readonly (string | number)[])[]>>) & {
55
- when(paths: Paramable<BuilderPaths>, name: string, payload: Paramable<BuilderCollectionWhen>): BuilderCollection<string, Paramable<BuilderCollectionWhen>, readonly (readonly (string | number)[])[] | import("../..").BuilderRef | BuilderParameter<string>>;
55
+ when(paths: Paramable<BuilderPaths>, name: string, payload: Paramable<BuilderCollectionWhen>): BuilderCollection<string, Paramable<BuilderCollectionWhen>, readonly (readonly (string | number)[])[] | BuilderParameter<string> | import("../..").BuilderRef>;
56
56
  };
57
57
  export {};
@@ -0,0 +1,70 @@
1
+ import type { Paramable, ParamableSerialised } from '../../references';
2
+ import * as v from 'valibot';
3
+ export declare const BuilderPricingReduceSchema: v.PicklistSchema<["product", "sum", "first"], undefined>;
4
+ export type BuilderPricingReduce = v.InferOutput<typeof BuilderPricingReduceSchema>;
5
+ export type BuilderPricingLookupKey = {
6
+ readonly kind: 'variantTags';
7
+ } | {
8
+ readonly kind: 'option';
9
+ readonly name: string;
10
+ };
11
+ export declare const BuilderPricingLookupKeySchema: v.GenericSchema<BuilderPricingLookupKey>;
12
+ export type BuilderPricingExpression = number | {
13
+ readonly kind: 'variantPrice';
14
+ } | {
15
+ readonly kind: 'lookup';
16
+ readonly rate: string;
17
+ readonly key: BuilderPricingLookupKey;
18
+ readonly reduce?: BuilderPricingReduce;
19
+ } | {
20
+ readonly kind: 'variants';
21
+ readonly tag?: string;
22
+ readonly expression: Paramable<BuilderPricingExpression>;
23
+ readonly reduce?: BuilderPricingReduce;
24
+ } | {
25
+ readonly kind: 'add';
26
+ readonly left: Paramable<BuilderPricingExpression>;
27
+ readonly right: Paramable<BuilderPricingExpression>;
28
+ } | {
29
+ readonly kind: 'sub';
30
+ readonly left: Paramable<BuilderPricingExpression>;
31
+ readonly right: Paramable<BuilderPricingExpression>;
32
+ } | {
33
+ readonly kind: 'mul';
34
+ readonly left: Paramable<BuilderPricingExpression>;
35
+ readonly right: Paramable<BuilderPricingExpression>;
36
+ } | {
37
+ readonly kind: 'div';
38
+ readonly left: Paramable<BuilderPricingExpression>;
39
+ readonly right: Paramable<BuilderPricingExpression>;
40
+ };
41
+ export type BuilderPricingExpressionSerialised = number | {
42
+ readonly kind: 'variantPrice';
43
+ } | {
44
+ readonly kind: 'lookup';
45
+ readonly rate: string;
46
+ readonly key: BuilderPricingLookupKey;
47
+ readonly reduce?: BuilderPricingReduce;
48
+ } | {
49
+ readonly kind: 'variants';
50
+ readonly tag?: string;
51
+ readonly expression: ParamableSerialised<BuilderPricingExpressionSerialised>;
52
+ readonly reduce?: BuilderPricingReduce;
53
+ } | {
54
+ readonly kind: 'add';
55
+ readonly left: ParamableSerialised<BuilderPricingExpressionSerialised>;
56
+ readonly right: ParamableSerialised<BuilderPricingExpressionSerialised>;
57
+ } | {
58
+ readonly kind: 'sub';
59
+ readonly left: ParamableSerialised<BuilderPricingExpressionSerialised>;
60
+ readonly right: ParamableSerialised<BuilderPricingExpressionSerialised>;
61
+ } | {
62
+ readonly kind: 'mul';
63
+ readonly left: ParamableSerialised<BuilderPricingExpressionSerialised>;
64
+ readonly right: ParamableSerialised<BuilderPricingExpressionSerialised>;
65
+ } | {
66
+ readonly kind: 'div';
67
+ readonly left: ParamableSerialised<BuilderPricingExpressionSerialised>;
68
+ readonly right: ParamableSerialised<BuilderPricingExpressionSerialised>;
69
+ };
70
+ export declare const BuilderPricingExpressionSchema: v.GenericSchema<BuilderPricingExpression>;
@@ -0,0 +1,43 @@
1
+ import * as v from 'valibot';
2
+ import { paramable } from '../../references.js';
3
+ export const BuilderPricingReduceSchema = v.picklist(['product', 'sum', 'first']);
4
+ export const BuilderPricingLookupKeySchema = v.variant('kind', [
5
+ v.object({ kind: v.literal('variantTags') }),
6
+ v.object({ kind: v.literal('option'), name: v.string() })
7
+ ]);
8
+ export const BuilderPricingExpressionSchema = v.lazy(() => v.union([
9
+ v.number(),
10
+ v.object({ kind: v.literal('variantPrice') }),
11
+ v.object({
12
+ kind: v.literal('lookup'),
13
+ rate: v.string(),
14
+ key: BuilderPricingLookupKeySchema,
15
+ reduce: v.optional(BuilderPricingReduceSchema)
16
+ }),
17
+ v.object({
18
+ kind: v.literal('variants'),
19
+ tag: v.optional(v.string()),
20
+ expression: paramable(BuilderPricingExpressionSchema),
21
+ reduce: v.optional(BuilderPricingReduceSchema)
22
+ }),
23
+ v.object({
24
+ kind: v.literal('add'),
25
+ left: paramable(BuilderPricingExpressionSchema),
26
+ right: paramable(BuilderPricingExpressionSchema)
27
+ }),
28
+ v.object({
29
+ kind: v.literal('sub'),
30
+ left: paramable(BuilderPricingExpressionSchema),
31
+ right: paramable(BuilderPricingExpressionSchema)
32
+ }),
33
+ v.object({
34
+ kind: v.literal('mul'),
35
+ left: paramable(BuilderPricingExpressionSchema),
36
+ right: paramable(BuilderPricingExpressionSchema)
37
+ }),
38
+ v.object({
39
+ kind: v.literal('div'),
40
+ left: paramable(BuilderPricingExpressionSchema),
41
+ right: paramable(BuilderPricingExpressionSchema)
42
+ })
43
+ ]));
@@ -0,0 +1,6 @@
1
+ export type { BuilderPricingExpression, BuilderPricingLookupKey, BuilderPricingReduce } from './expression';
2
+ export type { BuilderRates } from './rates';
3
+ export type { BuilderPricingSerialised } from './pricing';
4
+ export { BuilderPricingExpressionSchema, BuilderPricingLookupKeySchema, BuilderPricingReduceSchema } from './expression.js';
5
+ export { BuilderRatesSchema } from './rates.js';
6
+ export { BuilderPricing, BuilderPricingSchema, BuilderPricingSerialisedSchema, pricing } from './pricing.js';
@@ -0,0 +1,3 @@
1
+ export { BuilderPricingExpressionSchema, BuilderPricingLookupKeySchema, BuilderPricingReduceSchema } from './expression.js';
2
+ export { BuilderRatesSchema } from './rates.js';
3
+ export { BuilderPricing, BuilderPricingSchema, BuilderPricingSerialisedSchema, pricing } from './pricing.js';
@@ -0,0 +1,17 @@
1
+ import type { Paramable, ParamableSerialised } from '../../references';
2
+ import type { BuilderPricingExpression } from './expression';
3
+ import type { BuilderRates } from './rates';
4
+ import * as v from 'valibot';
5
+ export declare class BuilderPricing {
6
+ readonly type: 'pricing';
7
+ readonly rates: ReadonlyArray<Paramable<BuilderRates>>;
8
+ readonly formula: BuilderPricingExpression | null;
9
+ constructor(formula?: BuilderPricingExpression | null, rates?: ReadonlyArray<Paramable<BuilderRates>>);
10
+ }
11
+ export declare const BuilderPricingSchema: v.InstanceSchema<typeof BuilderPricing, undefined>;
12
+ export interface BuilderPricingSerialised {
13
+ readonly rates: ReadonlyArray<ParamableSerialised<BuilderRates>>;
14
+ readonly formula: BuilderPricingExpression | null;
15
+ }
16
+ export declare const BuilderPricingSerialisedSchema: v.GenericSchema<BuilderPricingSerialised>;
17
+ export declare function pricing(formula?: BuilderPricingExpression | null, rates?: ReadonlyArray<Paramable<BuilderRates>>): BuilderPricing;
@@ -0,0 +1,21 @@
1
+ import * as v from 'valibot';
2
+ import { paramable } from '../../references.js';
3
+ import { serialisable } from '../../serialisable.js';
4
+ import { BuilderPricingExpressionSchema } from './expression.js';
5
+ import { BuilderRatesSchema } from './rates.js';
6
+ export class BuilderPricing {
7
+ rates;
8
+ formula;
9
+ constructor(formula = null, rates) {
10
+ this.formula = formula;
11
+ this.rates = rates ?? [];
12
+ }
13
+ }
14
+ export const BuilderPricingSchema = v.instance(BuilderPricing);
15
+ export const BuilderPricingSerialisedSchema = serialisable(v.object({
16
+ rates: v.pipe(v.array(paramable(BuilderRatesSchema)), v.readonly()),
17
+ formula: v.nullable(BuilderPricingExpressionSchema)
18
+ }));
19
+ export function pricing(formula = null, rates) {
20
+ return new BuilderPricing(formula, rates);
21
+ }
@@ -0,0 +1,3 @@
1
+ import * as v from 'valibot';
2
+ export type BuilderRates = Record<string, Record<string, number>>;
3
+ export declare const BuilderRatesSchema: v.GenericSchema<BuilderRates>;
@@ -0,0 +1,3 @@
1
+ import * as v from 'valibot';
2
+ import { serialisable } from '../../serialisable.js';
3
+ export const BuilderRatesSchema = serialisable(v.record(v.string(), v.record(v.string(), v.number())));