@skmtc/core 0.0.257 → 0.0.258
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/typescript/FunctionParameter.d.ts +6 -11
- package/esm/typescript/FunctionParameter.d.ts.map +1 -1
- package/esm/typescript/FunctionParameter.js +9 -25
- package/package.json +1 -1
- package/script/typescript/FunctionParameter.d.ts +6 -11
- package/script/typescript/FunctionParameter.d.ts.map +1 -1
- package/script/typescript/FunctionParameter.js +8 -27
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
import type { TypeSystemObject, TypeSystemValue } 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<
|
|
8
|
-
destructure
|
|
5
|
+
typeDefinition: Definition<TypeSystemObject>;
|
|
6
|
+
destructure?: boolean;
|
|
9
7
|
required?: boolean;
|
|
10
8
|
};
|
|
11
|
-
type ParameterProperties =
|
|
12
|
-
type VoidParameter = {
|
|
13
|
-
type: 'void';
|
|
14
|
-
};
|
|
9
|
+
type ParameterProperties = DestructuredParameter | RegularParameter;
|
|
15
10
|
type DestructuredParameter = {
|
|
16
11
|
type: 'destructured';
|
|
17
12
|
typeDefinition: Definition<TypeSystemObject>;
|
|
13
|
+
required: true;
|
|
18
14
|
};
|
|
19
15
|
type RegularParameter = {
|
|
20
16
|
type: 'regular';
|
|
@@ -26,9 +22,8 @@ export declare class FunctionParameter {
|
|
|
26
22
|
properties: ParameterProperties;
|
|
27
23
|
constructor(args: CreateArgs);
|
|
28
24
|
hasProperty(name: string): boolean;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
toInbound(): Stringable;
|
|
25
|
+
toPropertyList(): string[];
|
|
26
|
+
toInbound(): string;
|
|
32
27
|
toString(): string;
|
|
33
28
|
}
|
|
34
29
|
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;
|
|
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;AAC/E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAGtD,KAAK,UAAU,GAAG;IAChB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,cAAc,EAAE,UAAU,CAAC,gBAAgB,CAAC,CAAA;IAC5C,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA;AAED,KAAK,mBAAmB,GAAG,qBAAqB,GAAG,gBAAgB,CAAA;AAEnE,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;IAqB5B,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAclC,cAAc,IAAI,MAAM,EAAE;IAW1B,SAAS,IAAI,MAAM;IASnB,QAAQ,IAAI,MAAM;CAYnB"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
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) {
|
|
@@ -10,12 +9,10 @@ export class FunctionParameter {
|
|
|
10
9
|
value: void 0
|
|
11
10
|
});
|
|
12
11
|
this.properties = match(args)
|
|
13
|
-
.with({
|
|
14
|
-
type: 'void'
|
|
15
|
-
}))
|
|
16
|
-
.with({ typeDefinition: { value: { type: 'object' } }, destructure: true }, ({ typeDefinition }) => ({
|
|
12
|
+
.with({ destructure: true, required: true }, ({ typeDefinition, required }) => ({
|
|
17
13
|
type: 'destructured',
|
|
18
|
-
typeDefinition
|
|
14
|
+
typeDefinition,
|
|
15
|
+
required
|
|
19
16
|
}))
|
|
20
17
|
.with({ name: P.string }, ({ typeDefinition, name, required }) => ({
|
|
21
18
|
type: 'regular',
|
|
@@ -24,12 +21,11 @@ export class FunctionParameter {
|
|
|
24
21
|
required: required ?? false
|
|
25
22
|
}))
|
|
26
23
|
.otherwise(() => {
|
|
27
|
-
throw new Error('Invalid
|
|
24
|
+
throw new Error('Invalid FunctionParameter');
|
|
28
25
|
});
|
|
29
26
|
}
|
|
30
27
|
hasProperty(name) {
|
|
31
28
|
return match(this.properties)
|
|
32
|
-
.with({ type: 'void' }, () => false)
|
|
33
29
|
.with({ type: 'regular' }, ({ typeDefinition }) => {
|
|
34
30
|
const { value } = typeDefinition;
|
|
35
31
|
return Boolean(value.type === 'object' && value.objectProperties?.properties[name]);
|
|
@@ -39,42 +35,30 @@ export class FunctionParameter {
|
|
|
39
35
|
})
|
|
40
36
|
.exhaustive();
|
|
41
37
|
}
|
|
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
38
|
toPropertyList() {
|
|
53
39
|
return match(this.properties)
|
|
54
|
-
.with({ type: 'void' }, () => [])
|
|
55
40
|
.with({ type: 'regular' }, ({ name }) => [`${name}`])
|
|
56
41
|
.with({ type: 'destructured' }, ({ typeDefinition }) => {
|
|
57
|
-
return new DestructuredObject(typeDefinition.value).properties;
|
|
42
|
+
return new DestructuredObject(typeDefinition.value).properties.map(item => (typeof item === 'string' ? item : item.name));
|
|
58
43
|
})
|
|
59
44
|
.exhaustive();
|
|
60
45
|
}
|
|
61
46
|
toInbound() {
|
|
62
47
|
return match(this.properties)
|
|
63
|
-
.with({ type: 'void' }, () => '')
|
|
64
48
|
.with({ type: 'regular' }, ({ name }) => `${name}`)
|
|
65
49
|
.with({ type: 'destructured' }, ({ typeDefinition }) => {
|
|
66
|
-
return new DestructuredObject(typeDefinition.value);
|
|
50
|
+
return new DestructuredObject(typeDefinition.value).toString();
|
|
67
51
|
})
|
|
68
52
|
.exhaustive();
|
|
69
53
|
}
|
|
70
54
|
toString() {
|
|
71
55
|
return match(this.properties)
|
|
72
|
-
.with({ type: 'void' }, () => '')
|
|
73
56
|
.with({ type: 'regular' }, ({ name, typeDefinition, required }) => {
|
|
74
57
|
return `${name}${required ? '' : '?'}: ${typeDefinition.identifier}`;
|
|
75
58
|
})
|
|
76
59
|
.with({ type: 'destructured' }, ({ typeDefinition }) => {
|
|
77
|
-
|
|
60
|
+
const destructured = new DestructuredObject(typeDefinition.value);
|
|
61
|
+
return `${destructured}: ${typeDefinition.identifier}`;
|
|
78
62
|
})
|
|
79
63
|
.exhaustive();
|
|
80
64
|
}
|
package/package.json
CHANGED
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
import type { TypeSystemObject, TypeSystemValue } 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<
|
|
8
|
-
destructure
|
|
5
|
+
typeDefinition: Definition<TypeSystemObject>;
|
|
6
|
+
destructure?: boolean;
|
|
9
7
|
required?: boolean;
|
|
10
8
|
};
|
|
11
|
-
type ParameterProperties =
|
|
12
|
-
type VoidParameter = {
|
|
13
|
-
type: 'void';
|
|
14
|
-
};
|
|
9
|
+
type ParameterProperties = DestructuredParameter | RegularParameter;
|
|
15
10
|
type DestructuredParameter = {
|
|
16
11
|
type: 'destructured';
|
|
17
12
|
typeDefinition: Definition<TypeSystemObject>;
|
|
13
|
+
required: true;
|
|
18
14
|
};
|
|
19
15
|
type RegularParameter = {
|
|
20
16
|
type: 'regular';
|
|
@@ -26,9 +22,8 @@ export declare class FunctionParameter {
|
|
|
26
22
|
properties: ParameterProperties;
|
|
27
23
|
constructor(args: CreateArgs);
|
|
28
24
|
hasProperty(name: string): boolean;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
toInbound(): Stringable;
|
|
25
|
+
toPropertyList(): string[];
|
|
26
|
+
toInbound(): string;
|
|
32
27
|
toString(): string;
|
|
33
28
|
}
|
|
34
29
|
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;
|
|
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;AAC/E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAGtD,KAAK,UAAU,GAAG;IAChB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,cAAc,EAAE,UAAU,CAAC,gBAAgB,CAAC,CAAA;IAC5C,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA;AAED,KAAK,mBAAmB,GAAG,qBAAqB,GAAG,gBAAgB,CAAA;AAEnE,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;IAqB5B,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAclC,cAAc,IAAI,MAAM,EAAE;IAW1B,SAAS,IAAI,MAAM;IASnB,QAAQ,IAAI,MAAM;CAYnB"}
|
|
@@ -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) {
|
|
@@ -16,12 +12,10 @@ class FunctionParameter {
|
|
|
16
12
|
value: void 0
|
|
17
13
|
});
|
|
18
14
|
this.properties = (0, ts_pattern_1.match)(args)
|
|
19
|
-
.with({
|
|
20
|
-
type: 'void'
|
|
21
|
-
}))
|
|
22
|
-
.with({ typeDefinition: { value: { type: 'object' } }, destructure: true }, ({ typeDefinition }) => ({
|
|
15
|
+
.with({ destructure: true, required: true }, ({ typeDefinition, required }) => ({
|
|
23
16
|
type: 'destructured',
|
|
24
|
-
typeDefinition
|
|
17
|
+
typeDefinition,
|
|
18
|
+
required
|
|
25
19
|
}))
|
|
26
20
|
.with({ name: ts_pattern_1.P.string }, ({ typeDefinition, name, required }) => ({
|
|
27
21
|
type: 'regular',
|
|
@@ -30,12 +24,11 @@ class FunctionParameter {
|
|
|
30
24
|
required: required ?? false
|
|
31
25
|
}))
|
|
32
26
|
.otherwise(() => {
|
|
33
|
-
throw new Error('Invalid
|
|
27
|
+
throw new Error('Invalid FunctionParameter');
|
|
34
28
|
});
|
|
35
29
|
}
|
|
36
30
|
hasProperty(name) {
|
|
37
31
|
return (0, ts_pattern_1.match)(this.properties)
|
|
38
|
-
.with({ type: 'void' }, () => false)
|
|
39
32
|
.with({ type: 'regular' }, ({ typeDefinition }) => {
|
|
40
33
|
const { value } = typeDefinition;
|
|
41
34
|
return Boolean(value.type === 'object' && value.objectProperties?.properties[name]);
|
|
@@ -45,42 +38,30 @@ class FunctionParameter {
|
|
|
45
38
|
})
|
|
46
39
|
.exhaustive();
|
|
47
40
|
}
|
|
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
41
|
toPropertyList() {
|
|
59
42
|
return (0, ts_pattern_1.match)(this.properties)
|
|
60
|
-
.with({ type: 'void' }, () => [])
|
|
61
43
|
.with({ type: 'regular' }, ({ name }) => [`${name}`])
|
|
62
44
|
.with({ type: 'destructured' }, ({ typeDefinition }) => {
|
|
63
|
-
return new DestructuredObject_js_1.DestructuredObject(typeDefinition.value).properties;
|
|
45
|
+
return new DestructuredObject_js_1.DestructuredObject(typeDefinition.value).properties.map(item => (typeof item === 'string' ? item : item.name));
|
|
64
46
|
})
|
|
65
47
|
.exhaustive();
|
|
66
48
|
}
|
|
67
49
|
toInbound() {
|
|
68
50
|
return (0, ts_pattern_1.match)(this.properties)
|
|
69
|
-
.with({ type: 'void' }, () => '')
|
|
70
51
|
.with({ type: 'regular' }, ({ name }) => `${name}`)
|
|
71
52
|
.with({ type: 'destructured' }, ({ typeDefinition }) => {
|
|
72
|
-
return new DestructuredObject_js_1.DestructuredObject(typeDefinition.value);
|
|
53
|
+
return new DestructuredObject_js_1.DestructuredObject(typeDefinition.value).toString();
|
|
73
54
|
})
|
|
74
55
|
.exhaustive();
|
|
75
56
|
}
|
|
76
57
|
toString() {
|
|
77
58
|
return (0, ts_pattern_1.match)(this.properties)
|
|
78
|
-
.with({ type: 'void' }, () => '')
|
|
79
59
|
.with({ type: 'regular' }, ({ name, typeDefinition, required }) => {
|
|
80
60
|
return `${name}${required ? '' : '?'}: ${typeDefinition.identifier}`;
|
|
81
61
|
})
|
|
82
62
|
.with({ type: 'destructured' }, ({ typeDefinition }) => {
|
|
83
|
-
|
|
63
|
+
const destructured = new DestructuredObject_js_1.DestructuredObject(typeDefinition.value);
|
|
64
|
+
return `${destructured}: ${typeDefinition.identifier}`;
|
|
84
65
|
})
|
|
85
66
|
.exhaustive();
|
|
86
67
|
}
|