@skmtc/core 0.0.229 → 0.0.232

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,27 +1,23 @@
1
- import type { Identifier } from '../dsl/Identifier.js';
2
- import type { TypeSystemObject, TypeSystemValue, TypeSystemVoid } from '../types/TypeSystem.js';
1
+ import type { TypeSystemObject, TypeSystemValue } from '../types/TypeSystem.js';
2
+ import type { Definition } from '../dsl/Definition.js';
3
3
  type CreateArgs = {
4
4
  name?: string;
5
- identifier: Identifier;
6
- value: TypeSystemValue;
5
+ typeDefinition: Definition<TypeSystemValue>;
7
6
  destructure: boolean;
8
7
  required?: boolean;
9
8
  };
10
9
  type ParameterProperties = VoidParameter | DestructuredParameter | RegularParameter;
11
10
  type VoidParameter = {
12
11
  type: 'void';
13
- value: TypeSystemVoid;
14
12
  };
15
13
  type DestructuredParameter = {
16
14
  type: 'destructured';
17
- identifier: Identifier;
18
- value: TypeSystemObject;
15
+ typeDefinition: Definition<TypeSystemObject>;
19
16
  };
20
17
  type RegularParameter = {
21
18
  type: 'regular';
22
19
  name: string;
23
- identifier: Identifier;
24
- value: TypeSystemValue;
20
+ typeDefinition: Definition<TypeSystemValue>;
25
21
  required: boolean;
26
22
  };
27
23
  export declare class FunctionParameter {
@@ -1 +1 @@
1
- {"version":3,"file":"FunctionParameter.d.ts","sourceRoot":"","sources":["../../src/typescript/FunctionParameter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EACf,cAAc,EACf,MAAM,wBAAwB,CAAA;AAG/B,KAAK,UAAU,GAAG;IAChB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,UAAU,EAAE,UAAU,CAAA;IACtB,KAAK,EAAE,eAAe,CAAA;IACtB,WAAW,EAAE,OAAO,CAAA;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB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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"}
@@ -8,21 +8,23 @@ export class FunctionParameter {
8
8
  writable: true,
9
9
  value: void 0
10
10
  });
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
+ }
11
16
  this.properties = match(args)
12
- .with({ value: { type: 'void' } }, ({ value }) => ({
13
- type: 'void',
14
- value
17
+ .with({ typeDefinition: { value: { type: 'void' } } }, () => ({
18
+ type: 'void'
15
19
  }))
16
- .with({ value: { type: 'object' }, destructure: true }, ({ value, identifier }) => ({
20
+ .with({ typeDefinition: { value: { type: 'object' } }, destructure: true }, ({ typeDefinition }) => ({
17
21
  type: 'destructured',
18
- identifier,
19
- value
22
+ typeDefinition
20
23
  }))
21
- .with({ name: P.string }, ({ identifier, value, name, required }) => ({
24
+ .with({ name: P.string }, ({ typeDefinition, name, required }) => ({
22
25
  type: 'regular',
23
- identifier,
24
26
  name,
25
- value,
27
+ typeDefinition,
26
28
  required: required ?? false
27
29
  }))
28
30
  .otherwise(() => {
@@ -33,10 +35,9 @@ export class FunctionParameter {
33
35
  if (this.properties.type === 'void') {
34
36
  return this;
35
37
  }
36
- invariant(this.properties.value.type === 'object', 'Only object types can be destructured');
38
+ invariant(this.properties.typeDefinition.value.type === 'object', 'Only object types can be destructured');
37
39
  return new FunctionParameter({
38
- identifier: this.properties.identifier,
39
- value: this.properties.value,
40
+ typeDefinition: this.properties.typeDefinition,
40
41
  destructure: true
41
42
  });
42
43
  }
@@ -44,8 +45,8 @@ export class FunctionParameter {
44
45
  return match(this.properties)
45
46
  .with({ type: 'void' }, () => [])
46
47
  .with({ type: 'regular' }, ({ name }) => [`${name}`])
47
- .with({ type: 'destructured' }, ({ value }) => {
48
- return toPropertyNames(value).map(name => name === `'If-Match'` ? `'If-Match': IfMatch` : name);
48
+ .with({ type: 'destructured' }, ({ typeDefinition }) => {
49
+ return toPropertyNames(typeDefinition.value).map(name => name === `'If-Match'` ? `'If-Match': IfMatch` : name);
49
50
  })
50
51
  .otherwise(() => {
51
52
  throw new Error('Invalid parameter');
@@ -57,8 +58,8 @@ export class FunctionParameter {
57
58
  .with({ type: 'regular' }, ({ name }) => {
58
59
  return `${name}`;
59
60
  })
60
- .with({ type: 'destructured' }, ({ value }) => {
61
- const propertyNames = toPropertyNames(value).map(name => name === `'If-Match'` ? `'If-Match': IfMatch` : name);
61
+ .with({ type: 'destructured' }, ({ typeDefinition }) => {
62
+ const propertyNames = toPropertyNames(typeDefinition.value).map(name => name === `'If-Match'` ? `'If-Match': IfMatch` : name);
62
63
  return `{${propertyNames.join(', ')}}`;
63
64
  })
64
65
  .otherwise(() => {
@@ -68,12 +69,12 @@ export class FunctionParameter {
68
69
  toString() {
69
70
  return match(this.properties)
70
71
  .with({ type: 'void' }, () => '')
71
- .with({ type: 'regular' }, ({ name, identifier, required }) => {
72
- return `${name}${required ? '' : '?'}: ${identifier}`;
72
+ .with({ type: 'regular' }, ({ name, typeDefinition, required }) => {
73
+ return `${name}${required ? '' : '?'}: ${typeDefinition.identifier}`;
73
74
  })
74
- .with({ type: 'destructured' }, ({ identifier, value }) => {
75
- const propertyNames = toPropertyNames(value).map(name => name === `'If-Match'` ? `'If-Match': IfMatch` : name);
76
- return `{${propertyNames.join(', ')}}: ${identifier}`;
75
+ .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}`;
77
78
  })
78
79
  .otherwise(() => {
79
80
  throw new Error('Invalid parameter');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skmtc/core",
3
- "version": "0.0.229",
3
+ "version": "0.0.232",
4
4
  "main": "./script/mod.js",
5
5
  "module": "./esm/mod.js",
6
6
  "exports": {
@@ -1,27 +1,23 @@
1
- import type { Identifier } from '../dsl/Identifier.js';
2
- import type { TypeSystemObject, TypeSystemValue, TypeSystemVoid } from '../types/TypeSystem.js';
1
+ import type { TypeSystemObject, TypeSystemValue } from '../types/TypeSystem.js';
2
+ import type { Definition } from '../dsl/Definition.js';
3
3
  type CreateArgs = {
4
4
  name?: string;
5
- identifier: Identifier;
6
- value: TypeSystemValue;
5
+ typeDefinition: Definition<TypeSystemValue>;
7
6
  destructure: boolean;
8
7
  required?: boolean;
9
8
  };
10
9
  type ParameterProperties = VoidParameter | DestructuredParameter | RegularParameter;
11
10
  type VoidParameter = {
12
11
  type: 'void';
13
- value: TypeSystemVoid;
14
12
  };
15
13
  type DestructuredParameter = {
16
14
  type: 'destructured';
17
- identifier: Identifier;
18
- value: TypeSystemObject;
15
+ typeDefinition: Definition<TypeSystemObject>;
19
16
  };
20
17
  type RegularParameter = {
21
18
  type: 'regular';
22
19
  name: string;
23
- identifier: Identifier;
24
- value: TypeSystemValue;
20
+ typeDefinition: Definition<TypeSystemValue>;
25
21
  required: boolean;
26
22
  };
27
23
  export declare class FunctionParameter {
@@ -1 +1 @@
1
- {"version":3,"file":"FunctionParameter.d.ts","sourceRoot":"","sources":["../../src/typescript/FunctionParameter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EACf,cAAc,EACf,MAAM,wBAAwB,CAAA;AAG/B,KAAK,UAAU,GAAG;IAChB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,UAAU,EAAE,UAAU,CAAA;IACtB,KAAK,EAAE,eAAe,CAAA;IACtB,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;IACZ,KAAK,EAAE,cAAc,CAAA;CACtB,CAAA;AACD,KAAK,qBAAqB,GAAG;IAC3B,IAAI,EAAE,cAAc,CAAA;IACpB,UAAU,EAAE,UAAU,CAAA;IACtB,KAAK,EAAE,gBAAgB,CAAA;CACxB,CAAA;AACD,KAAK,gBAAgB,GAAG;IACtB,IAAI,EAAE,SAAS,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,EAAE,UAAU,CAAA;IACtB,KAAK,EAAE,eAAe,CAAA;IACtB,QAAQ,EAAE,OAAO,CAAA;CAClB,CAAA;AAED,qBAAa,iBAAiB;IAC5B,UAAU,EAAE,mBAAmB,CAAA;gBAEnB,IAAI,EAAE,UAAU;IA0B5B,cAAc,IAAI,iBAAiB;IAiBnC,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,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"}
@@ -14,21 +14,23 @@ class FunctionParameter {
14
14
  writable: true,
15
15
  value: void 0
16
16
  });
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
+ }
17
22
  this.properties = (0, ts_pattern_1.match)(args)
18
- .with({ value: { type: 'void' } }, ({ value }) => ({
19
- type: 'void',
20
- value
23
+ .with({ typeDefinition: { value: { type: 'void' } } }, () => ({
24
+ type: 'void'
21
25
  }))
22
- .with({ value: { type: 'object' }, destructure: true }, ({ value, identifier }) => ({
26
+ .with({ typeDefinition: { value: { type: 'object' } }, destructure: true }, ({ typeDefinition }) => ({
23
27
  type: 'destructured',
24
- identifier,
25
- value
28
+ typeDefinition
26
29
  }))
27
- .with({ name: ts_pattern_1.P.string }, ({ identifier, value, name, required }) => ({
30
+ .with({ name: ts_pattern_1.P.string }, ({ typeDefinition, name, required }) => ({
28
31
  type: 'regular',
29
- identifier,
30
32
  name,
31
- value,
33
+ typeDefinition,
32
34
  required: required ?? false
33
35
  }))
34
36
  .otherwise(() => {
@@ -39,10 +41,9 @@ class FunctionParameter {
39
41
  if (this.properties.type === 'void') {
40
42
  return this;
41
43
  }
42
- (0, tiny_invariant_1.default)(this.properties.value.type === 'object', 'Only object types can be destructured');
44
+ (0, tiny_invariant_1.default)(this.properties.typeDefinition.value.type === 'object', 'Only object types can be destructured');
43
45
  return new FunctionParameter({
44
- identifier: this.properties.identifier,
45
- value: this.properties.value,
46
+ typeDefinition: this.properties.typeDefinition,
46
47
  destructure: true
47
48
  });
48
49
  }
@@ -50,8 +51,8 @@ class FunctionParameter {
50
51
  return (0, ts_pattern_1.match)(this.properties)
51
52
  .with({ type: 'void' }, () => [])
52
53
  .with({ type: 'regular' }, ({ name }) => [`${name}`])
53
- .with({ type: 'destructured' }, ({ value }) => {
54
- return toPropertyNames(value).map(name => name === `'If-Match'` ? `'If-Match': IfMatch` : name);
54
+ .with({ type: 'destructured' }, ({ typeDefinition }) => {
55
+ return toPropertyNames(typeDefinition.value).map(name => name === `'If-Match'` ? `'If-Match': IfMatch` : name);
55
56
  })
56
57
  .otherwise(() => {
57
58
  throw new Error('Invalid parameter');
@@ -63,8 +64,8 @@ class FunctionParameter {
63
64
  .with({ type: 'regular' }, ({ name }) => {
64
65
  return `${name}`;
65
66
  })
66
- .with({ type: 'destructured' }, ({ value }) => {
67
- const propertyNames = toPropertyNames(value).map(name => name === `'If-Match'` ? `'If-Match': IfMatch` : name);
67
+ .with({ type: 'destructured' }, ({ typeDefinition }) => {
68
+ const propertyNames = toPropertyNames(typeDefinition.value).map(name => name === `'If-Match'` ? `'If-Match': IfMatch` : name);
68
69
  return `{${propertyNames.join(', ')}}`;
69
70
  })
70
71
  .otherwise(() => {
@@ -74,12 +75,12 @@ class FunctionParameter {
74
75
  toString() {
75
76
  return (0, ts_pattern_1.match)(this.properties)
76
77
  .with({ type: 'void' }, () => '')
77
- .with({ type: 'regular' }, ({ name, identifier, required }) => {
78
- return `${name}${required ? '' : '?'}: ${identifier}`;
78
+ .with({ type: 'regular' }, ({ name, typeDefinition, required }) => {
79
+ return `${name}${required ? '' : '?'}: ${typeDefinition.identifier}`;
79
80
  })
80
- .with({ type: 'destructured' }, ({ identifier, value }) => {
81
- const propertyNames = toPropertyNames(value).map(name => name === `'If-Match'` ? `'If-Match': IfMatch` : name);
82
- return `{${propertyNames.join(', ')}}: ${identifier}`;
81
+ .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}`;
83
84
  })
84
85
  .otherwise(() => {
85
86
  throw new Error('Invalid parameter');