@skmtc/core 0.0.253 → 0.0.255
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 +0 -1
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +0 -1
- package/esm/typescript/DestructuredObject.d.ts +15 -0
- package/esm/typescript/DestructuredObject.d.ts.map +1 -0
- package/esm/typescript/DestructuredObject.js +54 -0
- package/esm/typescript/FunctionParameter.d.ts +3 -2
- package/esm/typescript/FunctionParameter.d.ts.map +1 -1
- package/esm/typescript/FunctionParameter.js +18 -33
- package/package.json +1 -1
- package/script/mod.d.ts +0 -1
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +0 -1
- package/script/typescript/DestructuredObject.d.ts +15 -0
- package/script/typescript/DestructuredObject.d.ts.map +1 -0
- package/script/typescript/DestructuredObject.js +59 -0
- package/script/typescript/FunctionParameter.d.ts +3 -2
- package/script/typescript/FunctionParameter.d.ts.map +1 -1
- package/script/typescript/FunctionParameter.js +18 -33
- package/esm/typescript/toDestructuredObject.d.ts +0 -3
- package/esm/typescript/toDestructuredObject.d.ts.map +0 -1
- package/esm/typescript/toDestructuredObject.js +0 -16
- package/script/typescript/toDestructuredObject.d.ts +0 -3
- package/script/typescript/toDestructuredObject.d.ts.map +0 -1
- package/script/typescript/toDestructuredObject.js +0 -20
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.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kBAAkB,CAAA;AAChC,cAAc,kCAAkC,CAAA;AAChD,cAAc,wBAAwB,CAAA;AACtC,cAAc,wBAAwB,CAAA;AACtC,cAAc,kBAAkB,CAAA;AAChC,cAAc,oBAAoB,CAAA;AAClC,cAAc,kBAAkB,CAAA;AAChC,cAAc,0BAA0B,CAAA;AACxC,cAAc,qBAAqB,CAAA;AACnC,cAAc,0BAA0B,CAAA;AACxC,cAAc,wBAAwB,CAAA;AACtC,cAAc,2BAA2B,CAAA;AACzC,cAAc,0BAA0B,CAAA;AACxC,cAAc,mBAAmB,CAAA;AACjC,cAAc,sBAAsB,CAAA;AACpC,cAAc,2BAA2B,CAAA;AACzC,cAAc,oBAAoB,CAAA;AAClC,cAAc,qBAAqB,CAAA;AACnC,cAAc,uBAAuB,CAAA;AACrC,cAAc,qBAAqB,CAAA;AACnC,cAAc,mCAAmC,CAAA;AACjD,cAAc,6BAA6B,CAAA;AAC3C,cAAc,2BAA2B,CAAA;AACzC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,uCAAuC,CAAA;AACrD,cAAc,gCAAgC,CAAA;AAC9C,cAAc,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>;
|
|
@@ -23,9 +24,9 @@ type RegularParameter = {
|
|
|
23
24
|
export declare class FunctionParameter {
|
|
24
25
|
properties: ParameterProperties;
|
|
25
26
|
constructor(args: CreateArgs);
|
|
27
|
+
hasProperty(name: string): boolean;
|
|
26
28
|
toDestructured(): FunctionParameter;
|
|
27
|
-
|
|
28
|
-
toInbound(): string;
|
|
29
|
+
toInbound(): Stringable;
|
|
29
30
|
toString(): string;
|
|
30
31
|
}
|
|
31
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;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;
|
|
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,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAelC,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'
|
|
@@ -31,6 +27,18 @@ export class FunctionParameter {
|
|
|
31
27
|
throw new Error('Invalid parameter');
|
|
32
28
|
});
|
|
33
29
|
}
|
|
30
|
+
hasProperty(name) {
|
|
31
|
+
return match(this.properties)
|
|
32
|
+
.with({ type: 'void' }, () => false)
|
|
33
|
+
.with({ type: 'regular' }, ({ typeDefinition }) => {
|
|
34
|
+
const { value } = typeDefinition;
|
|
35
|
+
return Boolean(value.type === 'object' && value.objectProperties?.properties[name]);
|
|
36
|
+
})
|
|
37
|
+
.with({ type: 'destructured' }, ({ typeDefinition }) => {
|
|
38
|
+
return Boolean(typeDefinition.value.objectProperties?.properties[name]);
|
|
39
|
+
})
|
|
40
|
+
.exhaustive();
|
|
41
|
+
}
|
|
34
42
|
toDestructured() {
|
|
35
43
|
if (this.properties.type === 'void') {
|
|
36
44
|
return this;
|
|
@@ -41,30 +49,14 @@ export class FunctionParameter {
|
|
|
41
49
|
destructure: true
|
|
42
50
|
});
|
|
43
51
|
}
|
|
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
52
|
toInbound() {
|
|
56
53
|
return match(this.properties)
|
|
57
54
|
.with({ type: 'void' }, () => '')
|
|
58
|
-
.with({ type: 'regular' }, ({ name }) => {
|
|
59
|
-
return `${name}`;
|
|
60
|
-
})
|
|
55
|
+
.with({ type: 'regular' }, ({ name }) => `${name}`)
|
|
61
56
|
.with({ type: 'destructured' }, ({ typeDefinition }) => {
|
|
62
|
-
|
|
63
|
-
return `{${propertyNames.join(', ')}}`;
|
|
57
|
+
return new DestructuredObject(typeDefinition.value);
|
|
64
58
|
})
|
|
65
|
-
.
|
|
66
|
-
throw new Error('Invalid parameter');
|
|
67
|
-
});
|
|
59
|
+
.exhaustive();
|
|
68
60
|
}
|
|
69
61
|
toString() {
|
|
70
62
|
return match(this.properties)
|
|
@@ -73,15 +65,8 @@ export class FunctionParameter {
|
|
|
73
65
|
return `${name}${required ? '' : '?'}: ${typeDefinition.identifier}`;
|
|
74
66
|
})
|
|
75
67
|
.with({ type: 'destructured' }, ({ typeDefinition }) => {
|
|
76
|
-
|
|
77
|
-
return `{${propertyNames.join(', ')}}: ${typeDefinition.identifier}`;
|
|
68
|
+
return new DestructuredObject(typeDefinition.value).toString();
|
|
78
69
|
})
|
|
79
|
-
.
|
|
80
|
-
throw new Error('Invalid parameter');
|
|
81
|
-
});
|
|
70
|
+
.exhaustive();
|
|
82
71
|
}
|
|
83
72
|
}
|
|
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
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';
|
package/script/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,wBAAwB,CAAA;AACtC,cAAc,8BAA8B,CAAA;AAC5C,cAAc,8BAA8B,CAAA;AAC5C,cAAc,kBAAkB,CAAA;AAChC,cAAc,kCAAkC,CAAA;AAChD,cAAc,wBAAwB,CAAA;AACtC,cAAc,wBAAwB,CAAA;AACtC,c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Ac,qBAAqB,CAAA;AACnC,cAAc,sBAAsB,CAAA;AACpC,cAAc,yBAAyB,CAAA;AACvC,cAAc,sCAAsC,CAAA;AACpD,cAAc,4BAA4B,CAAA;AAC1C,cAAc,0BAA0B,CAAA;AACxC,cAAc,wBAAwB,CAAA;AACtC,cAAc,8BAA8B,CAAA;AAC5C,cAAc,8BAA8B,CAAA;AAC5C,cAAc,kBAAkB,CAAA;AAChC,cAAc,kCAAkC,CAAA;AAChD,cAAc,wBAAwB,CAAA;AACtC,cAAc,wBAAwB,CAAA;AACtC,cAAc,kBAAkB,CAAA;AAChC,cAAc,oBAAoB,CAAA;AAClC,cAAc,kBAAkB,CAAA;AAChC,cAAc,0BAA0B,CAAA;AACxC,cAAc,qBAAqB,CAAA;AACnC,cAAc,0BAA0B,CAAA;AACxC,cAAc,wBAAwB,CAAA;AACtC,cAAc,2BAA2B,CAAA;AACzC,cAAc,0BAA0B,CAAA;AACxC,cAAc,mBAAmB,CAAA;AACjC,cAAc,sBAAsB,CAAA;AACpC,cAAc,2BAA2B,CAAA;AACzC,cAAc,oBAAoB,CAAA;AAClC,cAAc,qBAAqB,CAAA;AACnC,cAAc,uBAAuB,CAAA;AACrC,cAAc,qBAAqB,CAAA;AACnC,cAAc,mCAAmC,CAAA;AACjD,cAAc,6BAA6B,CAAA;AAC3C,cAAc,2BAA2B,CAAA;AACzC,cAAc,4BAA4B,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>;
|
|
@@ -23,9 +24,9 @@ type RegularParameter = {
|
|
|
23
24
|
export declare class FunctionParameter {
|
|
24
25
|
properties: ParameterProperties;
|
|
25
26
|
constructor(args: CreateArgs);
|
|
27
|
+
hasProperty(name: string): boolean;
|
|
26
28
|
toDestructured(): FunctionParameter;
|
|
27
|
-
|
|
28
|
-
toInbound(): string;
|
|
29
|
+
toInbound(): Stringable;
|
|
29
30
|
toString(): string;
|
|
30
31
|
}
|
|
31
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;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,KAA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BAAgB,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,SAAS,IAAI,UAAU;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'
|
|
@@ -37,6 +33,18 @@ class FunctionParameter {
|
|
|
37
33
|
throw new Error('Invalid parameter');
|
|
38
34
|
});
|
|
39
35
|
}
|
|
36
|
+
hasProperty(name) {
|
|
37
|
+
return (0, ts_pattern_1.match)(this.properties)
|
|
38
|
+
.with({ type: 'void' }, () => false)
|
|
39
|
+
.with({ type: 'regular' }, ({ typeDefinition }) => {
|
|
40
|
+
const { value } = typeDefinition;
|
|
41
|
+
return Boolean(value.type === 'object' && value.objectProperties?.properties[name]);
|
|
42
|
+
})
|
|
43
|
+
.with({ type: 'destructured' }, ({ typeDefinition }) => {
|
|
44
|
+
return Boolean(typeDefinition.value.objectProperties?.properties[name]);
|
|
45
|
+
})
|
|
46
|
+
.exhaustive();
|
|
47
|
+
}
|
|
40
48
|
toDestructured() {
|
|
41
49
|
if (this.properties.type === 'void') {
|
|
42
50
|
return this;
|
|
@@ -47,30 +55,14 @@ class FunctionParameter {
|
|
|
47
55
|
destructure: true
|
|
48
56
|
});
|
|
49
57
|
}
|
|
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
58
|
toInbound() {
|
|
62
59
|
return (0, ts_pattern_1.match)(this.properties)
|
|
63
60
|
.with({ type: 'void' }, () => '')
|
|
64
|
-
.with({ type: 'regular' }, ({ name }) => {
|
|
65
|
-
return `${name}`;
|
|
66
|
-
})
|
|
61
|
+
.with({ type: 'regular' }, ({ name }) => `${name}`)
|
|
67
62
|
.with({ type: 'destructured' }, ({ typeDefinition }) => {
|
|
68
|
-
|
|
69
|
-
return `{${propertyNames.join(', ')}}`;
|
|
63
|
+
return new DestructuredObject_js_1.DestructuredObject(typeDefinition.value);
|
|
70
64
|
})
|
|
71
|
-
.
|
|
72
|
-
throw new Error('Invalid parameter');
|
|
73
|
-
});
|
|
65
|
+
.exhaustive();
|
|
74
66
|
}
|
|
75
67
|
toString() {
|
|
76
68
|
return (0, ts_pattern_1.match)(this.properties)
|
|
@@ -79,16 +71,9 @@ class FunctionParameter {
|
|
|
79
71
|
return `${name}${required ? '' : '?'}: ${typeDefinition.identifier}`;
|
|
80
72
|
})
|
|
81
73
|
.with({ type: 'destructured' }, ({ typeDefinition }) => {
|
|
82
|
-
|
|
83
|
-
return `{${propertyNames.join(', ')}}: ${typeDefinition.identifier}`;
|
|
74
|
+
return new DestructuredObject_js_1.DestructuredObject(typeDefinition.value).toString();
|
|
84
75
|
})
|
|
85
|
-
.
|
|
86
|
-
throw new Error('Invalid parameter');
|
|
87
|
-
});
|
|
76
|
+
.exhaustive();
|
|
88
77
|
}
|
|
89
78
|
}
|
|
90
79
|
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 +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 +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;
|