crankscript 0.9.5 → 0.9.7

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.
@@ -0,0 +1,4 @@
1
+ {
2
+ "name": "assets",
3
+ "module": "commonjs"
4
+ }
@@ -0,0 +1,204 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var _a;
26
+ Object.defineProperty(exports, "__esModule", { value: true });
27
+ exports.transformSuperExpression = exports.transformClassDeclaration = void 0;
28
+ exports.transformPropertyName = transformPropertyName;
29
+ var ts = __importStar(require("typescript"));
30
+ var tstl = __importStar(require("typescript-to-lua"));
31
+ var lua = __importStar(require("typescript-to-lua/dist/LuaAST"));
32
+ var scope_1 = require("typescript-to-lua/dist/transformation/utils/scope");
33
+ var call_1 = require("typescript-to-lua/dist/transformation/visitors/call");
34
+ var fields_1 = require("typescript-to-lua/dist/transformation/visitors/class/members/fields");
35
+ var utils_1 = require("typescript-to-lua/dist/transformation/visitors/class/utils");
36
+ var function_1 = require("typescript-to-lua/dist/transformation/visitors/function");
37
+ function createClassCall(context, className, extendsNode) {
38
+ // class('X')
39
+ var classCall = tstl.createCallExpression(tstl.createIdentifier('class'), [tstl.createStringLiteral(className.text)]);
40
+ var classCreationExpression;
41
+ if (extendsNode) {
42
+ // class('X').extends(Blah)
43
+ classCreationExpression = tstl.createCallExpression(tstl.createTableIndexExpression(classCall, tstl.createStringLiteral('extends')), [context.transformExpression(extendsNode.expression)]);
44
+ }
45
+ else {
46
+ classCreationExpression = tstl.createCallExpression(tstl.createTableIndexExpression(classCall, tstl.createStringLiteral('extends')), [tstl.createIdentifier('Object')]);
47
+ }
48
+ return tstl.createExpressionStatement(classCreationExpression);
49
+ }
50
+ function transformPropertyName(context, node) {
51
+ if (ts.isComputedPropertyName(node)) {
52
+ return context.transformExpression(node.expression);
53
+ }
54
+ else if (ts.isIdentifier(node)) {
55
+ return tstl.createStringLiteral(node.text);
56
+ }
57
+ else if (ts.isPrivateIdentifier(node)) {
58
+ throw new Error('PrivateIdentifier is not supported');
59
+ }
60
+ else {
61
+ return context.transformExpression(node);
62
+ }
63
+ }
64
+ function transformConstructor(context, className, instanceFields, constructor) {
65
+ var methodName = 'init';
66
+ context.pushScope(scope_1.ScopeType.Function);
67
+ var bodyStatements = [];
68
+ var params;
69
+ if (constructor) {
70
+ params = (0, function_1.transformParameters)(context, constructor === null || constructor === void 0 ? void 0 : constructor.parameters, tstl.createIdentifier('self'))[0];
71
+ }
72
+ else {
73
+ params = [tstl.createIdentifier('self')];
74
+ }
75
+ bodyStatements.push(tstl.createExpressionStatement(tstl.createCallExpression(tstl.createTableIndexExpression(tstl.createTableIndexExpression(className, tstl.createStringLiteral('super')), tstl.createStringLiteral('init')), params)));
76
+ var classInstanceFields = (0, fields_1.transformClassInstanceFields)(context, instanceFields);
77
+ // initializers have to come before any body of the constructor
78
+ bodyStatements.push.apply(bodyStatements, classInstanceFields);
79
+ if (constructor === null || constructor === void 0 ? void 0 : constructor.body) {
80
+ var body = (0, function_1.transformFunctionBodyContent)(context, constructor.body);
81
+ // if the first expression in the body is a super call, ignore it, because we have
82
+ // constructed our own super call.
83
+ // if it's not, make sure to include the entire body.
84
+ var firstStatement = constructor.body.statements[0];
85
+ if (firstStatement &&
86
+ ts.isExpressionStatement(firstStatement) &&
87
+ ts.isCallExpression(firstStatement.expression) &&
88
+ firstStatement.expression.expression.kind ===
89
+ ts.SyntaxKind.SuperKeyword) {
90
+ bodyStatements.push.apply(bodyStatements, body.slice(1));
91
+ }
92
+ else {
93
+ bodyStatements.push.apply(bodyStatements, body);
94
+ }
95
+ }
96
+ context.popScope();
97
+ return tstl.createAssignmentStatement(tstl.createTableIndexExpression(className, tstl.createStringLiteral(methodName)), tstl.createFunctionExpression(tstl.createBlock(bodyStatements), params));
98
+ }
99
+ function transformMethodDeclaration(context, node, className) {
100
+ var functionExpression = (0, function_1.transformFunctionToExpression)(context, node)[0];
101
+ return tstl.createAssignmentStatement(tstl.createTableIndexExpression(className, transformPropertyName(context, node.name)), functionExpression);
102
+ }
103
+ var transformClassDeclaration = function (declaration, context) {
104
+ var className;
105
+ if (declaration.name) {
106
+ className = tstl.createIdentifier(declaration.name.text);
107
+ }
108
+ else {
109
+ className = tstl.createIdentifier(context.createTempName('class'), declaration);
110
+ }
111
+ var extension = (0, utils_1.getExtendedNode)(declaration);
112
+ if (context.classSuperInfos) {
113
+ context.classSuperInfos.push({
114
+ className: className,
115
+ extendedTypeNode: extension,
116
+ });
117
+ }
118
+ else {
119
+ context.classSuperInfos = [{ className: className, extendedTypeNode: extension }];
120
+ }
121
+ // Get all properties with value
122
+ var properties = declaration.members
123
+ .filter(ts.isPropertyDeclaration)
124
+ .filter(function (member) { return member.initializer; });
125
+ // Divide properties into static and non-static
126
+ var instanceFields = properties.filter(function (prop) { return !(0, utils_1.isStaticNode)(prop); });
127
+ var statements = [];
128
+ // class('X')
129
+ statements.push(createClassCall(context, className, extension));
130
+ // function X:init()
131
+ // X.super.init(self)
132
+ // end
133
+ var constructor = declaration.members.find(function (n) {
134
+ return ts.isConstructorDeclaration(n) && n.body !== undefined;
135
+ });
136
+ var transformedConstructor = transformConstructor(context, className, instanceFields, constructor);
137
+ if (transformedConstructor) {
138
+ statements.push(transformedConstructor);
139
+ }
140
+ var methods = declaration.members
141
+ .filter(ts.isMethodDeclaration)
142
+ .map(function (method) { return transformMethodDeclaration(context, method, className); })
143
+ .filter(function (method) { return method !== undefined; });
144
+ statements.push.apply(statements, methods);
145
+ return statements;
146
+ };
147
+ exports.transformClassDeclaration = transformClassDeclaration;
148
+ var transformNewExpression = function (node, context) {
149
+ var _a;
150
+ var signature = context.checker.getResolvedSignature(node);
151
+ var _b = (0, call_1.transformCallAndArguments)(context, node.expression, (_a = node.arguments) !== null && _a !== void 0 ? _a : [ts.factory.createTrue()], signature), name = _b[0], params = _b[1];
152
+ return tstl.createCallExpression(name, params);
153
+ };
154
+ var transformSuperExpression = function (expression, context) {
155
+ var superInfos = context.classSuperInfos;
156
+ var superInfo = undefined;
157
+ if (superInfos) {
158
+ superInfo = superInfos[superInfos.length - 1];
159
+ }
160
+ if (!superInfo)
161
+ return lua.createAnonymousIdentifier(expression);
162
+ var className = superInfo.className;
163
+ // Using `super` without extended type node is a TypeScript error
164
+ // const extendsExpression = extendedTypeNode?.expression;
165
+ // let baseClassName: lua.AssignmentLeftHandSideExpression | undefined;
166
+ // if (extendsExpression && ts.isIdentifier(extendsExpression)) {
167
+ // const symbol = context.checker.getSymbolAtLocation(extendsExpression);
168
+ // if (symbol && !isSymbolExported(context, symbol)) {
169
+ // // Use "baseClassName" if base is a simple identifier
170
+ // baseClassName = transformIdentifier(context, extendsExpression);
171
+ // }
172
+ // }
173
+ // if (!baseClassName) {
174
+ // // Use "className.____super" if the base is not a simple identifier
175
+ // baseClassName = lua.createTableIndexExpression(
176
+ // className,
177
+ // lua.createStringLiteral('____super'),
178
+ // expression
179
+ // );
180
+ // }
181
+ return lua.createTableIndexExpression(className, lua.createStringLiteral('super'));
182
+ };
183
+ exports.transformSuperExpression = transformSuperExpression;
184
+ var plugin = {
185
+ visitors: (_a = {},
186
+ _a[ts.SyntaxKind.ClassDeclaration] = exports.transformClassDeclaration,
187
+ _a[ts.SyntaxKind.SuperKeyword] = exports.transformSuperExpression,
188
+ _a[ts.SyntaxKind.NewExpression] = transformNewExpression,
189
+ _a[ts.SyntaxKind.CallExpression] = function (node, context) {
190
+ if (ts.isIdentifier(node.expression) &&
191
+ node.expression.escapedText === 'require') {
192
+ console.log(1);
193
+ var normalNode = context.superTransformExpression(node);
194
+ normalNode.expression.text = 'import';
195
+ normalNode.expression.originalName = 'import';
196
+ return normalNode;
197
+ }
198
+ else {
199
+ return context.superTransformExpression(node);
200
+ }
201
+ },
202
+ _a),
203
+ };
204
+ exports.default = plugin;
package/assets/plugin.ts CHANGED
@@ -276,7 +276,6 @@ const plugin = {
276
276
  ts.isIdentifier(node.expression) &&
277
277
  node.expression.escapedText === 'require'
278
278
  ) {
279
- console.log(1);
280
279
  const normalNode = context.superTransformExpression(
281
280
  node
282
281
  ) as unknown as {
@@ -0,0 +1,10 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES5",
4
+ "module": "Node16",
5
+ "moduleResolution": "Node16"
6
+ },
7
+ "files": [
8
+ "plugin.ts"
9
+ ]
10
+ }
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "crankscript",
3
- "version": "0.9.5",
3
+ "version": "0.9.7",
4
4
  "scripts": {
5
5
  "dev": "tsx src/index.ts",
6
- "post-build": "tsc-alias --project tsconfig.json"
6
+ "post-build": "tsc-alias --project tsconfig.json",
7
+ "prepare-assets": "npx tsc -p assets/tsconfig.json"
7
8
  },
8
9
  "bin": {
9
10
  "crankscript": "./src/index.js"
@@ -17,9 +18,7 @@
17
18
  "ink": "^5.0.1",
18
19
  "react": "^18.3.1",
19
20
  "ts-morph": "^23.0.0",
20
- "ts-node": "^10.9.2",
21
21
  "typanion": "^3.14.0",
22
- "typescript": "~5.6.2",
23
22
  "typescript-to-lua": "^1.27.0"
24
23
  },
25
24
  "type": "module",
@@ -1,6 +1,2 @@
1
- import { FunctionDescription, PlaydateNamespace, PlaydateType, PropertyDescription } from '../../../types.js';
2
- export declare const getApiDefinitions: (functions: FunctionDescription[], properties: PropertyDescription[]) => {
3
- rootNamespace: PlaydateNamespace;
4
- namespaces: Record<string, PlaydateNamespace>;
5
- types: Record<string, PlaydateType>;
6
- };
1
+ import { ApiDefinitions, FunctionDescription, PropertyDescription } from '../../../types.js';
2
+ export declare const getApiDefinitions: (functions: FunctionDescription[], properties: PropertyDescription[]) => ApiDefinitions;
@@ -1,88 +1,37 @@
1
1
  export const getApiDefinitions = (functions, properties)=>{
2
- const rootNamespace = {
2
+ const global = {
3
3
  functions: [],
4
4
  methods: [],
5
- properties: []
5
+ properties: [],
6
+ namespaces: {}
6
7
  };
7
- const namespaces = {};
8
- const types = {};
9
- const realNamespaces = new Set();
10
- const potentialNamespaces = new Set();
11
- functions.forEach((func)=>{
12
- if (!func.hasSelf) {
13
- let currentNamespace = '';
14
- func.namespaces.forEach((ns)=>{
15
- currentNamespace = currentNamespace ? `${currentNamespace}.${ns}` : ns;
16
- const realNamespaceName = currentNamespace.trim();
17
- if (!realNamespaces.has(realNamespaceName)) {
18
- realNamespaces.add(realNamespaceName);
19
- }
20
- });
21
- }
22
- });
23
- properties.forEach((prop)=>{
24
- let currentNamespace = '';
25
- prop.namespaces.forEach((ns)=>{
26
- currentNamespace = currentNamespace ? `${currentNamespace}.${ns}` : ns;
27
- const realNamespaceName = currentNamespace.trim();
28
- if (!realNamespaces.has(realNamespaceName)) {
29
- realNamespaces.add(realNamespaceName);
8
+ const getOrCreateNamespace = (path, root)=>{
9
+ return path.reduce((currentNamespace, ns)=>{
10
+ if (!currentNamespace.namespaces[ns]) {
11
+ currentNamespace.namespaces[ns] = {
12
+ functions: [],
13
+ methods: [],
14
+ properties: [],
15
+ namespaces: {}
16
+ };
30
17
  }
31
- });
32
- });
18
+ return currentNamespace.namespaces[ns];
19
+ }, root);
20
+ };
33
21
  functions.forEach((func)=>{
22
+ const targetNamespace = getOrCreateNamespace(func.namespaces, global);
34
23
  if (func.hasSelf) {
35
- let currentNamespace = '';
36
- func.namespaces.forEach((ns)=>{
37
- currentNamespace = currentNamespace ? `${currentNamespace}.${ns}` : ns;
38
- if (!potentialNamespaces.has(currentNamespace)) {
39
- potentialNamespaces.add(currentNamespace);
40
- }
41
- });
42
- }
43
- });
44
- realNamespaces.forEach((ns)=>{
45
- namespaces[ns] = {
46
- functions: [],
47
- methods: [],
48
- properties: []
49
- };
50
- });
51
- functions.forEach((func)=>{
52
- const fullNamespacePath = func.namespaces.join('.');
53
- if (realNamespaces.has(fullNamespacePath)) {
54
- if (func.hasSelf) {
55
- namespaces[fullNamespacePath].methods.push(func);
56
- } else {
57
- namespaces[fullNamespacePath].functions.push(func);
58
- }
59
- } else if (potentialNamespaces.has(fullNamespacePath)) {
60
- if (!types[fullNamespacePath]) {
61
- types[fullNamespacePath] = {
62
- methods: []
63
- };
64
- }
65
- types[fullNamespacePath].methods.push(func);
66
- } else if (fullNamespacePath === '') {
67
- if (func.hasSelf) {
68
- rootNamespace.methods.push(func);
69
- } else {
70
- rootNamespace.functions.push(func);
71
- }
24
+ targetNamespace.methods.push(func);
25
+ } else {
26
+ targetNamespace.functions.push(func);
72
27
  }
73
28
  });
74
29
  properties.forEach((prop)=>{
75
- const fullNamespacePath = prop.namespaces.join('.');
76
- if (realNamespaces.has(fullNamespacePath)) {
77
- namespaces[fullNamespacePath].properties.push(prop);
78
- } else if (fullNamespacePath === '') {
79
- rootNamespace.properties.push(prop);
80
- }
30
+ const targetNamespace = getOrCreateNamespace(prop.namespaces, global);
31
+ targetNamespace.properties.push(prop);
81
32
  });
82
33
  return {
83
- rootNamespace,
84
- namespaces,
85
- types
34
+ global
86
35
  };
87
36
  };
88
37
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../libs/cli/src/commands/GenerateTypes/fn/getApiDefinitions.ts"],"sourcesContent":["import {\n ApiDefinitions,\n FunctionDescription,\n PlaydateNamespace,\n PlaydateType,\n PropertyDescription,\n} from '@/cli/types.js';\n\nexport const getApiDefinitions = (\n functions: FunctionDescription[],\n properties: PropertyDescription[]\n) => {\n const rootNamespace: PlaydateNamespace = {\n functions: [],\n methods: [],\n properties: [],\n };\n const namespaces: Record<string, PlaydateNamespace> = {};\n const types: Record<string, PlaydateType> = {};\n const realNamespaces = new Set<string>();\n const potentialNamespaces = new Set<string>();\n\n functions.forEach((func) => {\n if (!func.hasSelf) {\n let currentNamespace = '';\n func.namespaces.forEach((ns) => {\n currentNamespace = currentNamespace\n ? `${currentNamespace}.${ns}`\n : ns;\n\n const realNamespaceName = currentNamespace.trim();\n\n if (!realNamespaces.has(realNamespaceName)) {\n realNamespaces.add(realNamespaceName);\n }\n });\n }\n });\n\n properties.forEach((prop) => {\n let currentNamespace = '';\n prop.namespaces.forEach((ns) => {\n currentNamespace = currentNamespace\n ? `${currentNamespace}.${ns}`\n : ns;\n\n const realNamespaceName = currentNamespace.trim();\n\n if (!realNamespaces.has(realNamespaceName)) {\n realNamespaces.add(realNamespaceName);\n }\n });\n });\n\n functions.forEach((func) => {\n if (func.hasSelf) {\n let currentNamespace = '';\n func.namespaces.forEach((ns) => {\n currentNamespace = currentNamespace\n ? `${currentNamespace}.${ns}`\n : ns;\n\n if (!potentialNamespaces.has(currentNamespace)) {\n potentialNamespaces.add(currentNamespace);\n }\n });\n }\n });\n\n realNamespaces.forEach((ns) => {\n namespaces[ns] = {\n functions: [],\n methods: [],\n properties: [],\n };\n });\n\n functions.forEach((func) => {\n const fullNamespacePath = func.namespaces.join('.');\n\n if (realNamespaces.has(fullNamespacePath)) {\n if (func.hasSelf) {\n namespaces[fullNamespacePath].methods.push(func);\n } else {\n namespaces[fullNamespacePath].functions.push(func);\n }\n } else if (potentialNamespaces.has(fullNamespacePath)) {\n if (!types[fullNamespacePath]) {\n types[fullNamespacePath] = { methods: [] };\n }\n types[fullNamespacePath].methods.push(func);\n } else if (fullNamespacePath === '') {\n if (func.hasSelf) {\n rootNamespace.methods.push(func);\n } else {\n rootNamespace.functions.push(func);\n }\n }\n });\n\n properties.forEach((prop) => {\n const fullNamespacePath = prop.namespaces.join('.');\n\n if (realNamespaces.has(fullNamespacePath)) {\n namespaces[fullNamespacePath].properties.push(prop);\n } else if (fullNamespacePath === '') {\n rootNamespace.properties.push(prop);\n }\n });\n\n return {\n rootNamespace,\n namespaces,\n types,\n } satisfies ApiDefinitions;\n};\n"],"names":["getApiDefinitions","functions","properties","rootNamespace","methods","namespaces","types","realNamespaces","Set","potentialNamespaces","forEach","func","hasSelf","currentNamespace","ns","realNamespaceName","trim","has","add","prop","fullNamespacePath","join","push"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAQA,OAAO,MAAMA,oBAAoB,CAC7BC,WACAC;IAEA,MAAMC,gBAAmC;QACrCF,WAAW,EAAE;QACbG,SAAS,EAAE;QACXF,YAAY,EAAE;IAClB;IACA,MAAMG,aAAgD,CAAC;IACvD,MAAMC,QAAsC,CAAC;IAC7C,MAAMC,iBAAiB,IAAIC;IAC3B,MAAMC,sBAAsB,IAAID;IAEhCP,UAAUS,OAAO,CAAC,CAACC;QACf,IAAI,CAACA,KAAKC,OAAO,EAAE;YACf,IAAIC,mBAAmB;YACvBF,KAAKN,UAAU,CAACK,OAAO,CAAC,CAACI;gBACrBD,mBAAmBA,mBACb,CAAC,EAAEA,iBAAiB,CAAC,EAAEC,GAAG,CAAC,GAC3BA;gBAEN,MAAMC,oBAAoBF,iBAAiBG,IAAI;gBAE/C,IAAI,CAACT,eAAeU,GAAG,CAACF,oBAAoB;oBACxCR,eAAeW,GAAG,CAACH;gBACvB;YACJ;QACJ;IACJ;IAEAb,WAAWQ,OAAO,CAAC,CAACS;QAChB,IAAIN,m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AACX;QAC1C,OAAO,IAAIS,sBAAsB,IAAI;YACjC,IAAIT,KAAKC,OAAO,EAAE;gBACdT,cAAcC,OAAO,CAACkB,IAAI,CAACX;YAC/B,OAAO;gBACHR,cAAcF,SAAS,CAACqB,IAAI,CAACX;YACjC;QACJ;IACJ;IAEAT,WAAWQ,OAAO,CAAC,CAACS;QAChB,MAAMC,oBAAoBD,KAAKd,UAAU,CAACgB,IAAI,CAAC;QAE/C,IAAId,eAAeU,GAAG,CAACG,oBAAoB;YACvCf,UAAU,CAACe,kBAAkB,CAAClB,UAAU,CAACoB,IAAI,CAACH;QAClD,OAAO,IAAIC,sBAAsB,IAAI;YACjCjB,cAAcD,UAAU,CAACoB,IAAI,CAACH;QAClC;IACJ;IAEA,OAAO;QACHhB;QACAE;QACAC;IACJ;AACJ,EAAE"}
1
+ {"version":3,"sources":["../../../../../../../libs/cli/src/commands/GenerateTypes/fn/getApiDefinitions.ts"],"sourcesContent":["import {\n ApiDefinitions,\n FunctionDescription,\n ApiObject,\n PropertyDescription,\n} from '@/cli/types.js';\n\nexport const getApiDefinitions = (\n functions: FunctionDescription[],\n properties: PropertyDescription[]\n): ApiDefinitions => {\n const global: ApiObject = {\n functions: [],\n methods: [],\n properties: [],\n namespaces: {},\n };\n\n const getOrCreateNamespace = (\n path: string[],\n root: ApiObject\n ): ApiObject => {\n return path.reduce((currentNamespace, ns) => {\n if (!currentNamespace.namespaces[ns]) {\n currentNamespace.namespaces[ns] = {\n functions: [],\n methods: [],\n properties: [],\n namespaces: {},\n };\n }\n return currentNamespace.namespaces[ns];\n }, root);\n };\n\n functions.forEach((func) => {\n const targetNamespace = getOrCreateNamespace(func.namespaces, global);\n if (func.hasSelf) {\n targetNamespace.methods.push(func);\n } else {\n targetNamespace.functions.push(func);\n }\n });\n\n properties.forEach((prop) => {\n const targetNamespace = getOrCreateNamespace(prop.namespaces, global);\n targetNamespace.properties.push(prop);\n });\n\n return { global };\n};\n"],"names":["getApiDefinitions","functions","properties","global","methods","namespaces","getOrCreateNamespace","path","root","reduce","currentNamespace","ns","forEach","func","targetNamespace","hasSelf","push","prop"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAOA,OAAO,MAAMA,oBAAoB,CAC7BC,WACAC;IAEA,MAAMC,SAAoB;QACtBF,WAAW,EAAE;QACbG,SAAS,EAAE;QACXF,YAAY,EAAE;QACdG,YAAY,CAAC;IACjB;IAEA,MAAMC,uBAAuB,CACzBC,MACAC;QAEA,OAAOD,KAAKE,MAAM,CAAC,CAACC,kBAAkBC;YAClC,IAAI,CAACD,iBAAiBL,UAAU,CAACM,GAAG,EAAE;gBAClCD,iBAAiBL,UAAU,CAACM,GAAG,GAAG;oBAC9BV,WAAW,EAAE;oBACbG,SAAS,EAAE;oBACXF,YAAY,EAAE;oBACdG,YAAY,CAAC;gBACjB;YACJ;YACA,OAAOK,iBAAiBL,UAAU,CAACM,GAAG;QAC1C,GAAGH;IACP;IAEAP,UAAUW,OAAO,CAAC,CAACC;QACf,MAAMC,kBAAkBR,qBAAqBO,KAAKR,UAAU,EAAEF;QAC9D,IAAIU,KAAKE,OAAO,EAAE;YACdD,gBAAgBV,OAAO,CAACY,IAAI,CAACH;QACjC,OAAO;YACHC,gBAAgBb,SAAS,CAACe,IAAI,CAACH;QACnC;IACJ;IAEAX,WAAWU,OAAO,CAAC,CAACK;QAChB,MAAMH,kBAAkBR,qBAAqBW,KAAKZ,UAAU,EAAEF;QAC9DW,gBAAgBZ,UAAU,CAACc,IAAI,CAACC;IACpC;IAEA,OAAO;QAAEd;IAAO;AACpB,EAAE"}
@@ -1,7 +1,8 @@
1
+ import { _ as _extends } from "@swc/helpers/_/_extends";
1
2
  import { writeFileSync } from 'node:fs';
2
3
  import { useMemo } from 'react';
3
4
  import { Project } from 'ts-morph';
4
- import { generateNamespace } from '../../../commands/GenerateTypes/fn/generateNamespace.js';
5
+ import { TypescriptReservedNamed } from '../../../constants.js';
5
6
  export const useGenerateTypeFile = (path, definitions, typeProvider)=>{
6
7
  const generateTypeFile = useMemo(()=>{
7
8
  return {
@@ -20,16 +21,9 @@ export const useGenerateTypeFile = (path, definitions, typeProvider)=>{
20
21
  const typeFile = project.createSourceFile(path, '', {
21
22
  overwrite: true
22
23
  });
24
+ const globalNamespace = definitions.global;
23
25
  typeFile.addStatements(typeProvider.getGlobalStatements());
24
- const subjects = new Map();
25
- const typeSubjects = new Map();
26
- subjects.set('root', typeFile);
27
- generateNamespace(definitions.rootNamespace, [], subjects, typeSubjects, typeProvider, definitions.types);
28
- Object.keys(definitions.namespaces).forEach((namespace)=>{
29
- const namespaceDescription = definitions.namespaces[namespace];
30
- const namespaces = namespace.split('.');
31
- generateNamespace(namespaceDescription, namespaces, subjects, typeSubjects, typeProvider, definitions.types);
32
- });
26
+ generateNamespace(globalNamespace, typeFile, typeProvider);
33
27
  writeFileSync(path, typeFile.getFullText().replace('/**', '\n/**'));
34
28
  },
35
29
  ready: definitions !== null && typeProvider !== null
@@ -42,5 +36,86 @@ export const useGenerateTypeFile = (path, definitions, typeProvider)=>{
42
36
  generateTypeFile
43
37
  };
44
38
  };
39
+ const generateNamespace = (apiObject, incomingSubject, typeProvider, name)=>{
40
+ let subject = incomingSubject;
41
+ if (name) {
42
+ subject = incomingSubject.addModule({
43
+ name
44
+ });
45
+ }
46
+ if (name === 'playdate') {
47
+ subject.addStatements(typeProvider.getStatements());
48
+ }
49
+ for (const func of apiObject.functions){
50
+ const isFunctionNameReserved = TypescriptReservedNamed.includes(func.name);
51
+ const resolvedName = `_${func.name}`;
52
+ const parameters = typeProvider.getParameters(func);
53
+ subject.addFunction(_extends({
54
+ name: isFunctionNameReserved ? resolvedName : func.name,
55
+ docs: [
56
+ func.docs
57
+ ],
58
+ parameters,
59
+ returnType: typeProvider.getFunctionReturnType(func)
60
+ }, typeProvider.getFunctionOverrideOptions(func)));
61
+ if (isFunctionNameReserved) {
62
+ subject.addExportDeclaration({
63
+ namedExports: [
64
+ {
65
+ name: resolvedName,
66
+ alias: func.name
67
+ }
68
+ ]
69
+ });
70
+ }
71
+ }
72
+ let propertiesSubject = null;
73
+ if (name && apiObject.methods.length > 0) {
74
+ const typeClass = incomingSubject.addClass({
75
+ name
76
+ });
77
+ propertiesSubject = typeClass;
78
+ for (const method of apiObject.methods){
79
+ const parameters = typeProvider.getParameters(method);
80
+ typeClass.addMethod(_extends({
81
+ name: method.name,
82
+ docs: [
83
+ method.docs
84
+ ],
85
+ parameters,
86
+ returnType: typeProvider.getFunctionReturnType(method)
87
+ }, typeProvider.getFunctionOverrideOptions(method)));
88
+ }
89
+ }
90
+ for (const property of apiObject.properties){
91
+ const propertyDetails = typeProvider.getPropertyDetails(property);
92
+ if (propertiesSubject) {
93
+ propertiesSubject.addProperty({
94
+ name: property.name,
95
+ docs: [
96
+ property.docs
97
+ ],
98
+ type: propertyDetails.type,
99
+ isStatic: propertyDetails.isStatic,
100
+ isReadonly: propertyDetails.isReadOnly
101
+ });
102
+ } else {
103
+ subject.addVariableStatement({
104
+ docs: [
105
+ property.docs
106
+ ],
107
+ declarations: [
108
+ {
109
+ name: property.name,
110
+ type: propertyDetails.type
111
+ }
112
+ ]
113
+ });
114
+ }
115
+ }
116
+ for (const namespace of Object.entries(apiObject.namespaces)){
117
+ generateNamespace(namespace[1], subject, typeProvider, namespace[0]);
118
+ }
119
+ };
45
120
 
46
121
  //# sourceMappingURL=useGenerateTypeFile.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../libs/cli/src/commands/GenerateTypes/hooks/useGenerateTypeFile.ts"],"sourcesContent":["import { writeFileSync } from 'node:fs';\nimport { useMemo } from 'react';\nimport {\n ClassDeclaration,\n ModuleDeclaration,\n Project,\n SourceFile,\n} from 'ts-morph';\nimport { generateNamespace } from '@/cli/commands/GenerateTypes/fn/generateNamespace.js';\nimport { createTypeProvider } from '@/cli/commands/GenerateTypes/utils/createTypeProvider.js';\nimport { ApiDefinitions, CheckListItem } from '@/cli/types.js';\n\nexport const useGenerateTypeFile = (\n path: string,\n definitions: ApiDefinitions | null,\n typeProvider: ReturnType<typeof createTypeProvider> | null\n) => {\n const generateTypeFile = useMemo(() => {\n return {\n waitingDescription: 'Waiting to generate the type file...',\n errorDescription: 'Failed to generate the type file',\n finishedDescription: () => 'Type file generated',\n runningDescription: 'Generating the type file...',\n runner: async () => {\n if (!definitions) {\n throw new Error('Definitions are not set');\n }\n\n if (!typeProvider) {\n throw new Error('Type provider is not set');\n }\n\n const project = new Project();\n const typeFile = project.createSourceFile(path, '', {\n overwrite: true,\n });\n typeFile.addStatements(typeProvider.getGlobalStatements());\n\n const subjects = new Map<\n string,\n SourceFile | ModuleDeclaration\n >();\n const typeSubjects = new Map<string, ClassDeclaration>();\n subjects.set('root', typeFile);\n\n generateNamespace(\n definitions.rootNamespace,\n [],\n subjects,\n typeSubjects,\n typeProvider,\n definitions.types\n );\n\n Object.keys(definitions.namespaces).forEach((namespace) => {\n const namespaceDescription =\n definitions.namespaces[namespace];\n const namespaces = namespace.split('.');\n generateNamespace(\n namespaceDescription,\n namespaces,\n subjects,\n typeSubjects,\n typeProvider,\n definitions.types\n );\n });\n\n writeFileSync(\n path,\n typeFile.getFullText().replace('/**', '\\n/**')\n );\n },\n ready: definitions !== null && typeProvider !== null,\n } satisfies CheckListItem<void>;\n }, [definitions, typeProvider]);\n\n return {\n generateTypeFile,\n };\n};\n"],"names":["writeFileSync","useMemo","Project","generateNamespace","useGenerateTypeFile","path","definitions","typeProvider","generateTypeFile","waitingDescription","errorDescription","finishedDescription","runningDescription","runner","Error","project","typeFile","createSourceFile","overwrite","addStatements","getGlobalStatements","subjects","Map","typeSubjects","set","rootNamespace","types","Object","keys","namespaces","forEach","namespace","namespaceDescription","split","getFullText","replace","ready"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,aAAa,QAAQ,UAAU;AACxC,SAASC,OAAO,QAAQ,QAAQ;AAChC,SAGIC,OAAO,QAEJ,WAAW;AAClB,SAASC,iBAAiB,QAAQ,uDAAuD;AAIzF,OAAO,MAAMC,sBAAsB,CAC/BC,MACAC,aACAC;IAEA,MAAMC,mBAAmBP,QAAQ;QAC7B,OAAO;YACHQ,oBAAoB;YACpBC,kBAAkB;YAClBC,qBAAqB,IAAM;YAC3BC,oBAAoB;YACpBC,QAAQ;gBACJ,IAAI,CAACP,aAAa;oBACd,MAAM,IAAIQ,MAAM;gBACpB;gBAEA,IAAI,CAACP,cAAc;oBACf,MAAM,IAAIO,MAAM;gBACpB;gBAEA,MAAMC,UAAU,IAAIb;gBACpB,MAAMc,WAAWD,QAAQE,gBAAgB,CAACZ,MAAM,IAAI;oBAChDa,WAAW;gBACf;gBACAF,SAASG,aAAa,CAACZ,aAAaa,mBAAmB;gBAEvD,MAAMC,WAAW,IAAIC;gBAIrB,MAAMC,eAAe,IAAID;gBACzBD,SAASG,GAAG,CAAC,QAAQR;gBAErBb,kBACIG,YAAYmB,aAAa,EACzB,EAAE,EACFJ,UACAE,cACAhB,cACAD,YAAYoB,KAAK;gBAGrBC,OAAOC,IAAI,CAACtB,YAAYuB,UAAU,EAAEC,OAAO,CAAC,CAACC;oBACzC,MAAMC,uBACF1B,YAAYuB,UAAU,CAACE,UAAU;oBACrC,MAAMF,aAAaE,UAAUE,KAAK,CAAC;oBACnC9B,kBACI6B,sBACAH,YACAR,UACAE,cACAhB,cACAD,YAAYoB,KAAK;gBAEzB;gBAEA1B,cACIK,MACAW,SAASkB,WAAW,GAAGC,OAAO,CAAC,OAAO;YAE9C;YACAC,OAAO9B,gBAAgB,QAAQC,iBAAiB;QACpD;IACJ,GAAG;QAACD;QAAaC;KAAa;IAE9B,OAAO;QACHC;IACJ;AACJ,EAAE"}
1
+ {"version":3,"sources":["../../../../../../../libs/cli/src/commands/GenerateTypes/hooks/useGenerateTypeFile.ts"],"sourcesContent":["import { writeFileSync } from 'node:fs';\nimport { useMemo } from 'react';\nimport {\n ClassDeclaration,\n FunctionDeclarationStructure,\n MethodDeclarationStructure,\n ModuleDeclaration,\n Project,\n SourceFile,\n} from 'ts-morph';\nimport { createTypeProvider } from '@/cli/commands/GenerateTypes/utils/createTypeProvider.js';\nimport { TypescriptReservedNamed } from '@/cli/constants.js';\nimport { ApiDefinitions, ApiObject, CheckListItem } from '@/cli/types.js';\n\nexport const useGenerateTypeFile = (\n path: string,\n definitions: ApiDefinitions | null,\n typeProvider: ReturnType<typeof createTypeProvider> | null\n) => {\n const generateTypeFile = useMemo(() => {\n return {\n waitingDescription: 'Waiting to generate the type file...',\n errorDescription: 'Failed to generate the type file',\n finishedDescription: () => 'Type file generated',\n runningDescription: 'Generating the type file...',\n runner: async () => {\n if (!definitions) {\n throw new Error('Definitions are not set');\n }\n\n if (!typeProvider) {\n throw new Error('Type provider is not set');\n }\n\n const project = new Project();\n const typeFile = project.createSourceFile(path, '', {\n overwrite: true,\n });\n\n const globalNamespace = definitions.global;\n\n typeFile.addStatements(typeProvider.getGlobalStatements());\n\n generateNamespace(globalNamespace, typeFile, typeProvider);\n\n writeFileSync(\n path,\n typeFile.getFullText().replace('/**', '\\n/**')\n );\n },\n ready: definitions !== null && typeProvider !== null,\n } satisfies CheckListItem<void>;\n }, [definitions, typeProvider]);\n\n return {\n generateTypeFile,\n };\n};\n\nconst generateNamespace = (\n apiObject: ApiObject,\n incomingSubject: SourceFile | ModuleDeclaration,\n typeProvider: ReturnType<typeof createTypeProvider>,\n name?: string\n) => {\n let subject = incomingSubject;\n\n if (name) {\n subject = incomingSubject.addModule({\n name,\n });\n }\n\n if (name === 'playdate') {\n subject.addStatements(typeProvider.getStatements());\n }\n\n for (const func of apiObject.functions) {\n const isFunctionNameReserved = TypescriptReservedNamed.includes(\n func.name\n );\n const resolvedName = `_${func.name}`;\n const parameters = typeProvider.getParameters(func);\n\n subject.addFunction({\n name: isFunctionNameReserved ? resolvedName : func.name,\n docs: [func.docs],\n parameters,\n returnType: typeProvider.getFunctionReturnType(func),\n ...(typeProvider.getFunctionOverrideOptions(\n func\n ) as FunctionDeclarationStructure),\n });\n\n if (isFunctionNameReserved) {\n subject.addExportDeclaration({\n namedExports: [\n {\n name: resolvedName,\n alias: func.name,\n },\n ],\n });\n }\n }\n\n let propertiesSubject: ClassDeclaration | null = null;\n\n if (name && apiObject.methods.length > 0) {\n const typeClass = incomingSubject.addClass({\n name,\n });\n propertiesSubject = typeClass;\n\n for (const method of apiObject.methods) {\n const parameters = typeProvider.getParameters(method);\n\n typeClass.addMethod({\n name: method.name,\n docs: [method.docs],\n parameters,\n returnType: typeProvider.getFunctionReturnType(method),\n ...(typeProvider.getFunctionOverrideOptions(\n method\n ) as Partial<MethodDeclarationStructure>),\n });\n }\n }\n\n for (const property of apiObject.properties) {\n const propertyDetails = typeProvider.getPropertyDetails(property);\n\n if (propertiesSubject) {\n propertiesSubject.addProperty({\n name: property.name,\n docs: [property.docs],\n type: propertyDetails.type,\n isStatic: propertyDetails.isStatic,\n isReadonly: propertyDetails.isReadOnly,\n });\n } else {\n subject.addVariableStatement({\n docs: [property.docs],\n declarations: [\n {\n name: property.name,\n type: propertyDetails.type,\n },\n ],\n });\n }\n }\n\n for (const namespace of Object.entries(apiObject.namespaces)) {\n generateNamespace(namespace[1], subject, typeProvider, namespace[0]);\n }\n};\n"],"names":["writeFileSync","useMemo","Project","TypescriptReservedNamed","useGenerateTypeFile","path","definitions","typeProvider","generateTypeFile","waitingDescription","errorDescription","finishedDescription","runningDescription","runner","Error","project","typeFile","createSourceFile","overwrite","globalNamespace","global","addStatements","getGlobalStatements","generateNamespace","getFullText","replace","ready","apiObject","incomingSubject","name","subject","addModule","getStatements","func","functions","isFunctionNameReserved","includes","resolvedName","parameters","getParameters","addFunction","docs","returnType","getFunctionReturnType","getFunctionOverrideOptions","addExportDeclaration","namedExports","alias","propertiesSubject","methods","length","typeClass","addClass","method","addMethod","property","properties","propertyDetails","getPropertyDetails","addProperty","type","isStatic","isReadonly","isReadOnly","addVariableStatement","declarations","namespace","Object","entries","namespaces"],"range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AUJ,gBAAgBI,QAAQ;gBAClCC,YAAYL,gBAAgBM,UAAU;YAC1C;QACJ,OAAO;YACHjC,QAAQkC,oBAAoB,CAAC;gBACzBvB,MAAM;oBAACc,SAASd,IAAI;iBAAC;gBACrBwB,cAAc;oBACV;wBACIpC,MAAM0B,SAAS1B,IAAI;wBACnB+B,MAAMH,gBAAgBG,IAAI;oBAC9B;iBACH;YACL;QACJ;IACJ;IAEA,KAAK,MAAMM,aAAaC,OAAOC,OAAO,CAACzC,UAAU0C,UAAU,EAAG;QAC1D9C,kBAAkB2C,SAAS,CAAC,EAAE,EAAEpC,SAASvB,cAAc2D,SAAS,CAAC,EAAE;IACvE;AACJ"}
@@ -6,11 +6,7 @@ export declare const useParseDocumentation: (html: string | null, version: strin
6
6
  errorDescription: string;
7
7
  finishedDescription: () => string;
8
8
  runningDescription: string;
9
- runner: () => Promise<{
10
- rootNamespace: import("../../../types.js").PlaydateNamespace;
11
- namespaces: Record<string, import("../../../types.js").PlaydateNamespace>;
12
- types: Record<string, import("../../../types.js").PlaydateType>;
13
- }>;
9
+ runner: () => Promise<ApiDefinitions>;
14
10
  onFinish: (result: ApiDefinitions) => void;
15
11
  ready: boolean;
16
12
  };
@@ -13,7 +13,7 @@ const transpile = (path)=>{
13
13
  luaBundleEntry: join(path, 'src', 'index.ts'),
14
14
  luaPlugins: [
15
15
  {
16
- name: join(RootFolder, 'assets', 'plugin.ts')
16
+ name: join(RootFolder, 'assets', 'plugin.js')
17
17
  }
18
18
  ]
19
19
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../libs/cli/src/commands/TranspileCommand/components/Transpile.tsx"],"sourcesContent":["import { join } from 'node:path';\nimport React from 'react';\nimport { useMemo } from 'react';\nimport * as tstl from 'typescript-to-lua';\nimport { LuaTarget } from 'typescript-to-lua';\nimport { CheckList } from '@/cli/components/CheckList/index.js';\nimport { RootFolder } from '@/cli/constants.js';\nimport { CheckListItem } from '@/cli/types.js';\n\nconst transpile = (path: string) => {\n tstl.transpileProject(join(path, 'tsconfig.json'), {\n luaTarget: LuaTarget.Lua54,\n outDir: join(path, 'Source'),\n luaBundle: 'main.lua',\n luaBundleEntry: join(path, 'src', 'index.ts'),\n luaPlugins: [\n {\n name: join(RootFolder, 'assets', 'plugin.ts'),\n },\n ],\n });\n};\n\nexport const Transpile = ({ path }: { path: string }) => {\n const items = useMemo(\n () => [\n {\n waitingDescription: 'Waiting to transpile code...',\n errorDescription: 'Could not transpile code',\n runningDescription: 'Transpiling code...',\n finishedDescription: () => 'Code transpiled',\n runner: async () => {\n transpile(path);\n },\n ready: true,\n },\n ],\n []\n ) as CheckListItem<unknown>[];\n\n return <CheckList items={items} onFinish={process.exit} />;\n};\n"],"names":["join","React","useMemo","tstl","LuaTarget","CheckList","RootFolder","transpile","path","transpileProject","luaTarget","Lua54","outDir","luaBundle","luaBundleEntry","luaPlugins","name","Transpile","items","waitingDescription","errorDescription","runningDescription","finishedDescription","runner","ready","onFinish","process","exit"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,IAAI,QAAQ,YAAY;AACjC,OAAOC,WAAW,QAAQ;AAC1B,SAASC,OAAO,QAAQ,QAAQ;AAChC,YAAYC,UAAU,oBAAoB;AAC1C,SAASC,SAAS,QAAQ,oBAAoB;AAC9C,SAASC,SAAS,QAAQ,sCAAsC;AAChE,SAASC,UAAU,QAAQ,qBAAqB;AAGhD,MAAMC,YAAY,CAACC;IACfL,KAAKM,gBAAgB,CAACT,KAAKQ,MAAM,kBAAkB;QAC/CE,WAAWN,UAAUO,KAAK;QAC1BC,QAAQZ,KAAKQ,MAAM;QACnBK,WAAW;QACXC,gBAAgBd,KAAKQ,MAAM,OAAO;QAClCO,YAAY;YACR;gBACIC,MAAMhB,KAAKM,YAAY,UAAU;YACrC;SACH;IACL;AACJ;AAEA,OAAO,MAAMW,YAAY,CAAC,EAAET,IAAI,EAAoB;IAChD,MAAMU,QAAQhB,QACV,IAAM;YACF;gBACIiB,oBAAoB;gBACpBC,kBAAkB;gBAClBC,oBAAoB;gBACpBC,qBAAqB,IAAM;gBAC3BC,QAAQ;oBACJhB,UAAUC;gBACd;gBACAgB,OAAO;YACX;SACH,EACD,EAAE;IAGN,qBAAO,oBAACnB;QAAUa,OAAOA;QAAOO,UAAUC,QAAQC,IAAI;;AAC1D,EAAE"}
1
+ {"version":3,"sources":["../../../../../../../libs/cli/src/commands/TranspileCommand/components/Transpile.tsx"],"sourcesContent":["import { join } from 'node:path';\nimport React from 'react';\nimport { useMemo } from 'react';\nimport * as tstl from 'typescript-to-lua';\nimport { LuaTarget } from 'typescript-to-lua';\nimport { CheckList } from '@/cli/components/CheckList/index.js';\nimport { RootFolder } from '@/cli/constants.js';\nimport { CheckListItem } from '@/cli/types.js';\n\nconst transpile = (path: string) => {\n tstl.transpileProject(join(path, 'tsconfig.json'), {\n luaTarget: LuaTarget.Lua54,\n outDir: join(path, 'Source'),\n luaBundle: 'main.lua',\n luaBundleEntry: join(path, 'src', 'index.ts'),\n luaPlugins: [\n {\n name: join(RootFolder, 'assets', 'plugin.js'),\n },\n ],\n });\n};\n\nexport const Transpile = ({ path }: { path: string }) => {\n const items = useMemo(\n () => [\n {\n waitingDescription: 'Waiting to transpile code...',\n errorDescription: 'Could not transpile code',\n runningDescription: 'Transpiling code...',\n finishedDescription: () => 'Code transpiled',\n runner: async () => {\n transpile(path);\n },\n ready: true,\n },\n ],\n []\n ) as CheckListItem<unknown>[];\n\n return <CheckList items={items} onFinish={process.exit} />;\n};\n"],"names":["join","React","useMemo","tstl","LuaTarget","CheckList","RootFolder","transpile","path","transpileProject","luaTarget","Lua54","outDir","luaBundle","luaBundleEntry","luaPlugins","name","Transpile","items","waitingDescription","errorDescription","runningDescription","finishedDescription","runner","ready","onFinish","process","exit"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,IAAI,QAAQ,YAAY;AACjC,OAAOC,WAAW,QAAQ;AAC1B,SAASC,OAAO,QAAQ,QAAQ;AAChC,YAAYC,UAAU,oBAAoB;AAC1C,SAASC,SAAS,QAAQ,oBAAoB;AAC9C,SAASC,SAAS,QAAQ,sCAAsC;AAChE,SAASC,UAAU,QAAQ,qBAAqB;AAGhD,MAAMC,YAAY,CAACC;IACfL,KAAKM,gBAAgB,CAACT,KAAKQ,MAAM,kBAAkB;QAC/CE,WAAWN,UAAUO,KAAK;QAC1BC,QAAQZ,KAAKQ,MAAM;QACnBK,WAAW;QACXC,gBAAgBd,KAAKQ,MAAM,OAAO;QAClCO,YAAY;YACR;gBACIC,MAAMhB,KAAKM,YAAY,UAAU;YACrC;SACH;IACL;AACJ;AAEA,OAAO,MAAMW,YAAY,CAAC,EAAET,IAAI,EAAoB;IAChD,MAAMU,QAAQhB,QACV,IAAM;YACF;gBACIiB,oBAAoB;gBACpBC,kBAAkB;gBAClBC,oBAAoB;gBACpBC,qBAAqB,IAAM;gBAC3BC,QAAQ;oBACJhB,UAAUC;gBACd;gBACAgB,OAAO;YACX;SACH,EACD,EAAE;IAGN,qBAAO,oBAACnB;QAAUa,OAAOA;QAAOO,UAAUC,QAAQC,IAAI;;AAC1D,EAAE"}
package/src/types.d.ts CHANGED
@@ -54,27 +54,14 @@ export interface FunctionDescription {
54
54
  hasSelf: boolean;
55
55
  docs: string;
56
56
  }
57
- export interface ConstantDescription {
58
- name: string;
59
- docs: string;
60
- values: {
61
- name: string;
62
- value: number;
63
- docs: string;
64
- }[];
65
- }
66
- export interface PlaydateNamespace {
57
+ export interface ApiObject {
67
58
  functions: FunctionDescription[];
68
59
  methods: FunctionDescription[];
69
60
  properties: PropertyDescription[];
70
- }
71
- export interface PlaydateType {
72
- methods: FunctionDescription[];
61
+ namespaces: Record<string, ApiObject>;
73
62
  }
74
63
  export interface ApiDefinitions {
75
- rootNamespace: PlaydateNamespace;
76
- namespaces: Record<string, PlaydateNamespace>;
77
- types: Record<string, PlaydateType>;
64
+ global: ApiObject;
78
65
  }
79
66
  export interface ParameterDetails {
80
67
  name: string;
package/src/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../libs/cli/src/types.ts"],"sourcesContent":["import {\n FunctionDeclarationStructure,\n MethodDeclarationStructure,\n ParameterDeclarationStructure,\n} from 'ts-morph';\nimport { Environment } from '@/cli/environment/dto/Environment.js';\nimport { PlaydateSdkPath } from '@/cli/environment/path/dto/PlaydateSdkPath.js';\n\nexport enum PlaydateSdkVersionIdentifier {\n Latest = 'latest',\n}\n\nexport type PlaydateSdkVersion = PlaydateSdkVersionIdentifier.Latest | string;\n\nexport type EnvironmentHealthResult =\n | {\n isHealthy: true;\n environment: Environment;\n health: EnvironmentHealth;\n }\n | {\n isHealthy: false;\n health: EnvironmentHealth;\n };\n\nexport enum HealthCheckStatusType {\n Healthy = 'Healthy',\n Unhealthy = 'Unhealthy',\n Unknown = 'Unknown',\n}\n\nexport type HealthCheckStatus<TArgument> =\n | {\n healthStatus:\n | HealthCheckStatusType.Unknown\n | HealthCheckStatusType.Unhealthy;\n }\n | {\n healthStatus: HealthCheckStatusType.Healthy;\n argument: TArgument;\n };\n\nexport interface EnvironmentHealth {\n sdkPathKnown: HealthCheckStatus<PlaydateSdkPath>;\n}\n\nexport type CheckListItem<TResult> = {\n runningDescription: string;\n waitingDescription: string;\n errorDescription: string;\n finishedDescription: (result: TResult) => string;\n runner: () => Promise<TResult> | Promise<false>;\n onFinish?: (result: TResult) => void;\n ready?: boolean;\n};\n\nexport interface ParameterDescription {\n name: string;\n required: boolean;\n}\n\nexport interface PropertyDescription {\n signature: string;\n name: string;\n namespaces: string[];\n docs: string;\n}\n\nexport interface FunctionDescription {\n signature: string;\n name: string;\n namespaces: string[];\n parameters: ParameterDescription[];\n hasSelf: boolean;\n docs: string;\n}\n\nexport interface ConstantDescription {\n name: string;\n docs: string;\n values: {\n name: string;\n value: number;\n docs: string;\n }[];\n}\n\nexport interface PlaydateNamespace {\n functions: FunctionDescription[];\n methods: FunctionDescription[];\n properties: PropertyDescription[];\n}\n\nexport interface PlaydateType {\n methods: FunctionDescription[];\n}\n\nexport interface ApiDefinitions {\n rootNamespace: PlaydateNamespace;\n namespaces: Record<string, PlaydateNamespace>;\n types: Record<string, PlaydateType>;\n}\n\nexport interface ParameterDetails {\n name: string;\n type: string;\n overrideOptions?: Partial<\n Omit<ParameterDeclarationStructure, 'kind' | 'name' | 'type'>\n >;\n}\n\nexport interface PropertyDetails {\n signature: string;\n type: string;\n isStatic?: boolean;\n isReadOnly?: boolean;\n}\n\nexport interface FunctionDetails {\n signature: string;\n parameters: ParameterDetails[];\n returnType: string;\n overrideParameters?: boolean;\n overrideOptions?: Partial<\n FunctionDeclarationStructure | MethodDeclarationStructure\n >;\n}\n\nexport type TypeProviderData = {\n globalStatements: string[];\n statements: string[];\n properties: Record<string, PropertyDetails>;\n functions: Record<string, FunctionDetails>;\n};\n"],"names":["PlaydateSdkVersionIdentifier","HealthCheckStatusType"],"rangeMappings":";;;;;;;;;","mappings":";UAQYA;;GAAAA,iCAAAA;;UAiBAC;;;;GAAAA,0BAAAA"}
1
+ {"version":3,"sources":["../../../../libs/cli/src/types.ts"],"sourcesContent":["import {\n FunctionDeclarationStructure,\n MethodDeclarationStructure,\n ParameterDeclarationStructure,\n} from 'ts-morph';\nimport { Environment } from '@/cli/environment/dto/Environment.js';\nimport { PlaydateSdkPath } from '@/cli/environment/path/dto/PlaydateSdkPath.js';\n\nexport enum PlaydateSdkVersionIdentifier {\n Latest = 'latest',\n}\n\nexport type PlaydateSdkVersion = PlaydateSdkVersionIdentifier.Latest | string;\n\nexport type EnvironmentHealthResult =\n | {\n isHealthy: true;\n environment: Environment;\n health: EnvironmentHealth;\n }\n | {\n isHealthy: false;\n health: EnvironmentHealth;\n };\n\nexport enum HealthCheckStatusType {\n Healthy = 'Healthy',\n Unhealthy = 'Unhealthy',\n Unknown = 'Unknown',\n}\n\nexport type HealthCheckStatus<TArgument> =\n | {\n healthStatus:\n | HealthCheckStatusType.Unknown\n | HealthCheckStatusType.Unhealthy;\n }\n | {\n healthStatus: HealthCheckStatusType.Healthy;\n argument: TArgument;\n };\n\nexport interface EnvironmentHealth {\n sdkPathKnown: HealthCheckStatus<PlaydateSdkPath>;\n}\n\nexport type CheckListItem<TResult> = {\n runningDescription: string;\n waitingDescription: string;\n errorDescription: string;\n finishedDescription: (result: TResult) => string;\n runner: () => Promise<TResult> | Promise<false>;\n onFinish?: (result: TResult) => void;\n ready?: boolean;\n};\n\nexport interface ParameterDescription {\n name: string;\n required: boolean;\n}\n\nexport interface PropertyDescription {\n signature: string;\n name: string;\n namespaces: string[];\n docs: string;\n}\n\nexport interface FunctionDescription {\n signature: string;\n name: string;\n namespaces: string[];\n parameters: ParameterDescription[];\n hasSelf: boolean;\n docs: string;\n}\nexport interface ApiObject {\n functions: FunctionDescription[];\n methods: FunctionDescription[];\n properties: PropertyDescription[];\n namespaces: Record<string, ApiObject>;\n}\n\nexport interface ApiDefinitions {\n global: ApiObject;\n}\n\nexport interface ParameterDetails {\n name: string;\n type: string;\n overrideOptions?: Partial<\n Omit<ParameterDeclarationStructure, 'kind' | 'name' | 'type'>\n >;\n}\n\nexport interface PropertyDetails {\n signature: string;\n type: string;\n isStatic?: boolean;\n isReadOnly?: boolean;\n}\n\nexport interface FunctionDetails {\n signature: string;\n parameters: ParameterDetails[];\n returnType: string;\n overrideParameters?: boolean;\n overrideOptions?: Partial<\n FunctionDeclarationStructure | MethodDeclarationStructure\n >;\n}\n\nexport type TypeProviderData = {\n globalStatements: string[];\n statements: string[];\n properties: Record<string, PropertyDetails>;\n functions: Record<string, FunctionDetails>;\n};\n"],"names":["PlaydateSdkVersionIdentifier","HealthCheckStatusType"],"rangeMappings":";;;;;;;;;","mappings":";UAQYA;;GAAAA,iCAAAA;;UAiBAC;;;;GAAAA,0BAAAA"}
@@ -1,4 +0,0 @@
1
- import { ModuleDeclaration, SourceFile } from 'ts-morph';
2
- import { createTypeProvider } from '../../../commands/GenerateTypes/utils/createTypeProvider.js';
3
- import { FunctionDescription } from '../../../types.js';
4
- export declare const generateFunction: (func: FunctionDescription, subject: SourceFile | ModuleDeclaration, typeProvider: ReturnType<typeof createTypeProvider>) => void;
@@ -1,27 +0,0 @@
1
- import { _ as _extends } from "@swc/helpers/_/_extends";
2
- import { TypescriptReservedNamed } from '../../../constants.js';
3
- export const generateFunction = (func, subject, typeProvider)=>{
4
- const isReserved = TypescriptReservedNamed.includes(func.name);
5
- const name = isReserved ? `_${func.name}` : func.name;
6
- var _typeProvider_getFunctionOverrideOptions;
7
- subject.addFunction(_extends({
8
- name,
9
- docs: [
10
- func.docs
11
- ],
12
- returnType: typeProvider.getFunctionReturnType(func),
13
- parameters: typeProvider.getParameters(func)
14
- }, (_typeProvider_getFunctionOverrideOptions = typeProvider.getFunctionOverrideOptions(func)) != null ? _typeProvider_getFunctionOverrideOptions : {}));
15
- if (isReserved) {
16
- subject.addExportDeclaration({
17
- namedExports: [
18
- {
19
- name,
20
- alias: func.name
21
- }
22
- ]
23
- });
24
- }
25
- };
26
-
27
- //# sourceMappingURL=generateFunction.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../../../../libs/cli/src/commands/GenerateTypes/fn/generateFunction.ts"],"sourcesContent":["import {\n FunctionDeclarationStructure,\n ModuleDeclaration,\n SourceFile,\n} from 'ts-morph';\nimport { createTypeProvider } from '@/cli/commands/GenerateTypes/utils/createTypeProvider.js';\nimport { TypescriptReservedNamed } from '@/cli/constants.js';\nimport { FunctionDescription } from '@/cli/types.js';\n\nexport const generateFunction = (\n func: FunctionDescription,\n subject: SourceFile | ModuleDeclaration,\n typeProvider: ReturnType<typeof createTypeProvider>\n) => {\n const isReserved = TypescriptReservedNamed.includes(func.name);\n\n const name = isReserved ? `_${func.name}` : func.name;\n\n subject.addFunction({\n name,\n docs: [func.docs],\n returnType: typeProvider.getFunctionReturnType(func),\n parameters: typeProvider.getParameters(func),\n ...((typeProvider.getFunctionOverrideOptions(\n func\n ) as Partial<FunctionDeclarationStructure>) ?? {}),\n });\n\n if (isReserved) {\n subject.addExportDeclaration({\n namedExports: [\n {\n name,\n alias: func.name,\n },\n ],\n });\n }\n};\n"],"names":["TypescriptReservedNamed","generateFunction","func","subject","typeProvider","isReserved","includes","name","addFunction","docs","returnType","getFunctionReturnType","parameters","getParameters","getFunctionOverrideOptions","addExportDeclaration","namedExports","alias"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;","mappings":";AAMA,SAASA,uBAAuB,QAAQ,qBAAqB;AAG7D,OAAO,MAAMC,mBAAmB,CAC5BC,MACAC,SACAC;IAEA,MAAMC,aAAaL,wBAAwBM,QAAQ,CAACJ,KAAKK,IAAI;IAE7D,MAAMA,OAAOF,aAAa,CAAC,CAAC,EAAEH,KAAKK,IAAI,CAAC,CAAC,GAAGL,KAAKK,IAAI;QAO5CH;IALTD,QAAQK,WAAW,CAAC;QAChBD;QACAE,MAAM;YAACP,KAAKO,IAAI;SAAC;QACjBC,YAAYN,aAAaO,qBAAqB,CAACT;QAC/CU,YAAYR,aAAaS,aAAa,CAACX;OACnC,CAACE,2CAAAA,aAAaU,0BAA0B,CACxCZ,iBADCE,2CAE0C,CAAC;IAGpD,IAAIC,YAAY;QACZF,QAAQY,oBAAoB,CAAC;YACzBC,cAAc;gBACV;oBACIT;oBACAU,OAAOf,KAAKK,IAAI;gBACpB;aACH;QACL;IACJ;AACJ,EAAE"}
@@ -1,4 +0,0 @@
1
- import { ClassDeclaration, ModuleDeclaration, SourceFile } from 'ts-morph';
2
- import { createTypeProvider } from '../../../commands/GenerateTypes/utils/createTypeProvider.js';
3
- import { PlaydateNamespace, PlaydateType } from '../../../types.js';
4
- export declare const generateNamespace: (namespaceDescription: PlaydateNamespace, namespaces: string[], subjects: Map<string, SourceFile | ModuleDeclaration>, typeSubjects: Map<string, ClassDeclaration>, typeProvider: ReturnType<typeof createTypeProvider>, types: Record<string, PlaydateType>) => void;
@@ -1,81 +0,0 @@
1
- import { _ as _extends } from "@swc/helpers/_/_extends";
2
- import { VariableDeclarationKind } from 'ts-morph';
3
- import { generateFunction } from '../../../commands/GenerateTypes/fn/generateFunction.js';
4
- export const generateNamespace = (namespaceDescription, namespaces, subjects, typeSubjects, typeProvider, types)=>{
5
- const subjectName = namespaces.slice(0, -1).join('.');
6
- const namespaceName = namespaces[namespaces.length - 1];
7
- const isRoot = namespaces.length === 1 && namespaces[0] === 'playdate';
8
- const subject = namespaces.length <= 1 ? subjects.get('root') : subjects.get(subjectName);
9
- if (!subject) {
10
- return;
11
- }
12
- const module = namespaces.length > 0 ? subject.addModule({
13
- name: namespaceName
14
- }) : subject;
15
- const addMethods = (typeName, subj, methods)=>{
16
- const interfaceName = typeName.split('.').map((name)=>name[0].toUpperCase() + name.slice(1)).join('');
17
- const typeClass = subj.addClass({
18
- name: interfaceName
19
- });
20
- typeSubjects.set(typeName, typeClass);
21
- for (const func of methods){
22
- const parameters = typeProvider.getParameters(func);
23
- typeClass.addMethod(_extends({
24
- name: func.name,
25
- docs: [
26
- func.docs
27
- ],
28
- returnType: typeProvider.getFunctionReturnType(func),
29
- parameters
30
- }, typeProvider.getFunctionOverrideOptions(func)));
31
- }
32
- };
33
- if (isRoot && 'addJsDoc' in module) {
34
- module.addJsDoc({
35
- description: 'Playdate SDK'
36
- });
37
- module.addStatements(typeProvider.getStatements());
38
- Object.keys(types).forEach((eachType)=>{
39
- addMethods(eachType, module, types[eachType].methods);
40
- });
41
- }
42
- if (namespaces.length > 0) {
43
- subjects.set(namespaces.join('.'), module);
44
- }
45
- if (namespaceDescription.methods.length > 0) {
46
- addMethods(namespaces.join('.'), subjects.get('playdate'), namespaceDescription.methods);
47
- }
48
- for (const property of namespaceDescription.properties){
49
- const propertyDetails = typeProvider.getPropertyDetails(property);
50
- if (!propertyDetails.isStatic) {
51
- const typeName = namespaces.join('.');
52
- if (typeSubjects.has(typeName)) {
53
- const typeInterface = typeSubjects.get(typeName);
54
- typeInterface.addProperty({
55
- name: property.name,
56
- type: propertyDetails.type,
57
- docs: [
58
- property.docs
59
- ],
60
- isReadonly: propertyDetails.isReadOnly
61
- });
62
- }
63
- continue;
64
- }
65
- const propertyType = propertyDetails.type;
66
- module.addVariableStatement({
67
- declarationKind: VariableDeclarationKind.Const,
68
- declarations: [
69
- {
70
- name: property.name,
71
- type: propertyType
72
- }
73
- ]
74
- });
75
- }
76
- for (const func of namespaceDescription.functions){
77
- generateFunction(func, module, typeProvider);
78
- }
79
- };
80
-
81
- //# sourceMappingURL=generateNamespace.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../../../../libs/cli/src/commands/GenerateTypes/fn/generateNamespace.ts"],"sourcesContent":["import {\n ClassDeclaration,\n MethodDeclarationStructure,\n ModuleDeclaration,\n SourceFile,\n VariableDeclarationKind,\n} from 'ts-morph';\nimport { generateFunction } from '@/cli/commands/GenerateTypes/fn/generateFunction.js';\nimport { createTypeProvider } from '@/cli/commands/GenerateTypes/utils/createTypeProvider.js';\nimport {\n FunctionDescription,\n PlaydateNamespace,\n PlaydateType,\n} from '@/cli/types.js';\n\nexport const generateNamespace = (\n namespaceDescription: PlaydateNamespace,\n namespaces: string[],\n subjects: Map<string, SourceFile | ModuleDeclaration>,\n typeSubjects: Map<string, ClassDeclaration>,\n typeProvider: ReturnType<typeof createTypeProvider>,\n types: Record<string, PlaydateType>\n) => {\n const subjectName = namespaces.slice(0, -1).join('.');\n const namespaceName = namespaces[namespaces.length - 1];\n const isRoot = namespaces.length === 1 && namespaces[0] === 'playdate';\n const subject =\n namespaces.length <= 1\n ? subjects.get('root')\n : subjects.get(subjectName);\n\n if (!subject) {\n return;\n }\n\n const module =\n namespaces.length > 0\n ? subject.addModule({\n name: namespaceName,\n })\n : subject;\n\n const addMethods = (\n typeName: string,\n subj: ModuleDeclaration,\n methods: FunctionDescription[]\n ) => {\n const interfaceName = typeName\n .split('.')\n .map((name) => name[0].toUpperCase() + name.slice(1))\n .join('');\n const typeClass = subj.addClass({\n name: interfaceName,\n });\n typeSubjects.set(typeName, typeClass);\n\n for (const func of methods) {\n const parameters = typeProvider.getParameters(func);\n\n typeClass.addMethod({\n name: func.name,\n docs: [func.docs],\n returnType: typeProvider.getFunctionReturnType(func),\n parameters,\n ...(typeProvider.getFunctionOverrideOptions(\n func\n ) as Partial<MethodDeclarationStructure>),\n });\n }\n };\n\n if (isRoot && 'addJsDoc' in module) {\n module.addJsDoc({\n description: 'Playdate SDK',\n });\n module.addStatements(typeProvider.getStatements());\n\n Object.keys(types).forEach((eachType) => {\n addMethods(eachType, module, types[eachType].methods);\n });\n }\n\n if (namespaces.length > 0) {\n subjects.set(namespaces.join('.'), module);\n }\n\n if (namespaceDescription.methods.length > 0) {\n addMethods(\n namespaces.join('.'),\n subjects.get('playdate') as ModuleDeclaration,\n namespaceDescription.methods\n );\n }\n\n for (const property of namespaceDescription.properties) {\n const propertyDetails = typeProvider.getPropertyDetails(property);\n if (!propertyDetails.isStatic) {\n const typeName = namespaces.join('.');\n\n if (typeSubjects.has(typeName)) {\n const typeInterface = typeSubjects.get(\n typeName\n ) as ClassDeclaration;\n\n typeInterface.addProperty({\n name: property.name,\n type: propertyDetails.type,\n docs: [property.docs],\n isReadonly: propertyDetails.isReadOnly,\n });\n }\n\n continue;\n }\n\n const propertyType = propertyDetails.type;\n\n module.addVariableStatement({\n declarationKind: VariableDeclarationKind.Const,\n declarations: [\n {\n name: property.name,\n type: propertyType,\n },\n ],\n });\n }\n\n for (const func of namespaceDescription.functions) {\n generateFunction(func, module, typeProvider);\n }\n};\n"],"names":["VariableDeclarationKind","generateFunction","generateNamespace","namespaceDescription","namespaces","subjects","typeSubjects","typeProvider","types","subjectName","slice","join","namespaceName","length","isRoot","subject","get","module","addModule","name","addMethods","typeName","subj","methods","interfaceName","split","map","toUpperCase","typeClass","addClass","set","func","parameters","getParameters","addMethod","docs","returnType","getFunctionReturnType","getFunctionOverrideOptions","addJsDoc","description","addStatements","getStatements","Object","keys","forEach","eachType","property","properties","propertyDetails","getPropertyDetails","isStatic","has","typeInterface","addProperty","type","isReadonly","isReadOnly","propertyType","addVariableStatement","declarationKind","Const","declarations","functions"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";AAAA,SAKIA,uBAAuB,QACpB,WAAW;AAClB,SAASC,gBAAgB,QAAQ,sDAAsD;AAQvF,OAAO,MAAMC,oBAAoB,CAC7BC,sBACAC,YACAC,UACAC,cACAC,cACAC;IAEA,MAAMC,cAAcL,WAAWM,KAAK,CAAC,GAAG,CAAC,GAAGC,IAAI,CAAC;IACjD,MAAMC,gBAAgBR,UAAU,CAACA,WAAWS,MAAM,GAAG,EAAE;IACvD,MAAMC,SAASV,WAAWS,MAAM,KAAK,KAAKT,UAAU,CAAC,EAAE,KAAK;IAC5D,MAAMW,UACFX,WAAWS,MAAM,IAAI,IACfR,SAASW,GAAG,CAAC,UACbX,SAASW,GAAG,CAACP;IAEvB,IAAI,CAACM,SAAS;QACV;IACJ;IAEA,MAAME,SACFb,WAAWS,MAAM,GAAG,IACdE,QAAQG,SAAS,CAAC;QACdC,MAAMP;IACV,KACAG;IAEV,MAAMK,aAAa,CACfC,UACAC,MACAC;QAEA,MAAMC,gBAAgBH,SACjBI,KAAK,CAAC,KACNC,GAAG,CAAC,CAACP,OAASA,IAAI,CAAC,EAAE,CAACQ,WAAW,KAAKR,KAAKT,KAAK,CAAC,IACjDC,IAAI,CAAC;QACV,MAAMiB,YAAYN,KAAKO,QAAQ,CAAC;YAC5BV,MAAMK;QACV;QACAlB,aAAawB,GAAG,CAACT,UAAUO;QAE3B,KAAK,MAAMG,QAAQR,QAAS;YACxB,MAAMS,aAAazB,aAAa0B,aAAa,CAACF;YAE9CH,UAAUM,SAAS,CAAC;gBAChBf,MAAMY,KAAKZ,IAAI;gBACfgB,MAAM;oBAACJ,KAAKI,IAAI;iBAAC;gBACjBC,YAAY7B,aAAa8B,qBAAqB,CAACN;gBAC/C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