@platformos/platformos-common 0.0.2

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/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # @platformos/platformos-common
2
+
3
+ ## 0.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Beta release
@@ -0,0 +1,25 @@
1
+ /**
2
+ * The AbstractFileSystem interface is used to abstract file system operations.
3
+ *
4
+ * This way, the Theme Check library can be used in different environments,
5
+ * such as the browser, node.js or VS Code (which works with local files, remote
6
+ * files and on the web)
7
+ */
8
+ export interface AbstractFileSystem {
9
+ stat(uri: string): Promise<FileStat>;
10
+ readFile(uri: string): Promise<string>;
11
+ readDirectory(uri: string): Promise<FileTuple[]>;
12
+ }
13
+ export declare enum FileType {
14
+ Unknown = 0,
15
+ File = 1,
16
+ Directory = 2,
17
+ SymbolicLink = 64
18
+ }
19
+ export interface FileStat {
20
+ type: FileType;
21
+ size: number;
22
+ }
23
+ /** A vscode-uri string */
24
+ export type UriString = string;
25
+ export type FileTuple = [uri: UriString, fileType: FileType];
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FileType = void 0;
4
+ var FileType;
5
+ (function (FileType) {
6
+ FileType[FileType["Unknown"] = 0] = "Unknown";
7
+ FileType[FileType["File"] = 1] = "File";
8
+ FileType[FileType["Directory"] = 2] = "Directory";
9
+ FileType[FileType["SymbolicLink"] = 64] = "SymbolicLink";
10
+ })(FileType || (exports.FileType = FileType = {}));
11
+ //# sourceMappingURL=AbstractFileSystem.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AbstractFileSystem.js","sourceRoot":"","sources":["../src/AbstractFileSystem.ts"],"names":[],"mappings":";;;AAaA,IAAY,QAKX;AALD,WAAY,QAAQ;IAClB,6CAAW,CAAA;IACX,uCAAQ,CAAA;IACR,iDAAa,CAAA;IACb,wDAAiB,CAAA;AACnB,CAAC,EALW,QAAQ,wBAAR,QAAQ,QAKnB"}
@@ -0,0 +1,14 @@
1
+ import { AbstractFileSystem } from '../AbstractFileSystem';
2
+ import { URI } from 'vscode-uri';
3
+ export type DocumentType = 'function' | 'render' | 'include' | 'graphql' | 'asset';
4
+ export declare class DocumentsLocator {
5
+ private readonly fs;
6
+ constructor(fs: AbstractFileSystem);
7
+ private isFile;
8
+ private parseModulePath;
9
+ private getSearchPaths;
10
+ private locateFile;
11
+ private listFiles;
12
+ locate(rootUri: URI, nodeName: DocumentType, fileName: string): Promise<string | undefined>;
13
+ list(rootUri: URI, nodeName: string | undefined, filePrefix: string): Promise<string[]>;
14
+ }
@@ -0,0 +1,171 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DocumentsLocator = void 0;
4
+ const AbstractFileSystem_1 = require("../AbstractFileSystem");
5
+ const vscode_uri_1 = require("vscode-uri");
6
+ class DocumentsLocator {
7
+ constructor(fs) {
8
+ this.fs = fs;
9
+ }
10
+ async isFile(path) {
11
+ try {
12
+ return (await this.fs.stat(path)).type === AbstractFileSystem_1.FileType.File;
13
+ }
14
+ catch {
15
+ return false;
16
+ }
17
+ }
18
+ parseModulePath(fileName) {
19
+ if (!fileName.startsWith('modules/')) {
20
+ return { isModule: false, key: fileName };
21
+ }
22
+ const [, moduleName, ...rest] = fileName.split('/');
23
+ const key = rest.join('/');
24
+ return moduleName ? { isModule: true, moduleName, key } : { isModule: false, key: fileName };
25
+ }
26
+ getSearchPaths(type, moduleName) {
27
+ if (!moduleName) {
28
+ switch (type) {
29
+ case 'partial':
30
+ return ['app/lib'];
31
+ case 'view':
32
+ return ['app/views/partials'];
33
+ case 'graphql':
34
+ return ['app/graphql'];
35
+ case 'asset':
36
+ return ['app/assets'];
37
+ }
38
+ }
39
+ switch (type) {
40
+ case 'partial':
41
+ return [
42
+ `app/modules/${moduleName}/public/lib`,
43
+ `app/modules/${moduleName}/private/lib`,
44
+ `modules/${moduleName}/public/lib`,
45
+ `modules/${moduleName}/private/lib`,
46
+ ];
47
+ case 'view':
48
+ return [
49
+ `app/modules/${moduleName}/public/views/partials`,
50
+ `app/modules/${moduleName}/private/views/partials`,
51
+ `modules/${moduleName}/public/views/partials`,
52
+ `modules/${moduleName}/private/views/partials`,
53
+ ];
54
+ case 'graphql':
55
+ return [
56
+ `app/modules/${moduleName}/public/graphql`,
57
+ `app/modules/${moduleName}/private/graphql`,
58
+ `modules/${moduleName}/public/graphql`,
59
+ `modules/${moduleName}/private/graphql`,
60
+ ];
61
+ case 'asset':
62
+ return [
63
+ `app/modules/${moduleName}/public/assets`,
64
+ `app/modules/${moduleName}/private/assets`,
65
+ `modules/${moduleName}/public/assets`,
66
+ `modules/${moduleName}/private/assets`,
67
+ ];
68
+ }
69
+ }
70
+ async locateFile(rootUri, fileName, type) {
71
+ const parsed = this.parseModulePath(fileName);
72
+ const searchPaths = this.getSearchPaths(type, parsed.isModule ? parsed.moduleName : undefined);
73
+ let targetFile = parsed.key;
74
+ if (type === 'partial' || type === 'view') {
75
+ targetFile += '.liquid';
76
+ }
77
+ else if (type === 'graphql') {
78
+ targetFile += '.graphql';
79
+ }
80
+ for (const basePath of searchPaths) {
81
+ const uri = vscode_uri_1.Utils.joinPath(rootUri, basePath, targetFile).toString();
82
+ if (await this.isFile(uri)) {
83
+ return uri;
84
+ }
85
+ }
86
+ return undefined;
87
+ }
88
+ async listFiles(rootUri, filePrefix, type) {
89
+ const parsed = this.parseModulePath(filePrefix);
90
+ const searchPaths = this.getSearchPaths(type, parsed.isModule ? parsed.moduleName : undefined);
91
+ const results = new Set();
92
+ const matchesType = (name) => {
93
+ switch (type) {
94
+ case 'partial':
95
+ case 'view':
96
+ return name.endsWith('.liquid');
97
+ case 'graphql':
98
+ return name.endsWith('.graphql');
99
+ case 'asset':
100
+ return true;
101
+ }
102
+ };
103
+ const walk = async (basePath, dirUri) => {
104
+ let entries;
105
+ try {
106
+ entries = await this.fs.readDirectory(dirUri.toString());
107
+ }
108
+ catch {
109
+ return;
110
+ }
111
+ for (const [name, fileType] of entries) {
112
+ if (fileType === AbstractFileSystem_1.FileType.Directory) {
113
+ await walk(basePath, vscode_uri_1.URI.parse(name));
114
+ continue;
115
+ }
116
+ if (fileType !== AbstractFileSystem_1.FileType.File)
117
+ continue;
118
+ if (!matchesType(name))
119
+ continue;
120
+ const parsedName = name.slice(basePath.length);
121
+ if (!parsedName.startsWith('/' + parsed.key))
122
+ continue;
123
+ let result = parsedName.slice(parsed.key.length);
124
+ if ((parsed.key.endsWith('/') || parsed.key === '') && result.startsWith('/'))
125
+ result = result.slice(1);
126
+ if (type !== 'asset') {
127
+ const index = result.lastIndexOf('.');
128
+ result = index === -1 ? result : result.slice(0, index);
129
+ }
130
+ results.add(result);
131
+ }
132
+ };
133
+ for (const basePath of searchPaths) {
134
+ const baseUri = vscode_uri_1.Utils.joinPath(rootUri, basePath);
135
+ await walk(baseUri.toString(), baseUri);
136
+ }
137
+ return Array.from(results).sort((a, b) => a.localeCompare(b));
138
+ }
139
+ async locate(rootUri, nodeName, fileName) {
140
+ switch (nodeName) {
141
+ case 'function':
142
+ return this.locateFile(rootUri, fileName, 'partial');
143
+ case 'render':
144
+ case 'include':
145
+ return this.locateFile(rootUri, fileName, 'view');
146
+ case 'graphql':
147
+ return this.locateFile(rootUri, fileName, 'graphql');
148
+ case 'asset':
149
+ return this.locateFile(rootUri, fileName, 'asset');
150
+ default:
151
+ return undefined;
152
+ }
153
+ }
154
+ async list(rootUri, nodeName, filePrefix) {
155
+ switch (nodeName) {
156
+ case 'function':
157
+ return this.listFiles(rootUri, filePrefix, 'partial');
158
+ case 'render':
159
+ case 'include':
160
+ return this.listFiles(rootUri, filePrefix, 'view');
161
+ case 'graphql':
162
+ return this.listFiles(rootUri, filePrefix, 'graphql');
163
+ case 'asset':
164
+ return this.listFiles(rootUri, filePrefix, 'asset');
165
+ default:
166
+ return [];
167
+ }
168
+ }
169
+ }
170
+ exports.DocumentsLocator = DocumentsLocator;
171
+ //# sourceMappingURL=DocumentsLocator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DocumentsLocator.js","sourceRoot":"","sources":["../../src/documents-locator/DocumentsLocator.ts"],"names":[],"mappings":";;;AAAA,8DAAqE;AACrE,2CAAwC;AAQxC,MAAa,gBAAgB;IAC3B,YAA6B,EAAsB;QAAtB,OAAE,GAAF,EAAE,CAAoB;IAAG,CAAC;IAE/C,KAAK,CAAC,MAAM,CAAC,IAAY;QAC/B,IAAI,CAAC;YACH,OAAO,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,KAAK,6BAAQ,CAAC,IAAI,CAAC;QAC3D,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAEO,eAAe,CAAC,QAAgB;QACtC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;YACrC,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC;QAC5C,CAAC;QAED,MAAM,CAAC,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACpD,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAE3B,OAAO,UAAU,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC;IAC/F,CAAC;IAEO,cAAc,CACpB,IAA8C,EAC9C,UAAmB;QAEnB,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,QAAQ,IAAI,EAAE,CAAC;gBACb,KAAK,SAAS;oBACZ,OAAO,CAAC,SAAS,CAAC,CAAC;gBACrB,KAAK,MAAM;oBAC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KAAK,QAAQ,CAAC;YACd,KAAK,SAAS;gBACZ,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC;YAErD,KAAK,SAAS;gBACZ,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,UAAU,EAAE,SAAS,CAAC,CAAC;YAExD,KAAK,OAAO;gBACV,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;YAEtD;gBACE,OAAO,EAAE,CAAC;QACd,CAAC;IACH,CAAC;CACF;AA1MD,4CA0MC"}
@@ -0,0 +1,4 @@
1
+ export * from './documents-locator/DocumentsLocator';
2
+ export * from './translation-provider/TranslationProvider';
3
+ export * from './AbstractFileSystem';
4
+ export * from './path-utils';
package/dist/index.js ADDED
@@ -0,0 +1,21 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./documents-locator/DocumentsLocator"), exports);
18
+ __exportStar(require("./translation-provider/TranslationProvider"), exports);
19
+ __exportStar(require("./AbstractFileSystem"), exports);
20
+ __exportStar(require("./path-utils"), exports);
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uEAAqD;AACrD,6EAA2D;AAC3D,uDAAqC;AACrC,+CAA6B"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Utility functions for identifying platformOS file types based on their paths
3
+ */
4
+ import { UriString } from './AbstractFileSystem';
5
+ /**
6
+ * Checks if a URI points to a partial file.
7
+ * Partials can be located in:
8
+ * - app/lib
9
+ * - app/views/partials
10
+ * - app/modules/{moduleName}/public/lib
11
+ * - app/modules/{moduleName}/private/lib
12
+ * - app/modules/{moduleName}/public/views/partials
13
+ * - app/modules/{moduleName}/private/views/partials
14
+ * - modules/{moduleName}/public/lib
15
+ * - modules/{moduleName}/private/lib
16
+ * - modules/{moduleName}/public/views/partials
17
+ * - modules/{moduleName}/private/views/partials
18
+ */
19
+ export declare function isPartial(uri: UriString): boolean;
20
+ /**
21
+ * Checks if a URI points to a page file.
22
+ * Pages are located in app/views/pages
23
+ */
24
+ export declare function isPage(uri: UriString): boolean;
25
+ /**
26
+ * Checks if a URI points to a layout file.
27
+ * Layouts are located in app/views/layouts
28
+ */
29
+ export declare function isLayout(uri: UriString): boolean;
30
+ /**
31
+ * Legacy Shopify terminology - use isPartial instead
32
+ * @deprecated Use isPartial instead
33
+ */
34
+ export declare const isSnippet: typeof isPartial;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ /**
3
+ * Utility functions for identifying platformOS file types based on their paths
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.isSnippet = void 0;
7
+ exports.isPartial = isPartial;
8
+ exports.isPage = isPage;
9
+ exports.isLayout = isLayout;
10
+ /**
11
+ * Checks if a URI points to a partial file.
12
+ * Partials can be located in:
13
+ * - app/lib
14
+ * - app/views/partials
15
+ * - app/modules/{moduleName}/public/lib
16
+ * - app/modules/{moduleName}/private/lib
17
+ * - app/modules/{moduleName}/public/views/partials
18
+ * - app/modules/{moduleName}/private/views/partials
19
+ * - modules/{moduleName}/public/lib
20
+ * - modules/{moduleName}/private/lib
21
+ * - modules/{moduleName}/public/views/partials
22
+ * - modules/{moduleName}/private/views/partials
23
+ */
24
+ function isPartial(uri) {
25
+ return uri.includes('/lib/') || uri.includes('/views/partials');
26
+ }
27
+ /**
28
+ * Checks if a URI points to a page file.
29
+ * Pages are located in app/views/pages
30
+ */
31
+ function isPage(uri) {
32
+ return uri.includes('/views/pages');
33
+ }
34
+ /**
35
+ * Checks if a URI points to a layout file.
36
+ * Layouts are located in app/views/layouts
37
+ */
38
+ function isLayout(uri) {
39
+ return uri.includes('/views/layouts');
40
+ }
41
+ /**
42
+ * Legacy Shopify terminology - use isPartial instead
43
+ * @deprecated Use isPartial instead
44
+ */
45
+ exports.isSnippet = isPartial;
46
+ //# sourceMappingURL=path-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"path-utils.js","sourceRoot":"","sources":["../src/path-utils.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAkBH,8BAEC;AAMD,wBAEC;AAMD,4BAEC;AAhCD;;;;;;;;;;;;;GAaG;AACH,SAAgB,SAAS,CAAC,GAAc;IACtC,OAAO,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC;AAClE,CAAC;AAED;;;GAGG;AACH,SAAgB,MAAM,CAAC,GAAc;IACnC,OAAO,GAAG,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC;AACtC,CAAC;AAED;;;GAGG;AACH,SAAgB,QAAQ,CAAC,GAAc;IACrC,OAAO,GAAG,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAC;AACxC,CAAC;AAED;;;GAGG;AACU,QAAA,SAAS,GAAG,SAAS,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { AbstractFileSystem } from '../AbstractFileSystem';
2
+ import { URI } from 'vscode-uri';
3
+ export declare class TranslationProvider {
4
+ private readonly fs;
5
+ constructor(fs: AbstractFileSystem);
6
+ private isFile;
7
+ private readFileIfExists;
8
+ private parseModuleKey;
9
+ private getSearchPaths;
10
+ findTranslationFile(rootUri: URI, translationKey: string, defaultLocale: string): Promise<[string | undefined, string | undefined]>;
11
+ translate(rootUri: URI, translationKey: string, defaultLocale?: string): Promise<string | undefined>;
12
+ }
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.TranslationProvider = void 0;
7
+ const AbstractFileSystem_1 = require("../AbstractFileSystem");
8
+ const vscode_uri_1 = require("vscode-uri");
9
+ const js_yaml_1 = __importDefault(require("js-yaml"));
10
+ class TranslationProvider {
11
+ constructor(fs) {
12
+ this.fs = fs;
13
+ }
14
+ async isFile(path) {
15
+ try {
16
+ return (await this.fs.stat(path)).type === AbstractFileSystem_1.FileType.File;
17
+ }
18
+ catch {
19
+ return false;
20
+ }
21
+ }
22
+ async readFileIfExists(path) {
23
+ return (await this.isFile(path)) ? this.fs.readFile(path) : undefined;
24
+ }
25
+ parseModuleKey(translationKey) {
26
+ if (!translationKey.startsWith('modules/')) {
27
+ return { isModule: false, key: translationKey };
28
+ }
29
+ const [, moduleName, key] = translationKey.split('/', 3);
30
+ return key ? { isModule: true, moduleName, key } : { isModule: false, key: translationKey };
31
+ }
32
+ getSearchPaths(moduleName) {
33
+ if (!moduleName) {
34
+ return ['app/translations'];
35
+ }
36
+ return [
37
+ `app/modules/${moduleName}/public/translations`,
38
+ `app/modules/${moduleName}/private/translations`,
39
+ `modules/${moduleName}/public/translations`,
40
+ `modules/${moduleName}/private/translations`,
41
+ ];
42
+ }
43
+ async findTranslationFile(rootUri, translationKey, defaultLocale) {
44
+ const parsed = this.parseModuleKey(translationKey);
45
+ const fileName = parsed.key.split('.')[0];
46
+ if (!fileName) {
47
+ return [undefined, undefined];
48
+ }
49
+ const searchPaths = this.getSearchPaths(parsed.isModule ? parsed.moduleName : undefined);
50
+ for (const basePath of searchPaths) {
51
+ const uri = vscode_uri_1.Utils.joinPath(rootUri, basePath, defaultLocale, `${fileName}.yml`).toString();
52
+ if (await this.isFile(uri)) {
53
+ return [uri, parsed.key];
54
+ }
55
+ }
56
+ return [undefined, undefined];
57
+ }
58
+ async translate(rootUri, translationKey, defaultLocale = 'en') {
59
+ const [file, key] = await this.findTranslationFile(rootUri, translationKey, defaultLocale);
60
+ if (!file || !key) {
61
+ return undefined;
62
+ }
63
+ const contents = await this.readFileIfExists(file);
64
+ if (!contents) {
65
+ return undefined;
66
+ }
67
+ let data = js_yaml_1.default.load(contents);
68
+ for (const part of [defaultLocale, ...key.split('.')]) {
69
+ data = data?.[part];
70
+ if (data === undefined) {
71
+ return undefined;
72
+ }
73
+ }
74
+ return data;
75
+ }
76
+ }
77
+ exports.TranslationProvider = TranslationProvider;
78
+ //# sourceMappingURL=TranslationProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TranslationProvider.js","sourceRoot":"","sources":["../../src/translation-provider/TranslationProvider.ts"],"names":[],"mappings":";;;;;;AAAA,8DAAqE;AACrE,2CAAwC;AACxC,sDAA2B;AAM3B,MAAa,mBAAmB;IAC9B,YAA6B,EAAsB;QAAtB,OAAE,GAAF,EAAE,CAAoB;IAAG,CAAC;IAE/C,KAAK,CAAC,MAAM,CAAC,IAAY;QAC/B,IAAI,CAAC;YACH,OAAO,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,KAAK,6BAAQ,CAAC,IAAI,CAAC;QAC3D,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAEO,KAAK,CAAC,gBAAgB,CAAC,IAAY;QACzC,OAAO,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CA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