@skmtc/core 0.0.253 → 0.0.254

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/esm/mod.d.ts CHANGED
@@ -54,7 +54,6 @@ export * from './typescript/identifiers.js';
54
54
  export * from './typescript/keyValues.js';
55
55
  export * from './typescript/PathParams.js';
56
56
  export * from './typescript/ReactRouterPathParams.js';
57
- export * from './typescript/toDestructuredObject.js';
58
57
  export * from './typescript/toOperationArg.js';
59
58
  export * from './typescript/toOperationResponse.js';
60
59
  export * from './typescript/toPathTemplate.js';
package/esm/mod.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAC7B,cAAc,0BAA0B,CAAA;AACxC,cAAc,uBAAuB,CAAA;AACrC,cAAc,2BAA2B,CAAA;AACzC,cAAc,oBAAoB,CAAA;AAClC,cAAc,eAAe,CAAA;AAC7B,cAAc,oBAAoB,CAAA;AAClC,cAAc,0BAA0B,CAAA;AACxC,cAAc,qBAAqB,CAAA;AACnC,cAAc,6BAA6B,CAAA;AAC3C,cAAc,qBAAqB,CAAA;AACnC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,uBAAuB,CAAA;AACrC,cAAc,sBAAsB,CAAA;AACpC,cAAc,2BAA2B,CAAA;AACzC,cAAc,0BAA0B,CAAA;AACxC,cAAc,qBAAqB,CAAA;AACnC,cAAc,oBAAoB,CAAA;AAClC,cAAc,qBAAqB,CAAA;AACnC,cAAc,wBAAwB,CAAA;AACtC,cAAc,wBAAwB,CAAA;AACtC,cAAc,qBAAqB,CAAA;AACnC,cAAc,qBAAqB,CAAA;AACnC,cAAc,sBAAsB,CAAA;AACpC,cAAc,yBAAyB,CAAA;AACvC,cAAc,sCAAsC,CAAA;AACpD,cAAc,4BAA4B,CAAA;AAC1C,cAAc,0BAA0B,CAAA;AACxC,cAAc,wBAA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qCAAqC,CAAA;AACnD,cAAc,gCAAgC,CAAA;AAC9C,cAAc,iCAAiC,CAAA"}
package/esm/mod.js CHANGED
@@ -54,7 +54,6 @@ export * from './typescript/identifiers.js';
54
54
  export * from './typescript/keyValues.js';
55
55
  export * from './typescript/PathParams.js';
56
56
  export * from './typescript/ReactRouterPathParams.js';
57
- export * from './typescript/toDestructuredObject.js';
58
57
  export * from './typescript/toOperationArg.js';
59
58
  export * from './typescript/toOperationResponse.js';
60
59
  export * from './typescript/toPathTemplate.js';
@@ -0,0 +1,15 @@
1
+ import type { TypeSystemObject } from '../types/TypeSystem.js';
2
+ export declare class DestructuredObject {
3
+ typeSystemObject: TypeSystemObject;
4
+ properties: ObjectProperty[];
5
+ constructor(typeSystemObject: TypeSystemObject);
6
+ toString(): string;
7
+ }
8
+ export declare class ObjectProperty {
9
+ name: string;
10
+ isValid: boolean;
11
+ canonicalName: string;
12
+ constructor(name: string);
13
+ toString(): string;
14
+ }
15
+ //# sourceMappingURL=DestructuredObject.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DestructuredObject.d.ts","sourceRoot":"","sources":["../../src/typescript/DestructuredObject.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAG9D,qBAAa,kBAAkB;IAC7B,gBAAgB,EAAE,gBAAgB,CAAA;IAClC,UAAU,EAAE,cAAc,EAAE,CAAA;gBAChB,gBAAgB,EAAE,gBAAgB;IAQ9C,QAAQ,IAAI,MAAM;CAGnB;AAED,qBAAa,cAAc;IACzB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,OAAO,CAAA;IAChB,aAAa,EAAE,MAAM,CAAA;gBACT,IAAI,EAAE,MAAM;IAYxB,QAAQ,IAAI,MAAM;CAGnB"}
@@ -0,0 +1,54 @@
1
+ import { isIdentifierName } from '@babel/helper-validator-identifier';
2
+ import { camelCase } from 'lodash-es';
3
+ export class DestructuredObject {
4
+ constructor(typeSystemObject) {
5
+ Object.defineProperty(this, "typeSystemObject", {
6
+ enumerable: true,
7
+ configurable: true,
8
+ writable: true,
9
+ value: void 0
10
+ });
11
+ Object.defineProperty(this, "properties", {
12
+ enumerable: true,
13
+ configurable: true,
14
+ writable: true,
15
+ value: void 0
16
+ });
17
+ this.typeSystemObject = typeSystemObject;
18
+ this.properties = Object.keys(typeSystemObject.objectProperties?.properties ?? {}).map(name => new ObjectProperty(name));
19
+ }
20
+ toString() {
21
+ return `{${this.properties.map(property => `${property}`).join(',\n')}}`;
22
+ }
23
+ }
24
+ export class ObjectProperty {
25
+ constructor(name) {
26
+ Object.defineProperty(this, "name", {
27
+ enumerable: true,
28
+ configurable: true,
29
+ writable: true,
30
+ value: void 0
31
+ });
32
+ Object.defineProperty(this, "isValid", {
33
+ enumerable: true,
34
+ configurable: true,
35
+ writable: true,
36
+ value: void 0
37
+ });
38
+ Object.defineProperty(this, "canonicalName", {
39
+ enumerable: true,
40
+ configurable: true,
41
+ writable: true,
42
+ value: void 0
43
+ });
44
+ this.name = name;
45
+ this.isValid = isIdentifierName(name);
46
+ this.canonicalName = this.isValid ? name : camelCase(name);
47
+ if (!isIdentifierName(this.canonicalName)) {
48
+ throw new Error(`Property name '${name}' is not a valid identifier and cannot be converted to a canonical name`);
49
+ }
50
+ }
51
+ toString() {
52
+ return this.isValid ? this.name : `'${this.name}': ${this.canonicalName}`;
53
+ }
54
+ }
@@ -1,5 +1,6 @@
1
1
  import type { TypeSystemObject, TypeSystemValue } from '../types/TypeSystem.js';
2
2
  import type { Definition } from '../dsl/Definition.js';
3
+ import type { Stringable } from '../dsl/Stringable.js';
3
4
  type CreateArgs = {
4
5
  name?: string;
5
6
  typeDefinition: Definition<TypeSystemValue>;
@@ -24,8 +25,7 @@ export declare class FunctionParameter {
24
25
  properties: ParameterProperties;
25
26
  constructor(args: CreateArgs);
26
27
  toDestructured(): FunctionParameter;
27
- toPropertyList(): string[];
28
- toInbound(): string;
28
+ toInbound(): Stringable;
29
29
  toString(): string;
30
30
  }
31
31
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"FunctionParameter.d.ts","sourceRoot":"","sources":["../../src/typescript/FunctionParameter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAE/E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAEtD,KAAK,UAAU,GAAG;IAChB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,cAAc,EAAE,UAAU,CAAC,eAAe,CAAC,CAAA;IAC3C,WAAW,EAAE,OAAO,CAAA;IACpB,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;CAC7C,CAAA;AACD,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;IA6B5B,cAAc,IAAI,iBAAiB;IAgBnC,cAAc,IAAI,MAAM,EAAE;IAc1B,SAAS,IAAI,MAAM;IAkBnB,QAAQ,IAAI,MAAM;CAiBnB"}
1
+ {"version":3,"file":"FunctionParameter.d.ts","sourceRoot":"","sources":["../../src/typescript/FunctionParameter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAE/E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAEtD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAEtD,KAAK,UAAU,GAAG;IAChB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,cAAc,EAAE,UAAU,CAAC,eAAe,CAAC,CAAA;IAC3C,WAAW,EAAE,OAAO,CAAA;IACpB,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;CAC7C,CAAA;AACD,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;IAuB5B,cAAc,IAAI,iBAAiB;IAgBnC,SAAS,IAAI,UAAU;IAUvB,QAAQ,IAAI,MAAM;CAWnB"}
@@ -1,5 +1,6 @@
1
1
  import { P, match } from 'ts-pattern';
2
2
  import invariant from 'tiny-invariant';
3
+ import { DestructuredObject } from './DestructuredObject.js';
3
4
  export class FunctionParameter {
4
5
  constructor(args) {
5
6
  Object.defineProperty(this, "properties", {
@@ -8,11 +9,6 @@ export class FunctionParameter {
8
9
  writable: true,
9
10
  value: void 0
10
11
  });
11
- // @TODO It might be possible to simplify this by adding entityType
12
- // to Definition as one its generic parameter types
13
- if (args.typeDefinition.identifier.entityType.type === 'value') {
14
- throw new Error('Value identifiers cannot be used in type definitions');
15
- }
16
12
  this.properties = match(args)
17
13
  .with({ typeDefinition: { value: { type: 'void' } } }, () => ({
18
14
  type: 'void'
@@ -41,30 +37,14 @@ export class FunctionParameter {
41
37
  destructure: true
42
38
  });
43
39
  }
44
- toPropertyList() {
45
- return match(this.properties)
46
- .with({ type: 'void' }, () => [])
47
- .with({ type: 'regular' }, ({ name }) => [`${name}`])
48
- .with({ type: 'destructured' }, ({ typeDefinition }) => {
49
- return toPropertyNames(typeDefinition.value).map(name => name === `'If-Match'` ? `'If-Match': IfMatch` : name);
50
- })
51
- .otherwise(() => {
52
- throw new Error('Invalid parameter');
53
- });
54
- }
55
40
  toInbound() {
56
41
  return match(this.properties)
57
42
  .with({ type: 'void' }, () => '')
58
- .with({ type: 'regular' }, ({ name }) => {
59
- return `${name}`;
60
- })
43
+ .with({ type: 'regular' }, ({ name }) => `${name}`)
61
44
  .with({ type: 'destructured' }, ({ typeDefinition }) => {
62
- const propertyNames = toPropertyNames(typeDefinition.value).map(name => name === `'If-Match'` ? `'If-Match': IfMatch` : name);
63
- return `{${propertyNames.join(', ')}}`;
45
+ return new DestructuredObject(typeDefinition.value);
64
46
  })
65
- .otherwise(() => {
66
- throw new Error('Invalid parameter');
67
- });
47
+ .exhaustive();
68
48
  }
69
49
  toString() {
70
50
  return match(this.properties)
@@ -73,15 +53,8 @@ export class FunctionParameter {
73
53
  return `${name}${required ? '' : '?'}: ${typeDefinition.identifier}`;
74
54
  })
75
55
  .with({ type: 'destructured' }, ({ typeDefinition }) => {
76
- const propertyNames = toPropertyNames(typeDefinition.value).map(name => name === `'If-Match'` ? `'If-Match': IfMatch` : name);
77
- return `{${propertyNames.join(', ')}}: ${typeDefinition.identifier}`;
56
+ return new DestructuredObject(typeDefinition.value).toString();
78
57
  })
79
- .otherwise(() => {
80
- throw new Error('Invalid parameter');
81
- });
58
+ .exhaustive();
82
59
  }
83
60
  }
84
- const toPropertyNames = (value) => {
85
- invariant(value.objectProperties, 'Only object types can be destructured');
86
- return Object.keys(value.objectProperties.properties);
87
- };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skmtc/core",
3
- "version": "0.0.253",
3
+ "version": "0.0.254",
4
4
  "main": "./script/mod.js",
5
5
  "module": "./esm/mod.js",
6
6
  "exports": {
package/script/mod.d.ts CHANGED
@@ -54,7 +54,6 @@ export * from './typescript/identifiers.js';
54
54
  export * from './typescript/keyValues.js';
55
55
  export * from './typescript/PathParams.js';
56
56
  export * from './typescript/ReactRouterPathParams.js';
57
- export * from './typescript/toDestructuredObject.js';
58
57
  export * from './typescript/toOperationArg.js';
59
58
  export * from './typescript/toOperationResponse.js';
60
59
  export * from './typescript/toPathTemplate.js';
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAC7B,cAAc,0BAA0B,CAAA;AACxC,cAAc,uBAAuB,CAAA;AACrC,cAAc,2BAA2B,CAAA;AACzC,cAAc,oBAAoB,CAAA;AAClC,cAAc,eAAe,CAAA;AAC7B,cAAc,oBAAoB,CAAA;AAClC,cAAc,0BAA0B,CAAA;AACxC,cAAc,qBAAqB,CAAA;AACnC,cAAc,6BAA6B,CAAA;AAC3C,cAAc,qBAAqB,CAAA;AACnC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,uBAAuB,CAAA;AACrC,cAAc,sBAAsB,CAAA;AACpC,cAAc,2BAA2B,CAAA;AACzC,cAAc,0BAA0B,CAAA;AACxC,cAAc,qBAAqB,CAAA;AACnC,cAAc,oBAAoB,CAAA;AAClC,cAAc,qBAAqB,CAAA;AACnC,cAAc,wBAAwB,CAAA;AACtC,cAAc,wBAAwB,CAAA;AACtC,cAAc,qBAAqB,CAAA;AACnC,cAAc,qBAAqB,CAAA;AACnC,cAAc,sBAAsB,CAAA;AACpC,cAAc,yBAAyB,CAAA;AACvC,cAAc,sCAAsC,C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B,CAAA;AAC1C,cAAc,uCAAuC,CAAA;AACrD,cAAc,gCAAgC,CAAA;AAC9C,cAAc,qCAAqC,CAAA;AACnD,cAAc,gCAAgC,CAAA;AAC9C,cAAc,iCAAiC,CAAA"}
package/script/mod.js CHANGED
@@ -70,7 +70,6 @@ __exportStar(require("./typescript/identifiers.js"), exports);
70
70
  __exportStar(require("./typescript/keyValues.js"), exports);
71
71
  __exportStar(require("./typescript/PathParams.js"), exports);
72
72
  __exportStar(require("./typescript/ReactRouterPathParams.js"), exports);
73
- __exportStar(require("./typescript/toDestructuredObject.js"), exports);
74
73
  __exportStar(require("./typescript/toOperationArg.js"), exports);
75
74
  __exportStar(require("./typescript/toOperationResponse.js"), exports);
76
75
  __exportStar(require("./typescript/toPathTemplate.js"), exports);
@@ -0,0 +1,15 @@
1
+ import type { TypeSystemObject } from '../types/TypeSystem.js';
2
+ export declare class DestructuredObject {
3
+ typeSystemObject: TypeSystemObject;
4
+ properties: ObjectProperty[];
5
+ constructor(typeSystemObject: TypeSystemObject);
6
+ toString(): string;
7
+ }
8
+ export declare class ObjectProperty {
9
+ name: string;
10
+ isValid: boolean;
11
+ canonicalName: string;
12
+ constructor(name: string);
13
+ toString(): string;
14
+ }
15
+ //# sourceMappingURL=DestructuredObject.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DestructuredObject.d.ts","sourceRoot":"","sources":["../../src/typescript/DestructuredObject.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAG9D,qBAAa,kBAAkB;IAC7B,gBAAgB,EAAE,gBAAgB,CAAA;IAClC,UAAU,EAAE,cAAc,EAAE,CAAA;gBAChB,gBAAgB,EAAE,gBAAgB;IAQ9C,QAAQ,IAAI,MAAM;CAGnB;AAED,qBAAa,cAAc;IACzB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,OAAO,CAAA;IAChB,aAAa,EAAE,MAAM,CAAA;gBACT,IAAI,EAAE,MAAM;IAYxB,QAAQ,IAAI,MAAM;CAGnB"}
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ObjectProperty = exports.DestructuredObject = void 0;
4
+ const helper_validator_identifier_1 = require("@babel/helper-validator-identifier");
5
+ const lodash_es_1 = require("lodash-es");
6
+ class DestructuredObject {
7
+ constructor(typeSystemObject) {
8
+ Object.defineProperty(this, "typeSystemObject", {
9
+ enumerable: true,
10
+ configurable: true,
11
+ writable: true,
12
+ value: void 0
13
+ });
14
+ Object.defineProperty(this, "properties", {
15
+ enumerable: true,
16
+ configurable: true,
17
+ writable: true,
18
+ value: void 0
19
+ });
20
+ this.typeSystemObject = typeSystemObject;
21
+ this.properties = Object.keys(typeSystemObject.objectProperties?.properties ?? {}).map(name => new ObjectProperty(name));
22
+ }
23
+ toString() {
24
+ return `{${this.properties.map(property => `${property}`).join(',\n')}}`;
25
+ }
26
+ }
27
+ exports.DestructuredObject = DestructuredObject;
28
+ class ObjectProperty {
29
+ constructor(name) {
30
+ Object.defineProperty(this, "name", {
31
+ enumerable: true,
32
+ configurable: true,
33
+ writable: true,
34
+ value: void 0
35
+ });
36
+ Object.defineProperty(this, "isValid", {
37
+ enumerable: true,
38
+ configurable: true,
39
+ writable: true,
40
+ value: void 0
41
+ });
42
+ Object.defineProperty(this, "canonicalName", {
43
+ enumerable: true,
44
+ configurable: true,
45
+ writable: true,
46
+ value: void 0
47
+ });
48
+ this.name = name;
49
+ this.isValid = (0, helper_validator_identifier_1.isIdentifierName)(name);
50
+ this.canonicalName = this.isValid ? name : (0, lodash_es_1.camelCase)(name);
51
+ if (!(0, helper_validator_identifier_1.isIdentifierName)(this.canonicalName)) {
52
+ throw new Error(`Property name '${name}' is not a valid identifier and cannot be converted to a canonical name`);
53
+ }
54
+ }
55
+ toString() {
56
+ return this.isValid ? this.name : `'${this.name}': ${this.canonicalName}`;
57
+ }
58
+ }
59
+ exports.ObjectProperty = ObjectProperty;
@@ -1,5 +1,6 @@
1
1
  import type { TypeSystemObject, TypeSystemValue } from '../types/TypeSystem.js';
2
2
  import type { Definition } from '../dsl/Definition.js';
3
+ import type { Stringable } from '../dsl/Stringable.js';
3
4
  type CreateArgs = {
4
5
  name?: string;
5
6
  typeDefinition: Definition<TypeSystemValue>;
@@ -24,8 +25,7 @@ export declare class FunctionParameter {
24
25
  properties: ParameterProperties;
25
26
  constructor(args: CreateArgs);
26
27
  toDestructured(): FunctionParameter;
27
- toPropertyList(): string[];
28
- toInbound(): string;
28
+ toInbound(): Stringable;
29
29
  toString(): string;
30
30
  }
31
31
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"FunctionParameter.d.ts","sourceRoot":"","sources":["../../src/typescript/FunctionParameter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAE/E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAEtD,KAAK,UAAU,GAAG;IAChB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,cAAc,EAAE,UAAU,CAAC,eAAe,CAAC,CAAA;IAC3C,WAAW,EAAE,OAAO,CAAA;IACpB,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;CAC7C,CAAA;AACD,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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AAU;IAUvB,QAAQ,IAAI,MAAM;CAWnB"}
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.FunctionParameter = void 0;
7
7
  const ts_pattern_1 = require("ts-pattern");
8
8
  const tiny_invariant_1 = __importDefault(require("tiny-invariant"));
9
+ const DestructuredObject_js_1 = require("./DestructuredObject.js");
9
10
  class FunctionParameter {
10
11
  constructor(args) {
11
12
  Object.defineProperty(this, "properties", {
@@ -14,11 +15,6 @@ class FunctionParameter {
14
15
  writable: true,
15
16
  value: void 0
16
17
  });
17
- // @TODO It might be possible to simplify this by adding entityType
18
- // to Definition as one its generic parameter types
19
- if (args.typeDefinition.identifier.entityType.type === 'value') {
20
- throw new Error('Value identifiers cannot be used in type definitions');
21
- }
22
18
  this.properties = (0, ts_pattern_1.match)(args)
23
19
  .with({ typeDefinition: { value: { type: 'void' } } }, () => ({
24
20
  type: 'void'
@@ -47,30 +43,14 @@ class FunctionParameter {
47
43
  destructure: true
48
44
  });
49
45
  }
50
- toPropertyList() {
51
- return (0, ts_pattern_1.match)(this.properties)
52
- .with({ type: 'void' }, () => [])
53
- .with({ type: 'regular' }, ({ name }) => [`${name}`])
54
- .with({ type: 'destructured' }, ({ typeDefinition }) => {
55
- return toPropertyNames(typeDefinition.value).map(name => name === `'If-Match'` ? `'If-Match': IfMatch` : name);
56
- })
57
- .otherwise(() => {
58
- throw new Error('Invalid parameter');
59
- });
60
- }
61
46
  toInbound() {
62
47
  return (0, ts_pattern_1.match)(this.properties)
63
48
  .with({ type: 'void' }, () => '')
64
- .with({ type: 'regular' }, ({ name }) => {
65
- return `${name}`;
66
- })
49
+ .with({ type: 'regular' }, ({ name }) => `${name}`)
67
50
  .with({ type: 'destructured' }, ({ typeDefinition }) => {
68
- const propertyNames = toPropertyNames(typeDefinition.value).map(name => name === `'If-Match'` ? `'If-Match': IfMatch` : name);
69
- return `{${propertyNames.join(', ')}}`;
51
+ return new DestructuredObject_js_1.DestructuredObject(typeDefinition.value);
70
52
  })
71
- .otherwise(() => {
72
- throw new Error('Invalid parameter');
73
- });
53
+ .exhaustive();
74
54
  }
75
55
  toString() {
76
56
  return (0, ts_pattern_1.match)(this.properties)
@@ -79,16 +59,9 @@ class FunctionParameter {
79
59
  return `${name}${required ? '' : '?'}: ${typeDefinition.identifier}`;
80
60
  })
81
61
  .with({ type: 'destructured' }, ({ typeDefinition }) => {
82
- const propertyNames = toPropertyNames(typeDefinition.value).map(name => name === `'If-Match'` ? `'If-Match': IfMatch` : name);
83
- return `{${propertyNames.join(', ')}}: ${typeDefinition.identifier}`;
62
+ return new DestructuredObject_js_1.DestructuredObject(typeDefinition.value).toString();
84
63
  })
85
- .otherwise(() => {
86
- throw new Error('Invalid parameter');
87
- });
64
+ .exhaustive();
88
65
  }
89
66
  }
90
67
  exports.FunctionParameter = FunctionParameter;
91
- const toPropertyNames = (value) => {
92
- (0, tiny_invariant_1.default)(value.objectProperties, 'Only object types can be destructured');
93
- return Object.keys(value.objectProperties.properties);
94
- };
@@ -1,3 +0,0 @@
1
- import type { TypeSystemValue } from '../types/TypeSystem.js';
2
- export declare const toDestructuredObject: (value: TypeSystemValue) => string;
3
- //# sourceMappingURL=toDestructuredObject.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"toDestructuredObject.d.ts","sourceRoot":"","sources":["../../src/typescript/toDestructuredObject.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAE7D,eAAO,MAAM,oBAAoB,UAAW,eAAe,KAAG,MAsB7D,CAAA"}
@@ -1,16 +0,0 @@
1
- export const toDestructuredObject = (value) => {
2
- if (value.type === 'void') {
3
- return '';
4
- }
5
- if (value.type !== 'object' || !value.objectProperties) {
6
- throw new Error('Only object types can be destructured');
7
- }
8
- if (value.recordProperties) {
9
- throw new Error('Objects with record properties cannot be destructured, yet');
10
- }
11
- if (!value.objectProperties.properties) {
12
- throw new Error('Cannot destructure an object without properties');
13
- }
14
- const propertyNames = Object.keys(value.objectProperties.properties);
15
- return `{${propertyNames.join(', ')}}`;
16
- };
@@ -1,3 +0,0 @@
1
- import type { TypeSystemValue } from '../types/TypeSystem.js';
2
- export declare const toDestructuredObject: (value: TypeSystemValue) => string;
3
- //# sourceMappingURL=toDestructuredObject.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"toDestructuredObject.d.ts","sourceRoot":"","sources":["../../src/typescript/toDestructuredObject.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAE7D,eAAO,MAAM,oBAAoB,UAAW,eAAe,KAAG,MAsB7D,CAAA"}
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toDestructuredObject = void 0;
4
- const toDestructuredObject = (value) => {
5
- if (value.type === 'void') {
6
- return '';
7
- }
8
- if (value.type !== 'object' || !value.objectProperties) {
9
- throw new Error('Only object types can be destructured');
10
- }
11
- if (value.recordProperties) {
12
- throw new Error('Objects with record properties cannot be destructured, yet');
13
- }
14
- if (!value.objectProperties.properties) {
15
- throw new Error('Cannot destructure an object without properties');
16
- }
17
- const propertyNames = Object.keys(value.objectProperties.properties);
18
- return `{${propertyNames.join(', ')}}`;
19
- };
20
- exports.toDestructuredObject = toDestructuredObject;