@skmtc/core 0.0.329 → 0.0.331

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.
@@ -3,12 +3,12 @@ import type { RegisterArgs } from '../context/GenerateContext.js';
3
3
  import type { GeneratorKey } from '../types/GeneratorKeys.js';
4
4
  type ValueBaseArgs = {
5
5
  context: GenerateContext;
6
- generatorKey?: GeneratorKey;
6
+ generatorKey: GeneratorKey;
7
7
  };
8
8
  export declare class ValueBase {
9
9
  context: GenerateContext;
10
10
  skipped: boolean;
11
- generatorKey: GeneratorKey | undefined;
11
+ generatorKey: GeneratorKey;
12
12
  constructor({ context, generatorKey }: ValueBaseArgs);
13
13
  register(args: RegisterArgs): void;
14
14
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ValueBase.d.ts","sourceRoot":"","sources":["../../src/dsl/ValueBase.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AACpE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAA;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAE7D,KAAK,aAAa,GAAG;IACnB,OAAO,EAAE,eAAe,CAAA;IACxB,YAAY,CAAC,EAAE,YAAY,CAAA;CAC5B,CAAA;AAED,qBAAa,SAAS;IACpB,OAAO,EAAE,eAAe,CAAA;IACxB,OAAO,EAAE,OAAO,CAAQ;IACxB,YAAY,EAAE,YAAY,GAAG,SAAS,CAAA;gBAE1B,EAAE,OAAO,EAAE,YAAY,EAAE,EAAE,aAAa;IAOpD,QAAQ,CAAC,IAAI,EAAE,YAAY;CAG5B"}
1
+ {"version":3,"file":"ValueBase.d.ts","sourceRoot":"","sources":["../../src/dsl/ValueBase.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AACpE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAA;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAE7D,KAAK,aAAa,GAAG;IACnB,OAAO,EAAE,eAAe,CAAA;IACxB,YAAY,EAAE,YAAY,CAAA;CAC3B,CAAA;AAED,qBAAa,SAAS;IACpB,OAAO,EAAE,eAAe,CAAA;IACxB,OAAO,EAAE,OAAO,CAAQ;IACxB,YAAY,EAAE,YAAY,CAAA;gBAEd,EAAE,OAAO,EAAE,YAAY,EAAE,EAAE,aAAa;IAOpD,QAAQ,CAAC,IAAI,EAAE,YAAY;CAG5B"}
@@ -31,9 +31,10 @@ const proxyHandler = {
31
31
  return propertyName === 'toString'
32
32
  ? new Proxy(target[propertyName], {
33
33
  apply: (toString, thisArg) => {
34
- if (target.generatorKey) {
35
- target.context.callback(target.generatorKey);
34
+ if (!target.generatorKey) {
35
+ throw new Error('generatorKey is required');
36
36
  }
37
+ target.context.callback(target.generatorKey);
37
38
  return toString.apply(thisArg);
38
39
  }
39
40
  })
@@ -49,7 +49,7 @@ export declare const toOperationInsertable: (config: OperationConfig) => {
49
49
  register(args: Partial<import("../context/GenerateContext.js").RegisterArgs>): void;
50
50
  context: GenerateContext;
51
51
  skipped: boolean;
52
- generatorKey: import("../types/GeneratorKeys.js").GeneratorKey | undefined;
52
+ generatorKey: import("../types/GeneratorKeys.js").GeneratorKey;
53
53
  };
54
54
  id: string;
55
55
  entityType: EntityType;
@@ -84,7 +84,7 @@ export declare const toModelInsertable: (config: ModelConfig) => {
84
84
  register(args: Partial<import("../context/GenerateContext.js").RegisterArgs>): void;
85
85
  context: GenerateContext;
86
86
  skipped: boolean;
87
- generatorKey: import("../types/GeneratorKeys.js").GeneratorKey | undefined;
87
+ generatorKey: import("../types/GeneratorKeys.js").GeneratorKey;
88
88
  };
89
89
  id: string;
90
90
  type: "model";
@@ -20,13 +20,17 @@ export type OperationFields = {
20
20
  responses: Record<string, OasResponse | OasRef<'response'>>;
21
21
  deprecated: boolean | undefined;
22
22
  };
23
+ type ToRequestBodyMapArgs = {
24
+ schema: OasSchema | OasRef<'schema'>;
25
+ requestBody: OasRequestBody;
26
+ };
23
27
  /** Operation represents a resource path and a method that can be enacted against it */
24
28
  export declare class OasOperation {
25
29
  #private;
26
30
  oasType: 'operation';
27
31
  constructor(fields: OperationFields);
28
32
  toSuccessResponse(): OasResponse | OasRef<'response'>;
29
- toRequestBody(mediaType?: string): OasSchema | OasRef<'schema'> | undefined;
33
+ toRequestBody<V>(map: ({ schema, requestBody }: ToRequestBodyMapArgs) => V, mediaType?: string): V | undefined;
30
34
  /**
31
35
  * Resolve all parameters and optionally filter by location
32
36
  *
@@ -47,4 +51,5 @@ export declare class OasOperation {
47
51
  get responses(): Record<string, OasResponse | OasRef<'response'>>;
48
52
  get deprecated(): boolean | undefined;
49
53
  }
54
+ export {};
50
55
  //# sourceMappingURL=Operation.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Operation.d.ts","sourceRoot":"","sources":["../../../src/oas/operation/Operation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAA;AACnE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAA;AAC3E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAE/C,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM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AAC,EAAE,GAAG,SAAS,CAEnE;IAED,IAAI,WAAW,IAAI,cAAc,GAAG,MAAM,CAAC,aAAa,CAAC,GAAG,SAAS,CAEpE;IAED,IAAI,SAAS,IAAI,MAAM,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,CAEhE;IAED,IAAI,UAAU,IAAI,OAAO,GAAG,SAAS,CAEpC;CACF"}
@@ -31,8 +31,10 @@ export class OasOperation {
31
31
  .find(httpCode => httpCode >= 200 && httpCode < 300);
32
32
  return successCode ? httpCodeResponses[successCode] : defaultResponse;
33
33
  }
34
- toRequestBody(mediaType = 'application/json') {
35
- return this.requestBody?.resolve().content[mediaType]?.schema;
34
+ toRequestBody(map, mediaType = 'application/json') {
35
+ const requestBody = this.requestBody?.resolve();
36
+ const schema = requestBody?.content[mediaType]?.schema;
37
+ return schema ? map({ schema, requestBody }) : undefined;
36
38
  }
37
39
  /**
38
40
  * Resolve all parameters and optionally filter by location
@@ -26,7 +26,7 @@ export declare class FunctionParameter {
26
26
  properties: ParameterProperties;
27
27
  constructor(args: CreateArgs);
28
28
  hasProperty(name: string): boolean;
29
- toPropertyList(): List<string>;
29
+ toPropertyList(): List;
30
30
  toInbound(): string;
31
31
  toString(): string;
32
32
  }
@@ -1 +1 @@
1
- {"version":3,"file":"FunctionParameter.d.ts","sourceRoot":"","sources":["../../src/typescript/FunctionParameter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EACf,cAAc,EACf,MAAM,wBAAwB,CAAA;AAC/B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,EAAE,IAAI,EAAkB,MAAM,WAAW,CAAA;AAEhD,KAAK,UAAU,GAAG;IAChB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,cAAc,EAAE,UAAU,CAAC,gBAAgB,GAAG,cAAc,CAAC,CAAA;IAC7D,WAAW,CAAC,EAAE,OAAO,CAAA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AK,mBAAmB,GACpB,aAAa,GACb,qBAAqB,GACrB,gBAAgB,CAAA;AAEpB,KAAK,aAAa,GAAG;IACnB,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED,KAAK,qBAAqB,GAAG;IAC3B,IAAI,EAAE,cAAc,CAAA;IACpB,cAAc,EAAE,UAAU,CAAC,gBAAgB,CAAC,CAAA;IAC5C,QAAQ,EAAE,IAAI,CAAA;CACf,CAAA;AAED,KAAK,gBAAgB,GAAG;IACtB,IAAI,EAAE,SAAS,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,cAAc,EAAE,UAAU,CAAC,eAAe,CAAC,CAAA;IAC3C,QAAQ,EAAE,OAAO,CAAA;CAClB,CAAA;AAED,qBAAa,iBAAiB;IAC5B,UAAU,EAAE,mBAAmB,CAAA;gBAEnB,IAAI,EAAE,UAAU;IAyB5B,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAelC,cAAc,IAAI,IAAI;IAYtB,SAAS,IAAI,MAAM;IAUnB,QAAQ,IAAI,MAAM;CAcnB"}
@@ -1,5 +1,7 @@
1
+ import { isIdentifierName } from '@babel/helper-validator-identifier';
1
2
  import { match, P } from 'ts-pattern';
2
- import { List, ObjectProperty } from './List.js';
3
+ import { List } from './List.js';
4
+ import { camelCase } from 'lodash-es';
3
5
  export class FunctionParameter {
4
6
  constructor(args) {
5
7
  Object.defineProperty(this, "properties", {
@@ -43,12 +45,10 @@ export class FunctionParameter {
43
45
  }
44
46
  toPropertyList() {
45
47
  return match(this.properties)
46
- .with({ type: 'void' }, () => List.toObject({ items: [], renderWhenEmpty: false }))
47
- .with({ type: 'regular' }, ({ name }) => List.toObject({ items: [`${name}`] }))
48
+ .with({ type: 'void' }, () => List.toEmpty())
49
+ .with({ type: 'regular' }, ({ name }) => List.toSingle(name))
48
50
  .with({ type: 'destructured' }, ({ typeDefinition }) => {
49
- return List.keysToObject({
50
- record: typeDefinition.value.objectProperties?.properties
51
- });
51
+ return List.fromRecord(typeDefinition.value.objectProperties?.properties);
52
52
  })
53
53
  .exhaustive();
54
54
  }
@@ -57,11 +57,7 @@ export class FunctionParameter {
57
57
  .with({ type: 'void' }, () => '')
58
58
  .with({ type: 'regular' }, ({ name }) => `${name}`)
59
59
  .with({ type: 'destructured' }, ({ typeDefinition }) => {
60
- const list = List.keysToObject({
61
- record: typeDefinition.value.objectProperties?.properties,
62
- map: key => new ObjectProperty(key)
63
- });
64
- return `${list}`;
60
+ return toDestructured(typeDefinition).toString();
65
61
  })
66
62
  .exhaustive();
67
63
  }
@@ -72,12 +68,19 @@ export class FunctionParameter {
72
68
  return `${name}${required ? '' : '?'}: ${typeDefinition.identifier}`;
73
69
  })
74
70
  .with({ type: 'destructured' }, ({ typeDefinition }) => {
75
- const destructured = List.keysToObject({
76
- record: typeDefinition.value.objectProperties?.properties,
77
- map: key => new ObjectProperty(key)
78
- });
79
- return `${destructured}: ${typeDefinition.identifier}`;
71
+ return List.toKeyValue(toDestructured(typeDefinition).toString(), typeDefinition.identifier).toString();
80
72
  })
81
73
  .exhaustive();
82
74
  }
83
75
  }
76
+ const toDestructured = (typeDefinition) => {
77
+ const { values } = List.fromRecord(typeDefinition.value.objectProperties?.properties);
78
+ const camelised = values
79
+ .map(value => value.toString())
80
+ .map(value => {
81
+ return isIdentifierName(value)
82
+ ? value
83
+ : List.toKeyValue(value, camelCase(value));
84
+ });
85
+ return List.toObject(camelised);
86
+ };
@@ -1,39 +1,24 @@
1
- type ListArgs<V> = {
2
- items: V[];
3
- bookends: 'square' | 'curly' | 'round' | 'none';
4
- separator: string;
5
- renderWhenEmpty?: boolean;
6
- };
7
- type ToArrayArgs<V> = {
8
- items: V[];
9
- renderWhenEmpty?: boolean;
10
- };
11
- type ToObjectArgs<V> = {
12
- items: V[];
13
- renderWhenEmpty?: boolean;
14
- };
15
- type KeysToObjectArgs<V> = {
16
- record?: Record<string, unknown>;
17
- map?: (value: string) => V;
18
- renderWhenEmpty?: boolean;
1
+ import type { Stringable } from '../dsl/Stringable.js';
2
+ type ConstructorOptions = {
3
+ separator?: string;
4
+ bookends?: 'square' | 'curly' | 'round' | 'none';
19
5
  };
20
- export declare class List<V> {
21
- bookends: 'square' | 'curly' | 'round' | 'none';
6
+ export declare class List {
7
+ values: Stringable[];
22
8
  separator: string;
23
- renderWhenEmpty: boolean;
24
- items: V[];
25
- constructor({ items, bookends, separator, renderWhenEmpty }: ListArgs<V>);
26
- static toArray<V>(args: ToArrayArgs<V>): List<V>;
27
- static toObject<V>(args: ToObjectArgs<V>): List<V>;
28
- static keysToObject<V>({ record, map, renderWhenEmpty }: KeysToObjectArgs<V>): List<string | V>;
29
- toString(): string;
30
- }
31
- export declare class ObjectProperty {
32
- name: string;
33
- isValid: boolean;
34
- canonicalName: string;
35
- constructor(name: string);
9
+ bookends: 'square' | 'curly' | 'round' | 'none';
10
+ constructor(values: (Stringable | undefined)[], { separator, bookends }?: ConstructorOptions);
36
11
  toString(): string;
12
+ static toEmpty: () => List;
13
+ static toSingle: (value: Stringable) => List;
14
+ static toOptional: (value: Stringable, condition: boolean) => List;
15
+ static toFilteredRecord: (record: Record<string, undefined | Stringable | Stringable[] | List>) => List;
16
+ static toKeyValue: (key: string, value: Stringable) => List;
17
+ static toObjectKey: (key: string, value: Stringable) => List;
18
+ static toObject: (values: (Stringable | undefined)[]) => List;
19
+ static fromRecord: (record: Record<string, Stringable> | undefined) => List;
20
+ static toFilteredKeyValue: (key: string, value: undefined | Stringable | Stringable[] | List) => List | undefined;
21
+ static hasValue: (value: undefined | Stringable | Stringable[] | List) => value is Stringable | Stringable[] | List;
37
22
  }
38
23
  export {};
39
24
  //# sourceMappingURL=List.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"List.d.ts","sourceRoot":"","sources":["../../src/typescript/List.ts"],"names":[],"mappings":"AAKA,KAAK,QAAQ,CAAC,CAAC,IAAI;IACjB,KAAK,EAAE,CAAC,EAAE,CAAA;IACV,QAAQ,EAAE,QAAQ,GAAG,OAAO,G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AU,EAAE,GAAG,IAAI,sBAGpD;IAED,MAAM,CAAC,QAAQ,UACN,SAAS,GAAG,UAAU,GAAG,UAAU,EAAE,GAAG,IAAI,KAClD,KAAK,IAAI,UAAU,GAAG,UAAU,EAAE,GAAG,IAAI,CAc3C;CACF"}
@@ -1,9 +1,7 @@
1
- import { isIdentifierName } from '@babel/helper-validator-identifier';
2
- import { camelCase } from 'lodash-es';
3
1
  import { match } from 'ts-pattern';
4
2
  export class List {
5
- constructor({ items, bookends, separator, renderWhenEmpty = true }) {
6
- Object.defineProperty(this, "bookends", {
3
+ constructor(values, { separator = ', ', bookends = 'none' } = {}) {
4
+ Object.defineProperty(this, "values", {
7
5
  enumerable: true,
8
6
  configurable: true,
9
7
  writable: true,
@@ -15,79 +13,103 @@ export class List {
15
13
  writable: true,
16
14
  value: void 0
17
15
  });
18
- Object.defineProperty(this, "renderWhenEmpty", {
16
+ Object.defineProperty(this, "bookends", {
19
17
  enumerable: true,
20
18
  configurable: true,
21
19
  writable: true,
22
20
  value: void 0
23
21
  });
24
- Object.defineProperty(this, "items", {
25
- enumerable: true,
26
- configurable: true,
27
- writable: true,
28
- value: []
29
- });
30
- this.items = items;
31
- this.bookends = bookends;
22
+ this.values = values.filter(value => value !== undefined);
32
23
  this.separator = separator;
33
- this.renderWhenEmpty = renderWhenEmpty;
34
- }
35
- static toArray(args) {
36
- return new List({ ...args, bookends: 'square', separator: ',' });
37
- }
38
- static toObject(args) {
39
- return new List({ ...args, bookends: 'curly', separator: ',' });
40
- }
41
- static keysToObject({ record, map, renderWhenEmpty }) {
42
- const items = Object.keys(record ?? {}).map(key => (map ? map(key) : key));
43
- return new List({
44
- items,
45
- bookends: 'curly',
46
- separator: ',',
47
- renderWhenEmpty
48
- });
24
+ this.bookends = bookends;
49
25
  }
50
26
  toString() {
51
- if (this.items.length === 0 && !this.renderWhenEmpty) {
52
- return '';
53
- }
54
- const items = this.items.map(item => `${item}`).join(this.separator);
27
+ const joined = this.values.join(this.separator);
55
28
  return match(this.bookends)
56
- .with('square', () => `[${items}]`)
57
- .with('curly', () => `{${items}}`)
58
- .with('round', () => `(${items})`)
59
- .with('none', () => items)
29
+ .with('square', () => `[${joined}]`)
30
+ .with('curly', () => `{${joined}}`)
31
+ .with('round', () => `(${joined})`)
32
+ .with('none', () => joined)
60
33
  .exhaustive();
61
34
  }
62
35
  }
63
- export class ObjectProperty {
64
- constructor(name) {
65
- Object.defineProperty(this, "name", {
66
- enumerable: true,
67
- configurable: true,
68
- writable: true,
69
- value: void 0
36
+ Object.defineProperty(List, "toEmpty", {
37
+ enumerable: true,
38
+ configurable: true,
39
+ writable: true,
40
+ value: () => new List([], { bookends: 'none' })
41
+ });
42
+ Object.defineProperty(List, "toSingle", {
43
+ enumerable: true,
44
+ configurable: true,
45
+ writable: true,
46
+ value: (value) => new List([value], { bookends: 'none' })
47
+ });
48
+ Object.defineProperty(List, "toOptional", {
49
+ enumerable: true,
50
+ configurable: true,
51
+ writable: true,
52
+ value: (value, condition) => new List([condition ? value : undefined])
53
+ });
54
+ Object.defineProperty(List, "toFilteredRecord", {
55
+ enumerable: true,
56
+ configurable: true,
57
+ writable: true,
58
+ value: (record) => {
59
+ const entries = Object.entries(record).map(([key, value]) => {
60
+ return List.toFilteredKeyValue(key, value);
70
61
  });
71
- Object.defineProperty(this, "isValid", {
72
- enumerable: true,
73
- configurable: true,
74
- writable: true,
75
- value: void 0
76
- });
77
- Object.defineProperty(this, "canonicalName", {
78
- enumerable: true,
79
- configurable: true,
80
- writable: true,
81
- value: void 0
82
- });
83
- this.name = name;
84
- this.isValid = isIdentifierName(name);
85
- this.canonicalName = this.isValid ? name : camelCase(name);
86
- if (!isIdentifierName(this.canonicalName)) {
87
- throw new Error(`Property name '${name}' is not a valid identifier and cannot be converted to a canonical name`);
88
- }
62
+ return List.toObject(entries);
89
63
  }
90
- toString() {
91
- return this.isValid ? this.name : `${this.name}: ${this.canonicalName}`;
64
+ });
65
+ Object.defineProperty(List, "toKeyValue", {
66
+ enumerable: true,
67
+ configurable: true,
68
+ writable: true,
69
+ value: (key, value) => new List([key, value], { separator: ': ' })
70
+ });
71
+ Object.defineProperty(List, "toObjectKey", {
72
+ enumerable: true,
73
+ configurable: true,
74
+ writable: true,
75
+ value: (key, value) => new List([key, value], { separator: '.' })
76
+ });
77
+ Object.defineProperty(List, "toObject", {
78
+ enumerable: true,
79
+ configurable: true,
80
+ writable: true,
81
+ value: (values) => new List(values, { bookends: 'curly' })
82
+ });
83
+ Object.defineProperty(List, "fromRecord", {
84
+ enumerable: true,
85
+ configurable: true,
86
+ writable: true,
87
+ value: (record) => {
88
+ return new List(Object.keys(record ?? {}));
92
89
  }
93
- }
90
+ });
91
+ Object.defineProperty(List, "toFilteredKeyValue", {
92
+ enumerable: true,
93
+ configurable: true,
94
+ writable: true,
95
+ value: (key, value) => {
96
+ return List.hasValue(value) ? List.toKeyValue(key, value) : undefined;
97
+ }
98
+ });
99
+ Object.defineProperty(List, "hasValue", {
100
+ enumerable: true,
101
+ configurable: true,
102
+ writable: true,
103
+ value: (value) => {
104
+ if (value === undefined) {
105
+ return false;
106
+ }
107
+ if (Array.isArray(value)) {
108
+ return value.length > 0;
109
+ }
110
+ if (value instanceof List) {
111
+ return List.hasValue(value.values);
112
+ }
113
+ return true;
114
+ }
115
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skmtc/core",
3
- "version": "0.0.329",
3
+ "version": "0.0.331",
4
4
  "main": "./script/mod.js",
5
5
  "module": "./esm/mod.js",
6
6
  "exports": {
@@ -3,12 +3,12 @@ import type { RegisterArgs } from '../context/GenerateContext.js';
3
3
  import type { GeneratorKey } from '../types/GeneratorKeys.js';
4
4
  type ValueBaseArgs = {
5
5
  context: GenerateContext;
6
- generatorKey?: GeneratorKey;
6
+ generatorKey: GeneratorKey;
7
7
  };
8
8
  export declare class ValueBase {
9
9
  context: GenerateContext;
10
10
  skipped: boolean;
11
- generatorKey: GeneratorKey | undefined;
11
+ generatorKey: GeneratorKey;
12
12
  constructor({ context, generatorKey }: ValueBaseArgs);
13
13
  register(args: RegisterArgs): void;
14
14
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ValueBase.d.ts","sourceRoot":"","sources":["../../src/dsl/ValueBase.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AACpE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAA;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAE7D,KAAK,aAAa,GAAG;IACnB,OAAO,EAAE,eAAe,CAAA;IACxB,YAAY,CAAC,EAAE,YAAY,CAAA;CAC5B,CAAA;AAED,qBAAa,SAAS;IACpB,OAAO,EAAE,eAAe,CAAA;IACxB,OAAO,EAAE,OAAO,CAAQ;IACxB,YAAY,EAAE,YAAY,GAAG,SAAS,CAAA;gBAE1B,EAAE,OAAO,EAAE,YAAY,EAAE,EAAE,aAAa;IAOpD,QAAQ,CAAC,IAAI,EAAE,YAAY;CAG5B"}
1
+ {"version":3,"file":"ValueBase.d.ts","sourceRoot":"","sources":["../../src/dsl/ValueBase.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AACpE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAA;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAE7D,KAAK,aAAa,GAAG;IACnB,OAAO,EAAE,eAAe,CAAA;IACxB,YAAY,EAAE,YAAY,CAAA;CAC3B,CAAA;AAED,qBAAa,SAAS;IACpB,OAAO,EAAE,eAAe,CAAA;IACxB,OAAO,EAAE,OAAO,CAAQ;IACxB,YAAY,EAAE,YAAY,CAAA;gBAEd,EAAE,OAAO,EAAE,YAAY,EAAE,EAAE,aAAa;IAOpD,QAAQ,CAAC,IAAI,EAAE,YAAY;CAG5B"}
@@ -35,9 +35,10 @@ const proxyHandler = {
35
35
  return propertyName === 'toString'
36
36
  ? new Proxy(target[propertyName], {
37
37
  apply: (toString, thisArg) => {
38
- if (target.generatorKey) {
39
- target.context.callback(target.generatorKey);
38
+ if (!target.generatorKey) {
39
+ throw new Error('generatorKey is required');
40
40
  }
41
+ target.context.callback(target.generatorKey);
41
42
  return toString.apply(thisArg);
42
43
  }
43
44
  })
@@ -49,7 +49,7 @@ export declare const toOperationInsertable: (config: OperationConfig) => {
49
49
  register(args: Partial<import("../context/GenerateContext.js").RegisterArgs>): void;
50
50
  context: GenerateContext;
51
51
  skipped: boolean;
52
- generatorKey: import("../types/GeneratorKeys.js").GeneratorKey | undefined;
52
+ generatorKey: import("../types/GeneratorKeys.js").GeneratorKey;
53
53
  };
54
54
  id: string;
55
55
  entityType: EntityType;
@@ -84,7 +84,7 @@ export declare const toModelInsertable: (config: ModelConfig) => {
84
84
  register(args: Partial<import("../context/GenerateContext.js").RegisterArgs>): void;
85
85
  context: GenerateContext;
86
86
  skipped: boolean;
87
- generatorKey: import("../types/GeneratorKeys.js").GeneratorKey | undefined;
87
+ generatorKey: import("../types/GeneratorKeys.js").GeneratorKey;
88
88
  };
89
89
  id: string;
90
90
  type: "model";
@@ -20,13 +20,17 @@ export type OperationFields = {
20
20
  responses: Record<string, OasResponse | OasRef<'response'>>;
21
21
  deprecated: boolean | undefined;
22
22
  };
23
+ type ToRequestBodyMapArgs = {
24
+ schema: OasSchema | OasRef<'schema'>;
25
+ requestBody: OasRequestBody;
26
+ };
23
27
  /** Operation represents a resource path and a method that can be enacted against it */
24
28
  export declare class OasOperation {
25
29
  #private;
26
30
  oasType: 'operation';
27
31
  constructor(fields: OperationFields);
28
32
  toSuccessResponse(): OasResponse | OasRef<'response'>;
29
- toRequestBody(mediaType?: string): OasSchema | OasRef<'schema'> | undefined;
33
+ toRequestBody<V>(map: ({ schema, requestBody }: ToRequestBodyMapArgs) => V, mediaType?: string): V | undefined;
30
34
  /**
31
35
  * Resolve all parameters and optionally filter by location
32
36
  *
@@ -47,4 +51,5 @@ export declare class OasOperation {
47
51
  get responses(): Record<string, OasResponse | OasRef<'response'>>;
48
52
  get deprecated(): boolean | undefined;
49
53
  }
54
+ export {};
50
55
  //# sourceMappingURL=Operation.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Operation.d.ts","sourceRoot":"","sources":["../../../src/oas/operation/Operation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAA;AACnE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAA;AAC3E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAE/C,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,WAAW,CAAA;IACrB,WAAW,EAAE,MAAM,GAAG,SAAS,CAAA;IAC/B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAA;IAC3B,IAAI,EAAE,MAAM,EAAE,GAAG,SAAS,CAAA;IAC1B,WAAW,EAAE,MAAM,GAAG,SAAS,CAAA;IAC/B,UAAU,EAAE,CAAC,YAAY,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC,EAAE,GAAG,SAAS,CAAA;IAC9D,WAAW,EAAE,cAAc,GAAG,MAAM,CAAC,aAAa,CAAC,GAAG,SAA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AW,EAAE,cAAc,CAAA;CAC5B,CAAA;AAED,uFAAuF;AACvF,qBAAa,YAAY;;IACvB,OAAO,EAAE,WAAW,CAAc;gBAGtB,MAAM,EAAE,eAAe;IAInC,iBAAiB,IAAI,WAAW,GAAG,MAAM,CAAC,UAAU,CAAC;IAWrD,aAAa,CAAC,CAAC,EACb,GAAG,EAAE,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,oBAAoB,KAAK,CAAC,EACzD,SAAS,SAAqB,GAC7B,CAAC,GAAG,SAAS;IAOhB;;;;;OAKG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,oBAAoB,EAAE,GAAG,YAAY,EAAE;IAUzD,kBAAkB,CAAC,MAAM,CAAC,EAAE,oBAAoB,EAAE;IAYlD,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,IAAI,QAAQ,IAAI,WAAW,CAE1B;IAED,IAAI,WAAW,IAAI,MAAM,GAAG,SAAS,CAEpC;IAED,IAAI,OAAO,IAAI,MAAM,GAAG,SAAS,CAEhC;IAED,IAAI,IAAI,IAAI,MAAM,EAAE,GAAG,SAAS,CAE/B;IAED,IAAI,WAAW,IAAI,MAAM,GAAG,SAAS,CAEpC;IAED,IAAI,UAAU,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC,EAAE,GAAG,SAAS,CAEnE;IAED,IAAI,WAAW,IAAI,cAAc,GAAG,MAAM,CAAC,aAAa,CAAC,GAAG,SAAS,CAEpE;IAED,IAAI,SAAS,IAAI,MAAM,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,CAEhE;IAED,IAAI,UAAU,IAAI,OAAO,GAAG,SAAS,CAEpC;CACF"}
@@ -34,8 +34,10 @@ class OasOperation {
34
34
  .find(httpCode => httpCode >= 200 && httpCode < 300);
35
35
  return successCode ? httpCodeResponses[successCode] : defaultResponse;
36
36
  }
37
- toRequestBody(mediaType = 'application/json') {
38
- return this.requestBody?.resolve().content[mediaType]?.schema;
37
+ toRequestBody(map, mediaType = 'application/json') {
38
+ const requestBody = this.requestBody?.resolve();
39
+ const schema = requestBody?.content[mediaType]?.schema;
40
+ return schema ? map({ schema, requestBody }) : undefined;
39
41
  }
40
42
  /**
41
43
  * Resolve all parameters and optionally filter by location
@@ -26,7 +26,7 @@ export declare class FunctionParameter {
26
26
  properties: ParameterProperties;
27
27
  constructor(args: CreateArgs);
28
28
  hasProperty(name: string): boolean;
29
- toPropertyList(): List<string>;
29
+ toPropertyList(): List;
30
30
  toInbound(): string;
31
31
  toString(): string;
32
32
  }
@@ -1 +1 @@
1
- {"version":3,"file":"FunctionParameter.d.ts","sourceRoot":"","sources":["../../src/typescript/FunctionParameter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EACf,cAAc,EACf,MAAM,wBAAwB,CAAA;AAC/B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,EAAE,IAAI,EAAkB,MAAM,WAAW,CAAA;AAEhD,KAAK,UAAU,GAAG;IAChB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,cAAc,EAAE,UAAU,CAAC,gBAAgB,GAAG,cAAc,CAAC,CAAA;IAC7D,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA;AAED,KAAK,mBAAmB,GACpB,aAAa,GACb,qBAAqB,GACrB,gBAAgB,CAAA;AAEpB,KAAK,aAAa,GAAG;IACnB,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED,KAAK,qBAAqB,GAAG;IAC3B,IAAI,EAAE,cAAc,CAAA;IACpB,cAAc,EAAE,UAAU,CAAC,gBAAgB,CAAC,CAAA;IAC5C,QAAQ,EAAE,IAAI,CAAA;CACf,CAAA;AAED,KAAK,gBAAgB,GAAG;IACtB,IAAI,EAAE,SAAS,CAA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AC,eAAe,CAAC,CAAA;IAC3C,QAAQ,EAAE,OAAO,CAAA;CAClB,CAAA;AAED,qBAAa,iBAAiB;IAC5B,UAAU,EAAE,mBAAmB,CAAA;gBAEnB,IAAI,EAAE,UAAU;IAyB5B,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAelC,cAAc,IAAI,IAAI;IAYtB,SAAS,IAAI,MAAM;IAUnB,QAAQ,IAAI,MAAM;CAcnB"}
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FunctionParameter = void 0;
4
+ const helper_validator_identifier_1 = require("@babel/helper-validator-identifier");
4
5
  const ts_pattern_1 = require("ts-pattern");
5
6
  const List_js_1 = require("./List.js");
7
+ const lodash_es_1 = require("lodash-es");
6
8
  class FunctionParameter {
7
9
  constructor(args) {
8
10
  Object.defineProperty(this, "properties", {
@@ -46,12 +48,10 @@ class FunctionParameter {
46
48
  }
47
49
  toPropertyList() {
48
50
  return (0, ts_pattern_1.match)(this.properties)
49
- .with({ type: 'void' }, () => List_js_1.List.toObject({ items: [], renderWhenEmpty: false }))
50
- .with({ type: 'regular' }, ({ name }) => List_js_1.List.toObject({ items: [`${name}`] }))
51
+ .with({ type: 'void' }, () => List_js_1.List.toEmpty())
52
+ .with({ type: 'regular' }, ({ name }) => List_js_1.List.toSingle(name))
51
53
  .with({ type: 'destructured' }, ({ typeDefinition }) => {
52
- return List_js_1.List.keysToObject({
53
- record: typeDefinition.value.objectProperties?.properties
54
- });
54
+ return List_js_1.List.fromRecord(typeDefinition.value.objectProperties?.properties);
55
55
  })
56
56
  .exhaustive();
57
57
  }
@@ -60,11 +60,7 @@ class FunctionParameter {
60
60
  .with({ type: 'void' }, () => '')
61
61
  .with({ type: 'regular' }, ({ name }) => `${name}`)
62
62
  .with({ type: 'destructured' }, ({ typeDefinition }) => {
63
- const list = List_js_1.List.keysToObject({
64
- record: typeDefinition.value.objectProperties?.properties,
65
- map: key => new List_js_1.ObjectProperty(key)
66
- });
67
- return `${list}`;
63
+ return toDestructured(typeDefinition).toString();
68
64
  })
69
65
  .exhaustive();
70
66
  }
@@ -75,13 +71,20 @@ class FunctionParameter {
75
71
  return `${name}${required ? '' : '?'}: ${typeDefinition.identifier}`;
76
72
  })
77
73
  .with({ type: 'destructured' }, ({ typeDefinition }) => {
78
- const destructured = List_js_1.List.keysToObject({
79
- record: typeDefinition.value.objectProperties?.properties,
80
- map: key => new List_js_1.ObjectProperty(key)
81
- });
82
- return `${destructured}: ${typeDefinition.identifier}`;
74
+ return List_js_1.List.toKeyValue(toDestructured(typeDefinition).toString(), typeDefinition.identifier).toString();
83
75
  })
84
76
  .exhaustive();
85
77
  }
86
78
  }
87
79
  exports.FunctionParameter = FunctionParameter;
80
+ const toDestructured = (typeDefinition) => {
81
+ const { values } = List_js_1.List.fromRecord(typeDefinition.value.objectProperties?.properties);
82
+ const camelised = values
83
+ .map(value => value.toString())
84
+ .map(value => {
85
+ return (0, helper_validator_identifier_1.isIdentifierName)(value)
86
+ ? value
87
+ : List_js_1.List.toKeyValue(value, (0, lodash_es_1.camelCase)(value));
88
+ });
89
+ return List_js_1.List.toObject(camelised);
90
+ };
@@ -1,39 +1,24 @@
1
- type ListArgs<V> = {
2
- items: V[];
3
- bookends: 'square' | 'curly' | 'round' | 'none';
4
- separator: string;
5
- renderWhenEmpty?: boolean;
6
- };
7
- type ToArrayArgs<V> = {
8
- items: V[];
9
- renderWhenEmpty?: boolean;
10
- };
11
- type ToObjectArgs<V> = {
12
- items: V[];
13
- renderWhenEmpty?: boolean;
14
- };
15
- type KeysToObjectArgs<V> = {
16
- record?: Record<string, unknown>;
17
- map?: (value: string) => V;
18
- renderWhenEmpty?: boolean;
1
+ import type { Stringable } from '../dsl/Stringable.js';
2
+ type ConstructorOptions = {
3
+ separator?: string;
4
+ bookends?: 'square' | 'curly' | 'round' | 'none';
19
5
  };
20
- export declare class List<V> {
21
- bookends: 'square' | 'curly' | 'round' | 'none';
6
+ export declare class List {
7
+ values: Stringable[];
22
8
  separator: string;
23
- renderWhenEmpty: boolean;
24
- items: V[];
25
- constructor({ items, bookends, separator, renderWhenEmpty }: ListArgs<V>);
26
- static toArray<V>(args: ToArrayArgs<V>): List<V>;
27
- static toObject<V>(args: ToObjectArgs<V>): List<V>;
28
- static keysToObject<V>({ record, map, renderWhenEmpty }: KeysToObjectArgs<V>): List<string | V>;
29
- toString(): string;
30
- }
31
- export declare class ObjectProperty {
32
- name: string;
33
- isValid: boolean;
34
- canonicalName: string;
35
- constructor(name: string);
9
+ bookends: 'square' | 'curly' | 'round' | 'none';
10
+ constructor(values: (Stringable | undefined)[], { separator, bookends }?: ConstructorOptions);
36
11
  toString(): string;
12
+ static toEmpty: () => List;
13
+ static toSingle: (value: Stringable) => List;
14
+ static toOptional: (value: Stringable, condition: boolean) => List;
15
+ static toFilteredRecord: (record: Record<string, undefined | Stringable | Stringable[] | List>) => List;
16
+ static toKeyValue: (key: string, value: Stringable) => List;
17
+ static toObjectKey: (key: string, value: Stringable) => List;
18
+ static toObject: (values: (Stringable | undefined)[]) => List;
19
+ static fromRecord: (record: Record<string, Stringable> | undefined) => List;
20
+ static toFilteredKeyValue: (key: string, value: undefined | Stringable | Stringable[] | List) => List | undefined;
21
+ static hasValue: (value: undefined | Stringable | Stringable[] | List) => value is Stringable | Stringable[] | List;
37
22
  }
38
23
  export {};
39
24
  //# sourceMappingURL=List.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"List.d.ts","sourceRoot":"","sources":["../../src/typescript/List.ts"],"names":[],"mappings":"AAKA,KAAK,QAAQ,CAAC,CAAC,IAAI;IACjB,KAAK,EAAE,CAAC,EAAE,CAAA;IACV,QAAQ,EAAE,QAAQ,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,CAAA;IAC/C,SAAS,EAAE,MAAM,CAAA;IACjB,eAAe,CAAC,EAAE,OAAO,CAAA;CAC1B,CAAA;AAED,KAAK,WAAW,CAAC,CAAC,IAAI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EAAE,GAAG,IAAI,CAc3C;CACF"}
@@ -1,12 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ObjectProperty = exports.List = void 0;
4
- const helper_validator_identifier_1 = require("@babel/helper-validator-identifier");
5
- const lodash_es_1 = require("lodash-es");
3
+ exports.List = void 0;
6
4
  const ts_pattern_1 = require("ts-pattern");
7
5
  class List {
8
- constructor({ items, bookends, separator, renderWhenEmpty = true }) {
9
- Object.defineProperty(this, "bookends", {
6
+ constructor(values, { separator = ', ', bookends = 'none' } = {}) {
7
+ Object.defineProperty(this, "values", {
10
8
  enumerable: true,
11
9
  configurable: true,
12
10
  writable: true,
@@ -18,81 +16,104 @@ class List {
18
16
  writable: true,
19
17
  value: void 0
20
18
  });
21
- Object.defineProperty(this, "renderWhenEmpty", {
19
+ Object.defineProperty(this, "bookends", {
22
20
  enumerable: true,
23
21
  configurable: true,
24
22
  writable: true,
25
23
  value: void 0
26
24
  });
27
- Object.defineProperty(this, "items", {
28
- enumerable: true,
29
- configurable: true,
30
- writable: true,
31
- value: []
32
- });
33
- this.items = items;
34
- this.bookends = bookends;
25
+ this.values = values.filter(value => value !== undefined);
35
26
  this.separator = separator;
36
- this.renderWhenEmpty = renderWhenEmpty;
37
- }
38
- static toArray(args) {
39
- return new List({ ...args, bookends: 'square', separator: ',' });
40
- }
41
- static toObject(args) {
42
- return new List({ ...args, bookends: 'curly', separator: ',' });
43
- }
44
- static keysToObject({ record, map, renderWhenEmpty }) {
45
- const items = Object.keys(record ?? {}).map(key => (map ? map(key) : key));
46
- return new List({
47
- items,
48
- bookends: 'curly',
49
- separator: ',',
50
- renderWhenEmpty
51
- });
27
+ this.bookends = bookends;
52
28
  }
53
29
  toString() {
54
- if (this.items.length === 0 && !this.renderWhenEmpty) {
55
- return '';
56
- }
57
- const items = this.items.map(item => `${item}`).join(this.separator);
30
+ const joined = this.values.join(this.separator);
58
31
  return (0, ts_pattern_1.match)(this.bookends)
59
- .with('square', () => `[${items}]`)
60
- .with('curly', () => `{${items}}`)
61
- .with('round', () => `(${items})`)
62
- .with('none', () => items)
32
+ .with('square', () => `[${joined}]`)
33
+ .with('curly', () => `{${joined}}`)
34
+ .with('round', () => `(${joined})`)
35
+ .with('none', () => joined)
63
36
  .exhaustive();
64
37
  }
65
38
  }
66
39
  exports.List = List;
67
- class ObjectProperty {
68
- constructor(name) {
69
- Object.defineProperty(this, "name", {
70
- enumerable: true,
71
- configurable: true,
72
- writable: true,
73
- value: void 0
40
+ Object.defineProperty(List, "toEmpty", {
41
+ enumerable: true,
42
+ configurable: true,
43
+ writable: true,
44
+ value: () => new List([], { bookends: 'none' })
45
+ });
46
+ Object.defineProperty(List, "toSingle", {
47
+ enumerable: true,
48
+ configurable: true,
49
+ writable: true,
50
+ value: (value) => new List([value], { bookends: 'none' })
51
+ });
52
+ Object.defineProperty(List, "toOptional", {
53
+ enumerable: true,
54
+ configurable: true,
55
+ writable: true,
56
+ value: (value, condition) => new List([condition ? value : undefined])
57
+ });
58
+ Object.defineProperty(List, "toFilteredRecord", {
59
+ enumerable: true,
60
+ configurable: true,
61
+ writable: true,
62
+ value: (record) => {
63
+ const entries = Object.entries(record).map(([key, value]) => {
64
+ return List.toFilteredKeyValue(key, value);
74
65
  });
75
- Object.defineProperty(this, "isValid", {
76
- enumerable: true,
77
- configurable: true,
78
- writable: true,
79
- value: void 0
80
- });
81
- Object.defineProperty(this, "canonicalName", {
82
- enumerable: true,
83
- configurable: true,
84
- writable: true,
85
- value: void 0
86
- });
87
- this.name = name;
88
- this.isValid = (0, helper_validator_identifier_1.isIdentifierName)(name);
89
- this.canonicalName = this.isValid ? name : (0, lodash_es_1.camelCase)(name);
90
- if (!(0, helper_validator_identifier_1.isIdentifierName)(this.canonicalName)) {
91
- throw new Error(`Property name '${name}' is not a valid identifier and cannot be converted to a canonical name`);
92
- }
66
+ return List.toObject(entries);
93
67
  }
94
- toString() {
95
- return this.isValid ? this.name : `${this.name}: ${this.canonicalName}`;
68
+ });
69
+ Object.defineProperty(List, "toKeyValue", {
70
+ enumerable: true,
71
+ configurable: true,
72
+ writable: true,
73
+ value: (key, value) => new List([key, value], { separator: ': ' })
74
+ });
75
+ Object.defineProperty(List, "toObjectKey", {
76
+ enumerable: true,
77
+ configurable: true,
78
+ writable: true,
79
+ value: (key, value) => new List([key, value], { separator: '.' })
80
+ });
81
+ Object.defineProperty(List, "toObject", {
82
+ enumerable: true,
83
+ configurable: true,
84
+ writable: true,
85
+ value: (values) => new List(values, { bookends: 'curly' })
86
+ });
87
+ Object.defineProperty(List, "fromRecord", {
88
+ enumerable: true,
89
+ configurable: true,
90
+ writable: true,
91
+ value: (record) => {
92
+ return new List(Object.keys(record ?? {}));
96
93
  }
97
- }
98
- exports.ObjectProperty = ObjectProperty;
94
+ });
95
+ Object.defineProperty(List, "toFilteredKeyValue", {
96
+ enumerable: true,
97
+ configurable: true,
98
+ writable: true,
99
+ value: (key, value) => {
100
+ return List.hasValue(value) ? List.toKeyValue(key, value) : undefined;
101
+ }
102
+ });
103
+ Object.defineProperty(List, "hasValue", {
104
+ enumerable: true,
105
+ configurable: true,
106
+ writable: true,
107
+ value: (value) => {
108
+ if (value === undefined) {
109
+ return false;
110
+ }
111
+ if (Array.isArray(value)) {
112
+ return value.length > 0;
113
+ }
114
+ if (value instanceof List) {
115
+ return List.hasValue(value.values);
116
+ }
117
+ return true;
118
+ }
119
+ });