@skmtc/core 0.0.257 → 0.0.259

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.
@@ -1,11 +1,9 @@
1
- import type { TypeSystemObject, TypeSystemValue } from '../types/TypeSystem.js';
1
+ import type { TypeSystemObject, TypeSystemValue, TypeSystemVoid } from '../types/TypeSystem.js';
2
2
  import type { Definition } from '../dsl/Definition.js';
3
- import { ObjectProperty } from './DestructuredObject.js';
4
- import type { Stringable } from '../dsl/Stringable.js';
5
3
  type CreateArgs = {
6
4
  name?: string;
7
- typeDefinition: Definition<TypeSystemValue>;
8
- destructure: boolean;
5
+ typeDefinition: Definition<TypeSystemObject | TypeSystemVoid>;
6
+ destructure?: boolean;
9
7
  required?: boolean;
10
8
  };
11
9
  type ParameterProperties = VoidParameter | DestructuredParameter | RegularParameter;
@@ -15,6 +13,7 @@ type VoidParameter = {
15
13
  type DestructuredParameter = {
16
14
  type: 'destructured';
17
15
  typeDefinition: Definition<TypeSystemObject>;
16
+ required: true;
18
17
  };
19
18
  type RegularParameter = {
20
19
  type: 'regular';
@@ -26,9 +25,8 @@ export declare class FunctionParameter {
26
25
  properties: ParameterProperties;
27
26
  constructor(args: CreateArgs);
28
27
  hasProperty(name: string): boolean;
29
- toDestructured(): FunctionParameter;
30
- toPropertyList(): string[] | ObjectProperty[];
31
- toInbound(): Stringable;
28
+ toPropertyList(): string[];
29
+ toInbound(): string;
32
30
  toString(): string;
33
31
  }
34
32
  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;AACtD,OAAO,EAAsB,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,KAAK,EAA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,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,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,MAAM,EAAE;IAY1B,SAAS,IAAI,MAAM;IAUnB,QAAQ,IAAI,MAAM;CAanB"}
@@ -1,5 +1,4 @@
1
- import { P, match } from 'ts-pattern';
2
- import invariant from 'tiny-invariant';
1
+ import { match, P } from 'ts-pattern';
3
2
  import { DestructuredObject } from './DestructuredObject.js';
4
3
  export class FunctionParameter {
5
4
  constructor(args) {
@@ -9,23 +8,26 @@ export class FunctionParameter {
9
8
  writable: true,
10
9
  value: void 0
11
10
  });
12
- this.properties = match(args)
13
- .with({ typeDefinition: { value: { type: 'void' } } }, () => ({
14
- type: 'void'
15
- }))
16
- .with({ typeDefinition: { value: { type: 'object' } }, destructure: true }, ({ typeDefinition }) => ({
17
- type: 'destructured',
18
- typeDefinition
19
- }))
20
- .with({ name: P.string }, ({ typeDefinition, name, required }) => ({
21
- type: 'regular',
22
- name,
23
- typeDefinition,
24
- required: required ?? false
25
- }))
26
- .otherwise(() => {
27
- throw new Error('Invalid parameter');
28
- });
11
+ if (args.typeDefinition.value.type === 'object') {
12
+ this.properties = match(args)
13
+ .with({ destructure: true, required: true }, ({ typeDefinition, required }) => ({
14
+ type: 'destructured',
15
+ typeDefinition: typeDefinition,
16
+ required
17
+ }))
18
+ .with({ name: P.string }, ({ typeDefinition, name, required }) => ({
19
+ type: 'regular',
20
+ name,
21
+ typeDefinition: typeDefinition,
22
+ required: required ?? false
23
+ }))
24
+ .otherwise(() => {
25
+ throw new Error('Invalid FunctionParameter');
26
+ });
27
+ }
28
+ else {
29
+ this.properties = { type: 'void' };
30
+ }
29
31
  }
30
32
  hasProperty(name) {
31
33
  return match(this.properties)
@@ -39,22 +41,12 @@ export class FunctionParameter {
39
41
  })
40
42
  .exhaustive();
41
43
  }
42
- toDestructured() {
43
- if (this.properties.type === 'void') {
44
- return this;
45
- }
46
- invariant(this.properties.typeDefinition.value.type === 'object', 'Only object types can be destructured');
47
- return new FunctionParameter({
48
- typeDefinition: this.properties.typeDefinition,
49
- destructure: true
50
- });
51
- }
52
44
  toPropertyList() {
53
45
  return match(this.properties)
54
46
  .with({ type: 'void' }, () => [])
55
47
  .with({ type: 'regular' }, ({ name }) => [`${name}`])
56
48
  .with({ type: 'destructured' }, ({ typeDefinition }) => {
57
- return new DestructuredObject(typeDefinition.value).properties;
49
+ return new DestructuredObject(typeDefinition.value).properties.map(item => (typeof item === 'string' ? item : item.name));
58
50
  })
59
51
  .exhaustive();
60
52
  }
@@ -63,7 +55,7 @@ export class FunctionParameter {
63
55
  .with({ type: 'void' }, () => '')
64
56
  .with({ type: 'regular' }, ({ name }) => `${name}`)
65
57
  .with({ type: 'destructured' }, ({ typeDefinition }) => {
66
- return new DestructuredObject(typeDefinition.value);
58
+ return new DestructuredObject(typeDefinition.value).toString();
67
59
  })
68
60
  .exhaustive();
69
61
  }
@@ -74,7 +66,8 @@ export class FunctionParameter {
74
66
  return `${name}${required ? '' : '?'}: ${typeDefinition.identifier}`;
75
67
  })
76
68
  .with({ type: 'destructured' }, ({ typeDefinition }) => {
77
- return new DestructuredObject(typeDefinition.value).toString();
69
+ const destructured = new DestructuredObject(typeDefinition.value);
70
+ return `${destructured}: ${typeDefinition.identifier}`;
78
71
  })
79
72
  .exhaustive();
80
73
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skmtc/core",
3
- "version": "0.0.257",
3
+ "version": "0.0.259",
4
4
  "main": "./script/mod.js",
5
5
  "module": "./esm/mod.js",
6
6
  "exports": {
@@ -1,11 +1,9 @@
1
- import type { TypeSystemObject, TypeSystemValue } from '../types/TypeSystem.js';
1
+ import type { TypeSystemObject, TypeSystemValue, TypeSystemVoid } from '../types/TypeSystem.js';
2
2
  import type { Definition } from '../dsl/Definition.js';
3
- import { ObjectProperty } from './DestructuredObject.js';
4
- import type { Stringable } from '../dsl/Stringable.js';
5
3
  type CreateArgs = {
6
4
  name?: string;
7
- typeDefinition: Definition<TypeSystemValue>;
8
- destructure: boolean;
5
+ typeDefinition: Definition<TypeSystemObject | TypeSystemVoid>;
6
+ destructure?: boolean;
9
7
  required?: boolean;
10
8
  };
11
9
  type ParameterProperties = VoidParameter | DestructuredParameter | RegularParameter;
@@ -15,6 +13,7 @@ type VoidParameter = {
15
13
  type DestructuredParameter = {
16
14
  type: 'destructured';
17
15
  typeDefinition: Definition<TypeSystemObject>;
16
+ required: true;
18
17
  };
19
18
  type RegularParameter = {
20
19
  type: 'regular';
@@ -26,9 +25,8 @@ export declare class FunctionParameter {
26
25
  properties: ParameterProperties;
27
26
  constructor(args: CreateArgs);
28
27
  hasProperty(name: string): boolean;
29
- toDestructured(): FunctionParameter;
30
- toPropertyList(): string[] | ObjectProperty[];
31
- toInbound(): Stringable;
28
+ toPropertyList(): string[];
29
+ toInbound(): string;
32
30
  toString(): string;
33
31
  }
34
32
  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;AACtD,OAAO,EAAsB,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAC5E,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,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAelC,cAAc,IAAI,iBAAiB;IAgBnC,cAAc,IAAI,MAAM,EAAE,GAAG,cAAc,EAAE;IAU7C,SAAS,IAAI,UAAU;IAUvB,QAAQ,IAAI,MAAM;CAWnB"}
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;AAGtD,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,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,MAAM,EAAE;IAY1B,SAAS,IAAI,MAAM;IAUnB,QAAQ,IAAI,MAAM;CAanB"}
@@ -1,11 +1,7 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.FunctionParameter = void 0;
7
4
  const ts_pattern_1 = require("ts-pattern");
8
- const tiny_invariant_1 = __importDefault(require("tiny-invariant"));
9
5
  const DestructuredObject_js_1 = require("./DestructuredObject.js");
10
6
  class FunctionParameter {
11
7
  constructor(args) {
@@ -15,23 +11,26 @@ class FunctionParameter {
15
11
  writable: true,
16
12
  value: void 0
17
13
  });
18
- this.properties = (0, ts_pattern_1.match)(args)
19
- .with({ typeDefinition: { value: { type: 'void' } } }, () => ({
20
- type: 'void'
21
- }))
22
- .with({ typeDefinition: { value: { type: 'object' } }, destructure: true }, ({ typeDefinition }) => ({
23
- type: 'destructured',
24
- typeDefinition
25
- }))
26
- .with({ name: ts_pattern_1.P.string }, ({ typeDefinition, name, required }) => ({
27
- type: 'regular',
28
- name,
29
- typeDefinition,
30
- required: required ?? false
31
- }))
32
- .otherwise(() => {
33
- throw new Error('Invalid parameter');
34
- });
14
+ if (args.typeDefinition.value.type === 'object') {
15
+ this.properties = (0, ts_pattern_1.match)(args)
16
+ .with({ destructure: true, required: true }, ({ typeDefinition, required }) => ({
17
+ type: 'destructured',
18
+ typeDefinition: typeDefinition,
19
+ required
20
+ }))
21
+ .with({ name: ts_pattern_1.P.string }, ({ typeDefinition, name, required }) => ({
22
+ type: 'regular',
23
+ name,
24
+ typeDefinition: typeDefinition,
25
+ required: required ?? false
26
+ }))
27
+ .otherwise(() => {
28
+ throw new Error('Invalid FunctionParameter');
29
+ });
30
+ }
31
+ else {
32
+ this.properties = { type: 'void' };
33
+ }
35
34
  }
36
35
  hasProperty(name) {
37
36
  return (0, ts_pattern_1.match)(this.properties)
@@ -45,22 +44,12 @@ class FunctionParameter {
45
44
  })
46
45
  .exhaustive();
47
46
  }
48
- toDestructured() {
49
- if (this.properties.type === 'void') {
50
- return this;
51
- }
52
- (0, tiny_invariant_1.default)(this.properties.typeDefinition.value.type === 'object', 'Only object types can be destructured');
53
- return new FunctionParameter({
54
- typeDefinition: this.properties.typeDefinition,
55
- destructure: true
56
- });
57
- }
58
47
  toPropertyList() {
59
48
  return (0, ts_pattern_1.match)(this.properties)
60
49
  .with({ type: 'void' }, () => [])
61
50
  .with({ type: 'regular' }, ({ name }) => [`${name}`])
62
51
  .with({ type: 'destructured' }, ({ typeDefinition }) => {
63
- return new DestructuredObject_js_1.DestructuredObject(typeDefinition.value).properties;
52
+ return new DestructuredObject_js_1.DestructuredObject(typeDefinition.value).properties.map(item => (typeof item === 'string' ? item : item.name));
64
53
  })
65
54
  .exhaustive();
66
55
  }
@@ -69,7 +58,7 @@ class FunctionParameter {
69
58
  .with({ type: 'void' }, () => '')
70
59
  .with({ type: 'regular' }, ({ name }) => `${name}`)
71
60
  .with({ type: 'destructured' }, ({ typeDefinition }) => {
72
- return new DestructuredObject_js_1.DestructuredObject(typeDefinition.value);
61
+ return new DestructuredObject_js_1.DestructuredObject(typeDefinition.value).toString();
73
62
  })
74
63
  .exhaustive();
75
64
  }
@@ -80,7 +69,8 @@ class FunctionParameter {
80
69
  return `${name}${required ? '' : '?'}: ${typeDefinition.identifier}`;
81
70
  })
82
71
  .with({ type: 'destructured' }, ({ typeDefinition }) => {
83
- return new DestructuredObject_js_1.DestructuredObject(typeDefinition.value).toString();
72
+ const destructured = new DestructuredObject_js_1.DestructuredObject(typeDefinition.value);
73
+ return `${destructured}: ${typeDefinition.identifier}`;
84
74
  })
85
75
  .exhaustive();
86
76
  }