@seamapi/nextlove-sdk-generator 1.11.3 → 1.12.0
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/lib/generate-python-sdk/class-file.js +26 -26
- package/lib/generate-python-sdk/class-file.js.map +1 -1
- package/lib/generate-python-sdk/generate-python-sdk.js +3 -5
- package/lib/generate-python-sdk/generate-python-sdk.js.map +1 -1
- package/lib/generate-python-sdk/templates/routes.py.template.js +5 -3
- package/lib/generate-python-sdk/templates/routes.py.template.js.map +1 -1
- package/package.json +1 -1
- package/src/lib/generate-python-sdk/class-file.ts +61 -65
- package/src/lib/generate-python-sdk/generate-python-sdk.ts +3 -5
- package/src/lib/generate-python-sdk/templates/routes.py.template.ts +8 -3
- package/lib/generate-python-sdk/templates/utils/action-attempt.d.ts +0 -20
- package/lib/generate-python-sdk/templates/utils/action-attempt.js +0 -91
- package/lib/generate-python-sdk/templates/utils/action-attempt.js.map +0 -1
- package/lib/generate-python-sdk/templates/utils/deep_attr_dict.py.template.d.ts +0 -2
- package/lib/generate-python-sdk/templates/utils/deep_attr_dict.py.template.js +0 -28
- package/lib/generate-python-sdk/templates/utils/deep_attr_dict.py.template.js.map +0 -1
- package/src/lib/generate-python-sdk/templates/utils/action-attempt.ts +0 -93
- package/src/lib/generate-python-sdk/templates/utils/deep_attr_dict.py.template.ts +0 -27
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { action_attempt_imports, action_attempt_utils_definitions, action_attempt_utils_specs, action_attempt_error_definitions, } from "./templates/utils/action-attempt.js";
|
|
2
1
|
export class ClassFile {
|
|
3
2
|
constructor(name, namespace, child_class_identifiers) {
|
|
4
3
|
this.name = name;
|
|
@@ -13,7 +12,7 @@ export class ClassFile {
|
|
|
13
12
|
const has_child_classes = this.child_class_identifiers.length > 0;
|
|
14
13
|
return [
|
|
15
14
|
`class Abstract${this.name}(abc.ABC):`,
|
|
16
|
-
this.methods.length === 0 ? ` pass` : "",
|
|
15
|
+
this.methods.length === 0 && !has_child_classes ? ` pass` : "",
|
|
17
16
|
`${has_child_classes
|
|
18
17
|
? this.child_class_identifiers
|
|
19
18
|
.map((i) => [
|
|
@@ -24,13 +23,9 @@ export class ClassFile {
|
|
|
24
23
|
].join("\n"))
|
|
25
24
|
.join("\n\n")
|
|
26
25
|
: ""}`,
|
|
27
|
-
...this.methods
|
|
28
|
-
.concat(this.name === "ActionAttempts" ? action_attempt_utils_specs : [])
|
|
29
|
-
.map(({ method_name, parameters, return_resource }) => {
|
|
26
|
+
...this.methods.map(({ method_name, parameters, return_resource }) => {
|
|
30
27
|
const has_params = parameters.length > 0;
|
|
31
|
-
const
|
|
32
|
-
const can_method_poll_action_attempt = return_resource === "ActionAttempt" &&
|
|
33
|
-
!action_attempt_util_method_names.includes(method_name);
|
|
28
|
+
const can_method_poll_action_attempt = return_resource === "ActionAttempt";
|
|
34
29
|
return [
|
|
35
30
|
"",
|
|
36
31
|
"",
|
|
@@ -60,31 +55,30 @@ export class ClassFile {
|
|
|
60
55
|
...Array.from(new Set(this.methods.map((m) => m.return_resource.replace(/^List\[/, "").replace(/\]$/, "")))),
|
|
61
56
|
].filter((classInstance) => classInstance !== "");
|
|
62
57
|
const has_child_classes = this.child_class_identifiers.length > 0;
|
|
63
|
-
const
|
|
58
|
+
const should_import_resolve_action_attempt = this.methods.some(({ return_resource }) => return_resource === "ActionAttempt");
|
|
64
59
|
return [
|
|
65
|
-
`from
|
|
66
|
-
`from
|
|
60
|
+
`from typing import Optional, Any, List, Dict, Union`,
|
|
61
|
+
`from ..client import SeamHttpClient`,
|
|
62
|
+
`from .models import (${validClasses
|
|
67
63
|
.filter((cls) => cls !== "None")
|
|
68
64
|
.join(",")})`,
|
|
69
|
-
`from typing import Optional, Any, List, Dict, Union`,
|
|
70
65
|
`${has_child_classes
|
|
71
66
|
? this.child_class_identifiers
|
|
72
|
-
.map((i) => `from
|
|
67
|
+
.map((i) => `from .${this.namespace}_${i.namespace} import ${i.class_name}`)
|
|
73
68
|
.join("\n")
|
|
74
69
|
: ""}`,
|
|
75
|
-
`${
|
|
76
|
-
|
|
77
|
-
|
|
70
|
+
`${should_import_resolve_action_attempt
|
|
71
|
+
? "from ..modules.action_attempts import resolve_action_attempt"
|
|
72
|
+
: ""}`,
|
|
78
73
|
"",
|
|
79
74
|
`class ${this.name}(Abstract${this.name}):`,
|
|
80
75
|
// TODO DOCSTRING
|
|
81
|
-
`
|
|
82
|
-
|
|
83
|
-
`
|
|
84
|
-
` self.seam = seam`,
|
|
76
|
+
` def __init__(self, client: SeamHttpClient, defaults: Dict[str, Any]):`,
|
|
77
|
+
` self.client = client`,
|
|
78
|
+
` self.defaults = defaults`,
|
|
85
79
|
`${has_child_classes
|
|
86
80
|
? this.child_class_identifiers
|
|
87
|
-
.map((i) => ` self._${i.namespace} = ${i.class_name}(
|
|
81
|
+
.map((i) => ` self._${i.namespace} = ${i.class_name}(client=client, defaults = defaults)`)
|
|
88
82
|
.join("\n")
|
|
89
83
|
: ""}`,
|
|
90
84
|
"",
|
|
@@ -125,17 +119,24 @@ export class ClassFile {
|
|
|
125
119
|
"",
|
|
126
120
|
...parameters.map(({ name }) => ` if ${name} is not None:\n json_payload["${name}"] = ${name}`),
|
|
127
121
|
"",
|
|
128
|
-
` ${is_none_return_type ? "" : "res = "}self.
|
|
122
|
+
` ${is_none_return_type ? "" : "res = "}self.client.post(`,
|
|
129
123
|
` "${path}",`,
|
|
130
124
|
` json=json_payload`,
|
|
131
125
|
` )`,
|
|
132
126
|
"",
|
|
133
127
|
can_method_poll_action_attempt
|
|
134
128
|
? [
|
|
135
|
-
"
|
|
136
|
-
|
|
137
|
-
|
|
129
|
+
" wait_for_action_attempt = (",
|
|
130
|
+
" self.defaults.get('wait_for_action_attempt')",
|
|
131
|
+
" if wait_for_action_attempt is None",
|
|
132
|
+
" else wait_for_action_attempt",
|
|
138
133
|
" )",
|
|
134
|
+
"",
|
|
135
|
+
" return resolve_action_attempt(",
|
|
136
|
+
` client=self.client,`,
|
|
137
|
+
` action_attempt=ActionAttempt.from_dict(res["action_attempt"]),`,
|
|
138
|
+
` wait_for_action_attempt=wait_for_action_attempt`,
|
|
139
|
+
" )",
|
|
139
140
|
].join("\n")
|
|
140
141
|
: "",
|
|
141
142
|
"",
|
|
@@ -150,7 +151,6 @@ export class ClassFile {
|
|
|
150
151
|
.map((s) => ` ${s}`)
|
|
151
152
|
.join("\n");
|
|
152
153
|
}),
|
|
153
|
-
is_action_attempt_class ? action_attempt_utils_definitions : "",
|
|
154
154
|
].join("\n");
|
|
155
155
|
}
|
|
156
156
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"class-file.js","sourceRoot":"","sources":["../../src/lib/generate-python-sdk/class-file.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"class-file.js","sourceRoot":"","sources":["../../src/lib/generate-python-sdk/class-file.ts"],"names":[],"mappings":"AA6BA,MAAM,OAAO,SAAS;IAMpB,YACE,IAAY,EACZ,SAA6B,EAC7B,uBAA+C;QAE/C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;QAC1B,IAAI,CAAC,OAAO,GAAG,EAAE,CAAA;QACjB,IAAI,CAAC,uBAAuB,GAAG,uBAAuB,CAAA;IACxD,CAAC;IAED,SAAS,CAAC,MAAuB;QAC/B,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IAC3B,CAAC;IAED,sCAAsC;QACpC,MAAM,iBAAiB,GAAG,IAAI,CAAC,uBAAuB,CAAC,MAAM,GAAG,CAAC,CAAA;QAEjE,OAAO;YACL,iBAAiB,IAAI,CAAC,IAAI,YAAY;YACtC,IAAI,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE;YAC/D,GACE,iBAAiB;gBACf,CAAC,CAAC,IAAI,CAA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4BACE,+BAA+B;4BAC/B,kDAAkD;4BAClD,wCAAwC;4BACxC,kCAAkC;4BAClC,KAAK;4BACL,EAAE;4BACF,oCAAoC;4BACpC,2BAA2B;4BAC3B,sEAAsE;4BACtE,uDAAuD;4BACvD,OAAO;yBACR,CAAC,IAAI,CAAC,IAAI,CAAC;wBACd,CAAC,CAAC,EAAE;oBACN,EAAE;oBAEF,CAAC,8BAA8B;wBAC7B,CAAC,CAAC,mBAAmB;4BACnB,CAAC,CAAC,eAAe;4BACjB,CAAC,CAAC,uBAAuB;gCACzB,CAAC,CAAC,aAAa,oBAAoB,qCAAqC,WAAW,CAAC,IAAI,CACpF,MAAM,CACP,KAAK;gCACR,CAAC,CAAC,YAAY,eAAe,mBAAmB,WAAW,CAAC,IAAI,CAC5D,MAAM,CACP,KAAK;wBACV,CAAC,CAAC,EAAE;iBACP;qBACE,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC;qBACpB,IAAI,CAAC,IAAI,CAAC,CAAA;YACf,CAAC,CACF;SACF,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACd,CAAC;CACF"}
|
|
@@ -3,7 +3,6 @@ import { pascalCase } from "change-case";
|
|
|
3
3
|
import { flattenObjSchema } from "../../lib/openapi/index.js";
|
|
4
4
|
import routesPyTemplate from "./templates/routes.py.template.js";
|
|
5
5
|
import { mapPythonType } from "./map-python-type.js";
|
|
6
|
-
import deepAttrDictPyTemplate from "./templates/utils/deep_attr_dict.py.template.js";
|
|
7
6
|
import abstractRoutesTemplate from "./templates/abstract-routes.template.js";
|
|
8
7
|
import resourceDataclassTemplate from "./templates/resource-dataclass.template.js";
|
|
9
8
|
import { getParameterAndResponseSchema } from "../../lib/openapi/get-parameter-and-response-schema.js";
|
|
@@ -93,12 +92,12 @@ export const generatePythonSDK = async (options = {}) => {
|
|
|
93
92
|
for (const [_, cls] of Object.entries(class_map)) {
|
|
94
93
|
fs[`seam/routes/${cls.namespace}.py`] = cls.serializeToClass();
|
|
95
94
|
}
|
|
96
|
-
fs[`seam/routes/
|
|
95
|
+
fs[`seam/routes/models.py`] = [
|
|
97
96
|
`from typing import Any, Dict, List, Optional, Union`,
|
|
98
97
|
`from typing_extensions import Self`,
|
|
99
98
|
`import abc`,
|
|
100
99
|
`from dataclasses import dataclass`,
|
|
101
|
-
`from
|
|
100
|
+
`from ..utils.deep_attr_dict import DeepAttrDict`,
|
|
102
101
|
"",
|
|
103
102
|
"",
|
|
104
103
|
...Object.entries(openapi.components.schemas)
|
|
@@ -118,8 +117,7 @@ export const generatePythonSDK = async (options = {}) => {
|
|
|
118
117
|
"",
|
|
119
118
|
abstractRoutesTemplate(top_level_namespaces),
|
|
120
119
|
].join("\n");
|
|
121
|
-
fs["seam/routes/
|
|
122
|
-
fs["seam/routes/utils/deep_attr_dict.py"] = deepAttrDictPyTemplate();
|
|
120
|
+
fs["seam/routes/__init__.py"] = routesPyTemplate(top_level_namespaces);
|
|
123
121
|
return fs;
|
|
124
122
|
};
|
|
125
123
|
function determineReturnResource({ route_path, response_arr_type, response_obj_type, }) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-python-sdk.js","sourceRoot":"","sources":["../../src/lib/generate-python-sdk/generate-python-sdk.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,gBAAgB,MAAM,mCAAmC,CAAA;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACpD,OAAO,sBAAsB,MAAM,
|
|
1
|
+
{"version":3,"file":"generate-python-sdk.js","sourceRoot":"","sources":["../../src/lib/generate-python-sdk/generate-python-sdk.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3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I,EAAE,aAAa,CAAC,eAAsB,CAAC;SAC5C,CAAC,CAAC,CACJ,CACF;QACH,EAAE;QACF,EAAE;QACF,GAAG,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC;aACzB,IAAI;QACH,qEAAqE;QACrE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CACf,CAAC,CAAC,uBAAuB,CAAC,MAAM,GAAG,CAAC,CAAC,uBAAuB,CAAC,MAAM,CACtE;aACA,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,sCAAsC,EAAE,CAAC;QAClE,EAAE;QACF,EAAE;QACF,sBAAsB,CAAC,oBAAoB,CAAC;KAC7C,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAEZ,EAAE,CAAC,yBAAyB,CAAC,GAAG,gBAAgB,CAAC,oBAAoB,CAAC,CAAA;IAEtE,OAAO,EAAE,CAAA;AACX,CAAC,CAAA;AAED,SAAS,uBAAuB,CAAC,EAC/B,UAAU,EACV,iBAAiB,EACjB,iBAAiB,GAKlB;IACC,IAAI,6CAA6C,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE;QACtE,OAAO,MAAM,CAAA;KACd;IAED,IAAI,iBAAiB,EAAE;QACrB,OAAO,UAAU,CAAC,iBAAiB,CAAC,CAAA;KACrC;IAED,IAAI,iBAAiB,EAAE;QACrB,OAAO,QAAQ,UAAU,CAAC,iBAAiB,CAAC,GAAG,CAAA;KAChD;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { pascalCase } from "change-case";
|
|
2
2
|
export default (namespaces) => [
|
|
3
|
-
`from
|
|
3
|
+
`from typing import Any, Dict`,
|
|
4
|
+
`from ..client import SeamHttpClient`,
|
|
5
|
+
`from .models import AbstractRoutes`,
|
|
4
6
|
...namespaces.map((ns) => `from .${ns} import ${pascalCase(ns)}`),
|
|
5
7
|
``,
|
|
6
8
|
`class Routes(AbstractRoutes):`,
|
|
7
|
-
` def __init__(self):`,
|
|
8
|
-
...namespaces.map((ns) => ` self.${ns} = ${pascalCase(ns)}(
|
|
9
|
+
` def __init__(self, client: SeamHttpClient, defaults: Dict[str, Any]):`,
|
|
10
|
+
...namespaces.map((ns) => ` self.${ns} = ${pascalCase(ns)}(client=client, defaults=defaults)`),
|
|
9
11
|
].join("\n");
|
|
10
12
|
//# sourceMappingURL=routes.py.template.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes.py.template.js","sourceRoot":"","sources":["../../../src/lib/generate-python-sdk/templates/routes.py.template.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,eAAe,CAAC,UAAoB,EAAE,EAAE,CACtC;IACE,
|
|
1
|
+
{"version":3,"file":"routes.py.template.js","sourceRoot":"","sources":["../../../src/lib/generate-python-sdk/templates/routes.py.template.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,eAAe,CAAC,UAAoB,EAAE,EAAE,CACtC;IACE,8BAA8B;IAC9B,qCAAqC;IACrC,oCAAoC;IACpC,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,SAAS,EAAE,WAAW,UAAU,CAAC,EAAE,CAAC,EAAE,CAAC;IACjE,EAAE;IACF,+BAA+B;IAC/B,yEAAyE;IACzE,GAAG,UAAU,CAAC,GAAG,CACf,CAAC,EAAE,EAAE,EAAE,CACL,YAAY,EAAE,MAAM,UAAU,CAAC,EAAE,CAAC,oCAAoC,CACzE;CACF,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
action_attempt_imports,
|
|
3
|
-
action_attempt_utils_definitions,
|
|
4
|
-
action_attempt_utils_specs,
|
|
5
|
-
action_attempt_error_definitions,
|
|
6
|
-
} from "./templates/utils/action-attempt.js"
|
|
7
|
-
|
|
8
1
|
export type ClassFileMethodBase = {
|
|
9
2
|
method_name: string
|
|
10
3
|
path: string
|
|
@@ -60,7 +53,7 @@ export class ClassFile {
|
|
|
60
53
|
|
|
61
54
|
return [
|
|
62
55
|
`class Abstract${this.name}(abc.ABC):`,
|
|
63
|
-
this.methods.length === 0 ? ` pass` : "",
|
|
56
|
+
this.methods.length === 0 && !has_child_classes ? ` pass` : "",
|
|
64
57
|
`${
|
|
65
58
|
has_child_classes
|
|
66
59
|
? this.child_class_identifiers
|
|
@@ -75,46 +68,39 @@ export class ClassFile {
|
|
|
75
68
|
.join("\n\n")
|
|
76
69
|
: ""
|
|
77
70
|
}`,
|
|
78
|
-
...this.methods
|
|
79
|
-
.
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
.map(({ method_name, parameters, return_resource }) => {
|
|
83
|
-
const has_params = parameters.length > 0
|
|
84
|
-
const action_attempt_util_method_names =
|
|
85
|
-
action_attempt_utils_specs.map((item) => item.method_name)
|
|
86
|
-
const can_method_poll_action_attempt =
|
|
87
|
-
return_resource === "ActionAttempt" &&
|
|
88
|
-
!action_attempt_util_method_names.includes(method_name)
|
|
71
|
+
...this.methods.map(({ method_name, parameters, return_resource }) => {
|
|
72
|
+
const has_params = parameters.length > 0
|
|
73
|
+
const can_method_poll_action_attempt =
|
|
74
|
+
return_resource === "ActionAttempt"
|
|
89
75
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
76
|
+
return [
|
|
77
|
+
"",
|
|
78
|
+
"",
|
|
79
|
+
`@abc.abstractmethod`,
|
|
80
|
+
`def ${method_name}(self,${has_params ? " *," : ""} ${parameters
|
|
81
|
+
.sort(
|
|
82
|
+
(a, b) =>
|
|
83
|
+
(a.position ?? a.required ? 1000 : 9999) -
|
|
84
|
+
(b.position ?? b.required ? 1000 : 9999)
|
|
85
|
+
)
|
|
86
|
+
.map(({ name, type, required, default_value }) =>
|
|
87
|
+
required
|
|
88
|
+
? `${name}: ${type}`
|
|
89
|
+
: `${name}: Optional[${type}] = ${default_value ?? "None"}`
|
|
90
|
+
)
|
|
91
|
+
.concat(
|
|
92
|
+
can_method_poll_action_attempt
|
|
93
|
+
? [
|
|
94
|
+
"wait_for_action_attempt: Optional[Union[bool, Dict[str, float]]] = None",
|
|
95
|
+
]
|
|
96
|
+
: []
|
|
97
|
+
)
|
|
98
|
+
.join(", ")}) -> ${return_resource}:`,
|
|
99
|
+
` raise NotImplementedError()`,
|
|
100
|
+
]
|
|
101
|
+
.map((s) => ` ${s}`)
|
|
102
|
+
.join("\n")
|
|
103
|
+
}),
|
|
118
104
|
].join("\n")
|
|
119
105
|
}
|
|
120
106
|
|
|
@@ -130,39 +116,43 @@ export class ClassFile {
|
|
|
130
116
|
),
|
|
131
117
|
].filter((classInstance) => classInstance !== "")
|
|
132
118
|
const has_child_classes = this.child_class_identifiers.length > 0
|
|
133
|
-
const
|
|
119
|
+
const should_import_resolve_action_attempt = this.methods.some(
|
|
120
|
+
({ return_resource }) => return_resource === "ActionAttempt"
|
|
121
|
+
)
|
|
134
122
|
|
|
135
123
|
return [
|
|
136
|
-
`from
|
|
137
|
-
`from
|
|
124
|
+
`from typing import Optional, Any, List, Dict, Union`,
|
|
125
|
+
`from ..client import SeamHttpClient`,
|
|
126
|
+
`from .models import (${validClasses
|
|
138
127
|
.filter((cls) => cls !== "None")
|
|
139
128
|
.join(",")})`,
|
|
140
|
-
`from typing import Optional, Any, List, Dict, Union`,
|
|
141
129
|
`${
|
|
142
130
|
has_child_classes
|
|
143
131
|
? this.child_class_identifiers
|
|
144
132
|
.map(
|
|
145
133
|
(i) =>
|
|
146
|
-
`from
|
|
134
|
+
`from .${this.namespace}_${i.namespace} import ${i.class_name}`
|
|
147
135
|
)
|
|
148
136
|
.join("\n")
|
|
149
137
|
: ""
|
|
150
138
|
}`,
|
|
151
|
-
`${
|
|
152
|
-
|
|
153
|
-
|
|
139
|
+
`${
|
|
140
|
+
should_import_resolve_action_attempt
|
|
141
|
+
? "from ..modules.action_attempts import resolve_action_attempt"
|
|
142
|
+
: ""
|
|
143
|
+
}`,
|
|
154
144
|
"",
|
|
155
145
|
`class ${this.name}(Abstract${this.name}):`,
|
|
156
146
|
// TODO DOCSTRING
|
|
157
|
-
`
|
|
158
|
-
|
|
159
|
-
`
|
|
160
|
-
` self.seam = seam`,
|
|
147
|
+
` def __init__(self, client: SeamHttpClient, defaults: Dict[str, Any]):`,
|
|
148
|
+
` self.client = client`,
|
|
149
|
+
` self.defaults = defaults`,
|
|
161
150
|
`${
|
|
162
151
|
has_child_classes
|
|
163
152
|
? this.child_class_identifiers
|
|
164
153
|
.map(
|
|
165
|
-
(i) =>
|
|
154
|
+
(i) =>
|
|
155
|
+
` self._${i.namespace} = ${i.class_name}(client=client, defaults = defaults)`
|
|
166
156
|
)
|
|
167
157
|
.join("\n")
|
|
168
158
|
: ""
|
|
@@ -228,7 +218,7 @@ export class ClassFile {
|
|
|
228
218
|
),
|
|
229
219
|
"",
|
|
230
220
|
|
|
231
|
-
` ${is_none_return_type ? "" : "res = "}self.
|
|
221
|
+
` ${is_none_return_type ? "" : "res = "}self.client.post(`,
|
|
232
222
|
` "${path}",`,
|
|
233
223
|
` json=json_payload`,
|
|
234
224
|
` )`,
|
|
@@ -236,10 +226,17 @@ export class ClassFile {
|
|
|
236
226
|
|
|
237
227
|
can_method_poll_action_attempt
|
|
238
228
|
? [
|
|
239
|
-
"
|
|
240
|
-
|
|
241
|
-
|
|
229
|
+
" wait_for_action_attempt = (",
|
|
230
|
+
" self.defaults.get('wait_for_action_attempt')",
|
|
231
|
+
" if wait_for_action_attempt is None",
|
|
232
|
+
" else wait_for_action_attempt",
|
|
242
233
|
" )",
|
|
234
|
+
"",
|
|
235
|
+
" return resolve_action_attempt(",
|
|
236
|
+
` client=self.client,`,
|
|
237
|
+
` action_attempt=ActionAttempt.from_dict(res["action_attempt"]),`,
|
|
238
|
+
` wait_for_action_attempt=wait_for_action_attempt`,
|
|
239
|
+
" )",
|
|
243
240
|
].join("\n")
|
|
244
241
|
: "",
|
|
245
242
|
"",
|
|
@@ -260,7 +257,6 @@ export class ClassFile {
|
|
|
260
257
|
.join("\n")
|
|
261
258
|
}
|
|
262
259
|
),
|
|
263
|
-
is_action_attempt_class ? action_attempt_utils_definitions : "",
|
|
264
260
|
].join("\n")
|
|
265
261
|
}
|
|
266
262
|
}
|
|
@@ -4,7 +4,6 @@ import { pascalCase } from "change-case"
|
|
|
4
4
|
import { flattenObjSchema } from "lib/openapi/index.js"
|
|
5
5
|
import routesPyTemplate from "./templates/routes.py.template.js"
|
|
6
6
|
import { mapPythonType } from "./map-python-type.js"
|
|
7
|
-
import deepAttrDictPyTemplate from "./templates/utils/deep_attr_dict.py.template.js"
|
|
8
7
|
import abstractRoutesTemplate from "./templates/abstract-routes.template.js"
|
|
9
8
|
import resourceDataclassTemplate from "./templates/resource-dataclass.template.js"
|
|
10
9
|
import { getParameterAndResponseSchema } from "lib/openapi/get-parameter-and-response-schema.js"
|
|
@@ -125,12 +124,12 @@ export const generatePythonSDK = async (options: SdkGeneratorOptions = {}) => {
|
|
|
125
124
|
fs[`seam/routes/${cls.namespace}.py`] = cls.serializeToClass()
|
|
126
125
|
}
|
|
127
126
|
|
|
128
|
-
fs[`seam/routes/
|
|
127
|
+
fs[`seam/routes/models.py`] = [
|
|
129
128
|
`from typing import Any, Dict, List, Optional, Union`,
|
|
130
129
|
`from typing_extensions import Self`,
|
|
131
130
|
`import abc`,
|
|
132
131
|
`from dataclasses import dataclass`,
|
|
133
|
-
`from
|
|
132
|
+
`from ..utils.deep_attr_dict import DeepAttrDict`,
|
|
134
133
|
"",
|
|
135
134
|
"",
|
|
136
135
|
...Object.entries(openapi.components.schemas)
|
|
@@ -161,8 +160,7 @@ export const generatePythonSDK = async (options: SdkGeneratorOptions = {}) => {
|
|
|
161
160
|
abstractRoutesTemplate(top_level_namespaces),
|
|
162
161
|
].join("\n")
|
|
163
162
|
|
|
164
|
-
fs["seam/routes/
|
|
165
|
-
fs["seam/routes/utils/deep_attr_dict.py"] = deepAttrDictPyTemplate()
|
|
163
|
+
fs["seam/routes/__init__.py"] = routesPyTemplate(top_level_namespaces)
|
|
166
164
|
|
|
167
165
|
return fs
|
|
168
166
|
}
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { pascalCase } from "change-case"
|
|
2
2
|
export default (namespaces: string[]) =>
|
|
3
3
|
[
|
|
4
|
-
`from
|
|
4
|
+
`from typing import Any, Dict`,
|
|
5
|
+
`from ..client import SeamHttpClient`,
|
|
6
|
+
`from .models import AbstractRoutes`,
|
|
5
7
|
...namespaces.map((ns) => `from .${ns} import ${pascalCase(ns)}`),
|
|
6
8
|
``,
|
|
7
9
|
`class Routes(AbstractRoutes):`,
|
|
8
|
-
` def __init__(self):`,
|
|
9
|
-
...namespaces.map(
|
|
10
|
+
` def __init__(self, client: SeamHttpClient, defaults: Dict[str, Any]):`,
|
|
11
|
+
...namespaces.map(
|
|
12
|
+
(ns) =>
|
|
13
|
+
` self.${ns} = ${pascalCase(ns)}(client=client, defaults=defaults)`
|
|
14
|
+
),
|
|
10
15
|
].join("\n")
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export declare const action_attempt_utils_specs: {
|
|
2
|
-
method_name: string;
|
|
3
|
-
parameters: ({
|
|
4
|
-
name: string;
|
|
5
|
-
type: string;
|
|
6
|
-
required: boolean;
|
|
7
|
-
default_value?: never;
|
|
8
|
-
} | {
|
|
9
|
-
name: string;
|
|
10
|
-
type: string;
|
|
11
|
-
default_value: string;
|
|
12
|
-
required?: never;
|
|
13
|
-
})[];
|
|
14
|
-
return_path: never[];
|
|
15
|
-
return_resource: string;
|
|
16
|
-
path: string;
|
|
17
|
-
}[];
|
|
18
|
-
export declare const action_attempt_utils_definitions: string;
|
|
19
|
-
export declare const action_attempt_imports = "import time\n";
|
|
20
|
-
export declare const action_attempt_error_definitions = "class SeamActionAttemptError(Exception):\n def __init__(self, message: str, action_attempt: ActionAttempt):\n super().__init__(message)\n self.name = self.__class__.__name__\n self.action_attempt = action_attempt\n\n\nclass SeamActionAttemptFailedError(SeamActionAttemptError):\n def __init__(self, action_attempt: ActionAttempt):\n super().__init__(action_attempt.error.message, action_attempt)\n self.name = self.__class__.__name__\n self.code = action_attempt.error.type\n\n\nclass SeamActionAttemptTimeoutError(SeamActionAttemptError):\n def __init__(self, action_attempt: ActionAttempt, timeout: str):\n message = f\"Timed out waiting for action attempt after {timeout}s\"\n super().__init__(message, action_attempt)\n self.name = self.__class__.__name__\n";
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
export const action_attempt_utils_specs = [
|
|
2
|
-
{
|
|
3
|
-
method_name: "poll_until_ready",
|
|
4
|
-
parameters: [
|
|
5
|
-
{ name: "action_attempt_id", type: "str", required: true },
|
|
6
|
-
{ name: "timeout", type: "float", default_value: "5.0" },
|
|
7
|
-
{
|
|
8
|
-
name: "polling_interval",
|
|
9
|
-
type: "float",
|
|
10
|
-
default_value: "0.5",
|
|
11
|
-
},
|
|
12
|
-
],
|
|
13
|
-
return_path: [],
|
|
14
|
-
return_resource: "ActionAttempt",
|
|
15
|
-
path: "",
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
method_name: "decide_and_wait",
|
|
19
|
-
parameters: [
|
|
20
|
-
{
|
|
21
|
-
name: "action_attempt",
|
|
22
|
-
type: "ActionAttempt",
|
|
23
|
-
required: true,
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
name: "wait_for_action_attempt",
|
|
27
|
-
type: "Union[bool, Dict[str, float]]",
|
|
28
|
-
required: true,
|
|
29
|
-
},
|
|
30
|
-
],
|
|
31
|
-
return_path: [],
|
|
32
|
-
return_resource: "ActionAttempt",
|
|
33
|
-
path: "",
|
|
34
|
-
},
|
|
35
|
-
];
|
|
36
|
-
export const action_attempt_utils_definitions = [
|
|
37
|
-
"",
|
|
38
|
-
" def poll_until_ready(self, *, action_attempt_id: str, timeout: Optional[float] = 5.0, polling_interval: Optional[float] = 0.5) -> ActionAttempt:",
|
|
39
|
-
" seam = self.seam",
|
|
40
|
-
" time_waiting = 0.0",
|
|
41
|
-
"",
|
|
42
|
-
" action_attempt = seam.action_attempts.get(action_attempt_id=action_attempt_id, wait_for_action_attempt=False)",
|
|
43
|
-
"",
|
|
44
|
-
" while action_attempt.status == 'pending':",
|
|
45
|
-
" time.sleep(polling_interval)",
|
|
46
|
-
" time_waiting += polling_interval",
|
|
47
|
-
"",
|
|
48
|
-
" if time_waiting > timeout:",
|
|
49
|
-
" raise SeamActionAttemptTimeoutError(action_attempt, timeout)",
|
|
50
|
-
"",
|
|
51
|
-
" action_attempt = seam.action_attempts.get(",
|
|
52
|
-
" action_attempt_id=action_attempt.action_attempt_id, wait_for_action_attempt=False",
|
|
53
|
-
" )",
|
|
54
|
-
"",
|
|
55
|
-
" if action_attempt.status == 'failed':",
|
|
56
|
-
" raise SeamActionAttemptFailedError(action_attempt)",
|
|
57
|
-
"",
|
|
58
|
-
" return action_attempt",
|
|
59
|
-
"",
|
|
60
|
-
" def decide_and_wait(self, *, action_attempt: ActionAttempt, wait_for_action_attempt: Optional[Union[bool, Dict[str, float]]] = None) -> ActionAttempt:",
|
|
61
|
-
" wait_decision = self.seam.wait_for_action_attempt if wait_for_action_attempt is None else wait_for_action_attempt",
|
|
62
|
-
"",
|
|
63
|
-
" if wait_decision is True:",
|
|
64
|
-
" return self.seam.action_attempts.poll_until_ready(action_attempt_id=action_attempt.action_attempt_id)",
|
|
65
|
-
" if isinstance(wait_decision, dict):",
|
|
66
|
-
" return self.seam.action_attempts.poll_until_ready(action_attempt_id=action_attempt.action_attempt_id, timeout=wait_decision.get('timeout', None), polling_interval=wait_decision.get('polling_interval', None))",
|
|
67
|
-
"",
|
|
68
|
-
" return action_attempt",
|
|
69
|
-
].join("\n");
|
|
70
|
-
export const action_attempt_imports = `import time\n`;
|
|
71
|
-
export const action_attempt_error_definitions = `class SeamActionAttemptError(Exception):
|
|
72
|
-
def __init__(self, message: str, action_attempt: ActionAttempt):
|
|
73
|
-
super().__init__(message)
|
|
74
|
-
self.name = self.__class__.__name__
|
|
75
|
-
self.action_attempt = action_attempt
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
class SeamActionAttemptFailedError(SeamActionAttemptError):
|
|
79
|
-
def __init__(self, action_attempt: ActionAttempt):
|
|
80
|
-
super().__init__(action_attempt.error.message, action_attempt)
|
|
81
|
-
self.name = self.__class__.__name__
|
|
82
|
-
self.code = action_attempt.error.type
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
class SeamActionAttemptTimeoutError(SeamActionAttemptError):
|
|
86
|
-
def __init__(self, action_attempt: ActionAttempt, timeout: str):
|
|
87
|
-
message = f"Timed out waiting for action attempt after {timeout}s"
|
|
88
|
-
super().__init__(message, action_attempt)
|
|
89
|
-
self.name = self.__class__.__name__
|
|
90
|
-
`;
|
|
91
|
-
//# sourceMappingURL=action-attempt.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"action-attempt.js","sourceRoot":"","sources":["../../../../src/lib/generate-python-sdk/templates/utils/action-attempt.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,0BAA0B,GAAG;IACxC;QACE,WAAW,EAAE,kBAAkB;QAC/B,UAAU,EAAE;YACV,EAAE,IAAI,EAAE,mBAAmB,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAA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 +0,0 @@
|
|
|
1
|
-
export default () => `# https://stackoverflow.com/a/3031270/559475
|
|
2
|
-
class DeepAttrDict(dict):
|
|
3
|
-
MARKER = object()
|
|
4
|
-
|
|
5
|
-
def __init__(self, value=None):
|
|
6
|
-
if value is None:
|
|
7
|
-
pass
|
|
8
|
-
elif isinstance(value, dict):
|
|
9
|
-
for key in value:
|
|
10
|
-
self.__setitem__(key, value[key])
|
|
11
|
-
else:
|
|
12
|
-
raise TypeError("expected dict")
|
|
13
|
-
|
|
14
|
-
def __setitem__(self, key, value):
|
|
15
|
-
if isinstance(value, dict) and not isinstance(value, DeepAttrDict):
|
|
16
|
-
value = DeepAttrDict(value)
|
|
17
|
-
super(DeepAttrDict, self).__setitem__(key, value)
|
|
18
|
-
|
|
19
|
-
def __getitem__(self, key):
|
|
20
|
-
found = self.get(key, DeepAttrDict.MARKER)
|
|
21
|
-
if found is DeepAttrDict.MARKER:
|
|
22
|
-
found = DeepAttrDict()
|
|
23
|
-
super(DeepAttrDict, self).__setitem__(key, found)
|
|
24
|
-
return found
|
|
25
|
-
|
|
26
|
-
__setattr__, __getattr__ = __setitem__, __getitem__
|
|
27
|
-
`;
|
|
28
|
-
//# sourceMappingURL=deep_attr_dict.py.template.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"deep_attr_dict.py.template.js","sourceRoot":"","sources":["../../../../src/lib/generate-python-sdk/templates/utils/deep_attr_dict.py.template.ts"],"names":[],"mappings":"AAAA,eAAe,GAAG,EAAE,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;CA0BpB,CAAA"}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
export const action_attempt_utils_specs = [
|
|
2
|
-
{
|
|
3
|
-
method_name: "poll_until_ready",
|
|
4
|
-
parameters: [
|
|
5
|
-
{ name: "action_attempt_id", type: "str", required: true },
|
|
6
|
-
{ name: "timeout", type: "float", default_value: "5.0" },
|
|
7
|
-
{
|
|
8
|
-
name: "polling_interval",
|
|
9
|
-
type: "float",
|
|
10
|
-
default_value: "0.5",
|
|
11
|
-
},
|
|
12
|
-
],
|
|
13
|
-
return_path: [],
|
|
14
|
-
return_resource: "ActionAttempt",
|
|
15
|
-
path: "",
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
method_name: "decide_and_wait",
|
|
19
|
-
parameters: [
|
|
20
|
-
{
|
|
21
|
-
name: "action_attempt",
|
|
22
|
-
type: "ActionAttempt",
|
|
23
|
-
required: true,
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
name: "wait_for_action_attempt",
|
|
27
|
-
type: "Union[bool, Dict[str, float]]",
|
|
28
|
-
required: true,
|
|
29
|
-
},
|
|
30
|
-
],
|
|
31
|
-
return_path: [],
|
|
32
|
-
return_resource: "ActionAttempt",
|
|
33
|
-
path: "",
|
|
34
|
-
},
|
|
35
|
-
]
|
|
36
|
-
|
|
37
|
-
export const action_attempt_utils_definitions = [
|
|
38
|
-
"",
|
|
39
|
-
" def poll_until_ready(self, *, action_attempt_id: str, timeout: Optional[float] = 5.0, polling_interval: Optional[float] = 0.5) -> ActionAttempt:",
|
|
40
|
-
" seam = self.seam",
|
|
41
|
-
" time_waiting = 0.0",
|
|
42
|
-
"",
|
|
43
|
-
" action_attempt = seam.action_attempts.get(action_attempt_id=action_attempt_id, wait_for_action_attempt=False)",
|
|
44
|
-
"",
|
|
45
|
-
" while action_attempt.status == 'pending':",
|
|
46
|
-
" time.sleep(polling_interval)",
|
|
47
|
-
" time_waiting += polling_interval",
|
|
48
|
-
"",
|
|
49
|
-
" if time_waiting > timeout:",
|
|
50
|
-
" raise SeamActionAttemptTimeoutError(action_attempt, timeout)",
|
|
51
|
-
"",
|
|
52
|
-
" action_attempt = seam.action_attempts.get(",
|
|
53
|
-
" action_attempt_id=action_attempt.action_attempt_id, wait_for_action_attempt=False",
|
|
54
|
-
" )",
|
|
55
|
-
"",
|
|
56
|
-
" if action_attempt.status == 'failed':",
|
|
57
|
-
" raise SeamActionAttemptFailedError(action_attempt)",
|
|
58
|
-
"",
|
|
59
|
-
" return action_attempt",
|
|
60
|
-
"",
|
|
61
|
-
" def decide_and_wait(self, *, action_attempt: ActionAttempt, wait_for_action_attempt: Optional[Union[bool, Dict[str, float]]] = None) -> ActionAttempt:",
|
|
62
|
-
" wait_decision = self.seam.wait_for_action_attempt if wait_for_action_attempt is None else wait_for_action_attempt",
|
|
63
|
-
"",
|
|
64
|
-
" if wait_decision is True:",
|
|
65
|
-
" return self.seam.action_attempts.poll_until_ready(action_attempt_id=action_attempt.action_attempt_id)",
|
|
66
|
-
" if isinstance(wait_decision, dict):",
|
|
67
|
-
" return self.seam.action_attempts.poll_until_ready(action_attempt_id=action_attempt.action_attempt_id, timeout=wait_decision.get('timeout', None), polling_interval=wait_decision.get('polling_interval', None))",
|
|
68
|
-
"",
|
|
69
|
-
" return action_attempt",
|
|
70
|
-
].join("\n")
|
|
71
|
-
|
|
72
|
-
export const action_attempt_imports = `import time\n`
|
|
73
|
-
|
|
74
|
-
export const action_attempt_error_definitions = `class SeamActionAttemptError(Exception):
|
|
75
|
-
def __init__(self, message: str, action_attempt: ActionAttempt):
|
|
76
|
-
super().__init__(message)
|
|
77
|
-
self.name = self.__class__.__name__
|
|
78
|
-
self.action_attempt = action_attempt
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
class SeamActionAttemptFailedError(SeamActionAttemptError):
|
|
82
|
-
def __init__(self, action_attempt: ActionAttempt):
|
|
83
|
-
super().__init__(action_attempt.error.message, action_attempt)
|
|
84
|
-
self.name = self.__class__.__name__
|
|
85
|
-
self.code = action_attempt.error.type
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
class SeamActionAttemptTimeoutError(SeamActionAttemptError):
|
|
89
|
-
def __init__(self, action_attempt: ActionAttempt, timeout: str):
|
|
90
|
-
message = f"Timed out waiting for action attempt after {timeout}s"
|
|
91
|
-
super().__init__(message, action_attempt)
|
|
92
|
-
self.name = self.__class__.__name__
|
|
93
|
-
`
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export default () => `# https://stackoverflow.com/a/3031270/559475
|
|
2
|
-
class DeepAttrDict(dict):
|
|
3
|
-
MARKER = object()
|
|
4
|
-
|
|
5
|
-
def __init__(self, value=None):
|
|
6
|
-
if value is None:
|
|
7
|
-
pass
|
|
8
|
-
elif isinstance(value, dict):
|
|
9
|
-
for key in value:
|
|
10
|
-
self.__setitem__(key, value[key])
|
|
11
|
-
else:
|
|
12
|
-
raise TypeError("expected dict")
|
|
13
|
-
|
|
14
|
-
def __setitem__(self, key, value):
|
|
15
|
-
if isinstance(value, dict) and not isinstance(value, DeepAttrDict):
|
|
16
|
-
value = DeepAttrDict(value)
|
|
17
|
-
super(DeepAttrDict, self).__setitem__(key, value)
|
|
18
|
-
|
|
19
|
-
def __getitem__(self, key):
|
|
20
|
-
found = self.get(key, DeepAttrDict.MARKER)
|
|
21
|
-
if found is DeepAttrDict.MARKER:
|
|
22
|
-
found = DeepAttrDict()
|
|
23
|
-
super(DeepAttrDict, self).__setitem__(key, found)
|
|
24
|
-
return found
|
|
25
|
-
|
|
26
|
-
__setattr__, __getattr__ = __setitem__, __getitem__
|
|
27
|
-
`
|