powersync 0.9.2 → 0.9.3

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.
Files changed (141) hide show
  1. package/README.md +103 -74
  2. package/bin/dev.js +7 -1
  3. package/dist/api/BaseDeployCommand.d.ts +39 -0
  4. package/dist/api/BaseDeployCommand.js +230 -0
  5. package/dist/api/BaseDeployCommand.js.map +1 -0
  6. package/dist/api/build-service-yaml.d.ts +29 -0
  7. package/dist/api/build-service-yaml.js +246 -0
  8. package/dist/api/build-service-yaml.js.map +1 -0
  9. package/dist/api/cloud/create-cloud-instance.js +1 -0
  10. package/dist/api/cloud/create-cloud-instance.js.map +1 -0
  11. package/dist/api/cloud/create-cloud-template.d.ts +15 -0
  12. package/dist/api/cloud/create-cloud-template.js +33 -0
  13. package/dist/api/cloud/create-cloud-template.js.map +1 -0
  14. package/dist/api/cloud/fetch-cloud-config.js +1 -0
  15. package/dist/api/cloud/fetch-cloud-config.js.map +1 -0
  16. package/dist/api/cloud/fetch-cloud-sync-rules-content.js +6 -7
  17. package/dist/api/cloud/fetch-cloud-sync-rules-content.js.map +1 -0
  18. package/dist/api/cloud/test-connection.js +3 -3
  19. package/dist/api/cloud/test-connection.js.map +1 -0
  20. package/dist/api/cloud/validate-cloud-link-config.js +1 -0
  21. package/dist/api/cloud/validate-cloud-link-config.js.map +1 -0
  22. package/dist/api/cloud/wait-for-operation.js +1 -0
  23. package/dist/api/cloud/wait-for-operation.js.map +1 -0
  24. package/dist/api/cloud/write-cloud-link.js +1 -0
  25. package/dist/api/cloud/write-cloud-link.js.map +1 -0
  26. package/dist/api/display-status.js +1 -0
  27. package/dist/api/display-status.js.map +1 -0
  28. package/dist/api/ide/configure-vscode-ide.js +1 -0
  29. package/dist/api/ide/configure-vscode-ide.js.map +1 -0
  30. package/dist/api/login-server.js +1 -0
  31. package/dist/api/login-server.js.map +1 -0
  32. package/dist/api/parse-local-cloud-service-config.d.ts +13 -0
  33. package/dist/api/parse-local-cloud-service-config.js +35 -0
  34. package/dist/api/parse-local-cloud-service-config.js.map +1 -0
  35. package/dist/api/self-hosted/fetch-self-hosted-sync-rules-content.js +7 -8
  36. package/dist/api/self-hosted/fetch-self-hosted-sync-rules-content.js.map +1 -0
  37. package/dist/api/validations/ValidationTestDefinition.d.ts +23 -0
  38. package/dist/api/validations/ValidationTestDefinition.js +10 -0
  39. package/dist/api/validations/ValidationTestDefinition.js.map +1 -0
  40. package/dist/api/validations/ValidationsRunner.d.ts +35 -0
  41. package/dist/api/validations/ValidationsRunner.js +82 -0
  42. package/dist/api/validations/ValidationsRunner.js.map +1 -0
  43. package/dist/api/validations/cloud-validations.d.ts +15 -0
  44. package/dist/api/validations/cloud-validations.js +120 -0
  45. package/dist/api/validations/cloud-validations.js.map +1 -0
  46. package/dist/api/validations/self-hosted-validations.d.ts +7 -0
  47. package/dist/api/validations/self-hosted-validations.js +25 -0
  48. package/dist/api/validations/self-hosted-validations.js.map +1 -0
  49. package/dist/api/validations/validation-flags.d.ts +38 -0
  50. package/dist/api/validations/validation-flags.js +77 -0
  51. package/dist/api/validations/validation-flags.js.map +1 -0
  52. package/dist/api/validations/validation-utils.d.ts +46 -0
  53. package/dist/api/validations/validation-utils.js +154 -0
  54. package/dist/api/validations/validation-utils.js.map +1 -0
  55. package/dist/api/validations/validations.d.ts +15 -0
  56. package/dist/api/validations/validations.js +102 -0
  57. package/dist/api/validations/validations.js.map +1 -0
  58. package/dist/commands/configure/ide.js +1 -0
  59. package/dist/commands/configure/ide.js.map +1 -0
  60. package/dist/commands/configure/index.js +1 -0
  61. package/dist/commands/configure/index.js.map +1 -0
  62. package/dist/commands/deploy/index.d.ts +5 -41
  63. package/dist/commands/deploy/index.js +69 -279
  64. package/dist/commands/deploy/index.js.map +1 -0
  65. package/dist/commands/deploy/service-config.d.ts +3 -7
  66. package/dist/commands/deploy/service-config.js +30 -7
  67. package/dist/commands/deploy/service-config.js.map +1 -0
  68. package/dist/commands/deploy/sync-config.d.ts +5 -8
  69. package/dist/commands/deploy/sync-config.js +43 -20
  70. package/dist/commands/deploy/sync-config.js.map +1 -0
  71. package/dist/commands/destroy.d.ts +0 -4
  72. package/dist/commands/destroy.js +2 -2
  73. package/dist/commands/destroy.js.map +1 -0
  74. package/dist/commands/fetch/config.d.ts +0 -4
  75. package/dist/commands/fetch/config.js +2 -2
  76. package/dist/commands/fetch/config.js.map +1 -0
  77. package/dist/commands/fetch/index.js +1 -0
  78. package/dist/commands/fetch/index.js.map +1 -0
  79. package/dist/commands/fetch/instances.js +1 -0
  80. package/dist/commands/fetch/instances.js.map +1 -0
  81. package/dist/commands/fetch/status.d.ts +0 -5
  82. package/dist/commands/fetch/status.js +2 -2
  83. package/dist/commands/fetch/status.js.map +1 -0
  84. package/dist/commands/generate/index.js +1 -0
  85. package/dist/commands/generate/index.js.map +1 -0
  86. package/dist/commands/generate/schema.d.ts +3 -6
  87. package/dist/commands/generate/schema.js +5 -5
  88. package/dist/commands/generate/schema.js.map +1 -0
  89. package/dist/commands/generate/token.d.ts +0 -5
  90. package/dist/commands/generate/token.js +2 -2
  91. package/dist/commands/generate/token.js.map +1 -0
  92. package/dist/commands/init/cloud.d.ts +0 -3
  93. package/dist/commands/init/cloud.js +21 -18
  94. package/dist/commands/init/cloud.js.map +1 -0
  95. package/dist/commands/init/index.js +1 -0
  96. package/dist/commands/init/index.js.map +1 -0
  97. package/dist/commands/init/self-hosted.d.ts +0 -3
  98. package/dist/commands/init/self-hosted.js +29 -6
  99. package/dist/commands/init/self-hosted.js.map +1 -0
  100. package/dist/commands/link/cloud.d.ts +0 -1
  101. package/dist/commands/link/cloud.js +3 -3
  102. package/dist/commands/link/cloud.js.map +1 -0
  103. package/dist/commands/link/index.js +1 -0
  104. package/dist/commands/link/index.js.map +1 -0
  105. package/dist/commands/link/self-hosted.d.ts +0 -1
  106. package/dist/commands/link/self-hosted.js +3 -3
  107. package/dist/commands/link/self-hosted.js.map +1 -0
  108. package/dist/commands/login.js +1 -0
  109. package/dist/commands/login.js.map +1 -0
  110. package/dist/commands/logout.js +1 -0
  111. package/dist/commands/logout.js.map +1 -0
  112. package/dist/commands/migrate/index.js +1 -0
  113. package/dist/commands/migrate/index.js.map +1 -0
  114. package/dist/commands/migrate/sync-rules.d.ts +0 -5
  115. package/dist/commands/migrate/sync-rules.js +2 -2
  116. package/dist/commands/migrate/sync-rules.js.map +1 -0
  117. package/dist/commands/pull/index.js +1 -0
  118. package/dist/commands/pull/index.js.map +1 -0
  119. package/dist/commands/pull/instance.d.ts +1 -4
  120. package/dist/commands/pull/instance.js +26 -12
  121. package/dist/commands/pull/instance.js.map +1 -0
  122. package/dist/commands/status.js +1 -0
  123. package/dist/commands/status.js.map +1 -0
  124. package/dist/commands/stop.d.ts +0 -4
  125. package/dist/commands/stop.js +2 -2
  126. package/dist/commands/stop.js.map +1 -0
  127. package/dist/commands/validate.d.ts +4 -8
  128. package/dist/commands/validate.js +50 -128
  129. package/dist/commands/validate.js.map +1 -0
  130. package/dist/help.js +1 -0
  131. package/dist/help.js.map +1 -0
  132. package/dist/index.js +1 -0
  133. package/dist/index.js.map +1 -0
  134. package/oclif.manifest.json +263 -161
  135. package/package.json +10 -9
  136. package/templates/cloud/powersync/service.template.yaml +164 -0
  137. package/templates/self-hosted/base/powersync/service.template.yaml +209 -0
  138. package/dist/api/run-validation-tests.d.ts +0 -63
  139. package/dist/api/run-validation-tests.js +0 -202
  140. package/templates/cloud/powersync/service.yaml +0 -174
  141. package/templates/self-hosted/base/powersync/service.yaml +0 -243
@@ -0,0 +1,230 @@
1
+ import { Flags, ux } from '@oclif/core';
2
+ import { CloudInstanceCommand, SERVICE_FILENAME } from '@powersync/cli-core';
3
+ import { AdditionalCloudConfigFields } from '@powersync/cli-schemas';
4
+ import ora from 'ora';
5
+ import { DEFAULT_DEPLOY_TIMEOUT_MS, waitForOperationStatusChange } from './cloud/wait-for-operation.js';
6
+ import { parseLocalCloudServiceConfig } from './parse-local-cloud-service-config.js';
7
+ export default class BaseDeployCommand extends CloudInstanceCommand {
8
+ static baseFlags = {
9
+ 'deploy-timeout': Flags.integer({
10
+ default: DEFAULT_DEPLOY_TIMEOUT_MS / 1000,
11
+ description: 'Seconds to wait after scheduling a deploy before timing out while polling status (default 300 seconds).',
12
+ async parse(input) {
13
+ const value = Number(input);
14
+ if (!Number.isFinite(value) || value <= 0) {
15
+ throw new Error('deploy-timeout must be a positive number of seconds');
16
+ }
17
+ return value;
18
+ }
19
+ }),
20
+ ...CloudInstanceCommand.baseFlags
21
+ };
22
+ async deployAll(params) {
23
+ const { cloudConfigState, deployTimeoutMs, updateSyncConfig } = params;
24
+ return this.withDeploy(deployTimeoutMs, async () => this.deployInstanceConfig({
25
+ cloudConfigState,
26
+ updateSyncConfig
27
+ }));
28
+ }
29
+ async deployInstanceConfig(params) {
30
+ const { cloudConfigState, updateSyncConfig } = params;
31
+ const { client, project } = this;
32
+ const { linked, syncRulesContent } = project;
33
+ const config = this.serviceConfig;
34
+ if (!config) {
35
+ this.styledError({
36
+ message: `Service config not loaded. Ensure ${SERVICE_FILENAME} is present and valid.`
37
+ });
38
+ }
39
+ // We don't want to add the additional fields which specify the cli cloud config.
40
+ const filteredConfig = Object.fromEntries(Object.entries(config).filter(([key]) => !Object.keys(AdditionalCloudConfigFields.props.shape).includes(key)));
41
+ return client.deployInstance({
42
+ app_id: linked.project_id,
43
+ config: filteredConfig,
44
+ id: cloudConfigState.id,
45
+ name: config.name,
46
+ org_id: linked.org_id,
47
+ // TODO Should we allow specifying these in the config file?
48
+ program_version: cloudConfigState.program_version,
49
+ sync_rules: updateSyncConfig ? syncRulesContent : cloudConfigState.sync_rules
50
+ });
51
+ }
52
+ async loadCloudConfigState() {
53
+ const { client, project } = this;
54
+ const { linked } = project;
55
+ return client
56
+ .getInstanceConfig({
57
+ app_id: linked.project_id,
58
+ id: linked.instance_id,
59
+ org_id: linked.org_id
60
+ })
61
+ .catch((error) => {
62
+ this.styledError({
63
+ error,
64
+ message: `Failed to get existing config for instance ${linked.instance_id} in project ${linked.project_id} in org ${linked.org_id}. Ensure the instance has been created before deploying.`
65
+ });
66
+ });
67
+ }
68
+ parseLocalConfig(projectDirectory, useRawConfig) {
69
+ const config = parseLocalCloudServiceConfig(projectDirectory, useRawConfig ?? false);
70
+ if (!config) {
71
+ throw new Error(`Service config file not found in ${projectDirectory}. Please create a ${SERVICE_FILENAME} file.`);
72
+ }
73
+ this.serviceConfig = config;
74
+ /**
75
+ * This is a temporary hack to maintain compatibilty with the PowerSync Dashboard.
76
+ * The dashboard requires replication connections to have a name field set.
77
+ * This is not enforced by the management service.
78
+ */
79
+ for (const [index, connection] of config.replication?.connections?.entries() ?? []) {
80
+ if (!connection.name) {
81
+ connection.name = `Default${index > 0 ? `_${index}` : ''}`;
82
+ }
83
+ }
84
+ return config;
85
+ }
86
+ async provision(params) {
87
+ const { cloudConfigState, deployTimeoutMs, indentationLevel } = params;
88
+ const indentation = '\t'.repeat(Math.max(0, indentationLevel));
89
+ const spinner = ora({
90
+ discardStdin: false,
91
+ prefixText: `\n${indentation}Initial provision: deploying without sync config changes in order to validate sync config before final deploy...\n`,
92
+ spinner: 'moon',
93
+ suffixText: `\n${indentation}This may take a few minutes.\n`
94
+ });
95
+ spinner.start();
96
+ try {
97
+ const deployResult = await this.deployInstanceConfig({
98
+ cloudConfigState,
99
+ updateSyncConfig: false
100
+ });
101
+ await this.waitForDeployCompletion({
102
+ deployResult,
103
+ indentation,
104
+ logCompletionMessage: false,
105
+ logScheduledMessage: false,
106
+ timeoutMs: deployTimeoutMs
107
+ });
108
+ /**
109
+ * We typically want to perform a sync config validation after a (re)provision.
110
+ * Even though we wait for the deploy operation above, the request to validate sync config
111
+ * can still fail due to the error
112
+ * [INTERNAL_SERVER_ERROR] Something went wrong
113
+ * getaddrinfo ENOTFOUND 69b8fec1358aa0646ff0ce71.powersync.journeyapps.com
114
+ * Which indicates that the API runner is not active yet.
115
+ * For this reason, we poll the diagnostics API until we get some successful response from the API
116
+ */
117
+ for (let retryCount = 0; retryCount < 5; retryCount++) {
118
+ try {
119
+ const { linked } = this.project;
120
+ await this.client.getInstanceDiagnostics({
121
+ app_id: linked.project_id,
122
+ id: linked.instance_id,
123
+ org_id: linked.org_id
124
+ });
125
+ // We reached the instance
126
+ break;
127
+ }
128
+ catch {
129
+ if (retryCount === 4) {
130
+ throw new Error('Failed to reach instance after provision. Please check the instance status and try again.');
131
+ }
132
+ await new Promise((resolve) => {
133
+ setTimeout(resolve, 5000);
134
+ });
135
+ }
136
+ }
137
+ spinner.stop();
138
+ }
139
+ catch (error) {
140
+ spinner.stop();
141
+ const { linked } = this.project;
142
+ this.styledError({
143
+ error,
144
+ message: `Failed to deploy changes to instance ${linked.instance_id} in project ${linked.project_id} in org ${linked.org_id}`,
145
+ suggestions: ['Check your network connection and try again.', 'If the problem persists, contact support.']
146
+ });
147
+ }
148
+ }
149
+ async validateServiceConfig(params) {
150
+ const { cloudConfigState } = params;
151
+ const { linked } = this.project;
152
+ const { serviceConfig } = this;
153
+ if (!serviceConfig) {
154
+ this.styledError({
155
+ message: `Service config not loaded. Ensure ${SERVICE_FILENAME} is present and valid.`
156
+ });
157
+ }
158
+ this.log('\tValidating configuration...');
159
+ const existingRegion = cloudConfigState.config?.region;
160
+ if (existingRegion && existingRegion !== serviceConfig.region) {
161
+ this.styledError({
162
+ message: `The existing config for instance ${linked.instance_id} in project ${linked.project_id} in org ${linked.org_id} has a different region than the config being deployed. Existing region: ${existingRegion}. New region: ${serviceConfig.region}. The region cannot be changed after the initial deployment.`,
163
+ suggestions: ['Check your config and try again.']
164
+ });
165
+ }
166
+ // Validate region against list of regions obtained from client.listRegions()
167
+ const regions = await this.client.listRegions().catch((error) => {
168
+ this.styledError({
169
+ error,
170
+ message: 'Could not validate region against list of regions: Failed to list regions',
171
+ suggestions: ['Check your network connection and try again.', 'If the problem persists, contact support.']
172
+ });
173
+ });
174
+ const foundRegion = regions.regions.find((region) => region.name === serviceConfig.region);
175
+ if (!foundRegion) {
176
+ this.styledError({
177
+ message: `The region ${serviceConfig.region} is not supported. Please choose a region from the list of supported regions: ${regions.regions.map((region) => region.name).join(', ')}.`
178
+ });
179
+ }
180
+ }
181
+ async waitForDeployCompletion(params) {
182
+ const { deployResult, indentation = '', logCompletionMessage = true, logScheduledMessage = true, timeoutMs } = params;
183
+ const { client, project } = this;
184
+ if (logScheduledMessage) {
185
+ this.log(`${indentation}Deploy operation has been scheduled. Waiting for completion...`);
186
+ }
187
+ const status = await waitForOperationStatusChange({
188
+ client,
189
+ instanceId: deployResult.id,
190
+ linked: project.linked,
191
+ operationId: deployResult.operation_id,
192
+ timeoutMs
193
+ });
194
+ if (status === 'completed') {
195
+ if (!logCompletionMessage) {
196
+ return;
197
+ }
198
+ this.log(ux.colorize('green', 'Deployment operation completed successfully!'));
199
+ }
200
+ else {
201
+ this.styledError({
202
+ message: `Deploy failed. Check instance diagnostics for details, for example: ${ux.colorize('blue', 'powersync status')}`
203
+ });
204
+ }
205
+ }
206
+ async withDeploy(timeoutMs, fn) {
207
+ const { project } = this;
208
+ const spinner = ora({
209
+ discardStdin: false,
210
+ prefixText: '\nDeploying instance...\n',
211
+ spinner: 'moon',
212
+ suffixText: '\nThis may take a few minutes.\n'
213
+ });
214
+ spinner.start();
215
+ try {
216
+ const deployResult = await fn();
217
+ await this.waitForDeployCompletion({ deployResult, timeoutMs });
218
+ spinner.stop();
219
+ }
220
+ catch (error) {
221
+ spinner.stop();
222
+ this.styledError({
223
+ error,
224
+ message: `Failed to deploy changes to instance ${project.linked.instance_id} in project ${project.linked.project_id} in org ${project.linked.org_id}`,
225
+ suggestions: ['Check your network connection and try again.', 'If the problem persists, contact support.']
226
+ });
227
+ }
228
+ }
229
+ }
230
+ //# sourceMappingURL=BaseDeployCommand.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BaseDeployCommand.js","sourceRoot":"","sources":["../../src/api/BaseDeployCommand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,MAA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QAAQ,CAAC,OAAO,EAAE,8CAA8C,CAAC,CAAC,CAAC;QACjF,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,WAAW,CAAC;gBACf,OAAO,EAAE,uEAAuE,EAAE,CAAC,QAAQ,CAAC,MAAM,EAAE,kBAAkB,CAAC,EAAE;aAC1H,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAES,KAAK,CAAC,UAAU,CAAC,SAAiB,EAAE,EAAgD;QAC5F,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;QAEzB,MAAM,OAAO,GAAG,GAAG,CAAC;YAClB,YAAY,EAAE,KAAK;YACnB,UAAU,EAAE,2BAA2B;YACvC,OAAO,EAAE,MAAM;YACf,UAAU,EAAE,kCAAkC;SAC/C,CAAC,CAAC;QAEH,OAAO,CAAC,KAAK,EAAE,CAAC;QAEhB,IAAI,CAAC;YACH,MAAM,YAAY,GAAG,MAAM,EAAE,EAAE,CAAC;YAChC,MAAM,IAAI,CAAC,uBAAuB,CAAC,EAAE,YAAY,EAAE,SAAS,EAAE,CAAC,CAAC;YAChE,OAAO,CAAC,IAAI,EAAE,CAAC;QACjB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,IAAI,EAAE,CAAC;YACf,IAAI,CAAC,WAAW,CAAC;gBACf,KAAK;gBACL,OAAO,EAAE,wCAAwC,OAAO,CAAC,MAAM,CAAC,WAAW,eAAe,OAAO,CAAC,MAAM,CAAC,UAAU,WAAW,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE;gBACrJ,WAAW,EAAE,CAAC,8CAA8C,EAAE,2CAA2C,CAAC;aAC3G,CAAC,CAAC;QACL,CAAC;IACH,CAAC"}
@@ -0,0 +1,29 @@
1
+ import { BaseServiceSelfHostedConfig, ServiceCloudConfig } from '@powersync/cli-schemas';
2
+ export type BuildServiceYamlOptions = {
3
+ /**
4
+ * The service configuration to render in the form of the provided template.
5
+ */
6
+ baseConfig: Partial<BaseServiceSelfHostedConfig | ServiceCloudConfig>;
7
+ /**
8
+ * A YAML comment block to attach to the top of the rendered YAML file, typically containing schema information and links to documentation.
9
+ */
10
+ schemaHeader: string;
11
+ /**
12
+ * The absolute path to the YAML template file to use for rendering. This file should contain all possible configuration options with comments.
13
+ */
14
+ templatePath: string;
15
+ /**
16
+ * For certain fields that are arrays of objects (e.g. replication->connections), if the provided config has an empty array, we want to replace it with a commented-out example from the template. This option allows specifying the paths to those fields in order to apply that replacement logic after the initial rendering of comments and missing fields.
17
+ */
18
+ templateReplacementPaths?: string[][];
19
+ };
20
+ /**
21
+ * Renders a service YAML file from a concrete base config and a parseable template.
22
+ * Given a service config, the rendering process involves:
23
+ * - Adding comments to fields from the template.
24
+ * - Adding commented-out snippets for missing fields from the template, placed at the end of their respective sections.
25
+ * - Preserving the order of fields as defined in the template.
26
+ *
27
+ * The output is a YAML string that can be written to a file, with comments and structure that guide users in filling out missing information.
28
+ */
29
+ export declare function buildServiceYaml({ baseConfig, schemaHeader, templatePath, templateReplacementPaths }: BuildServiceYamlOptions): string;
@@ -0,0 +1,246 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { Document, isMap, isNode, isPair, isScalar, isSeq, Pair, parseDocument, YAMLMap } from 'yaml';
3
+ /**
4
+ * Renders a service YAML file from a concrete base config and a parseable template.
5
+ * Given a service config, the rendering process involves:
6
+ * - Adding comments to fields from the template.
7
+ * - Adding commented-out snippets for missing fields from the template, placed at the end of their respective sections.
8
+ * - Preserving the order of fields as defined in the template.
9
+ *
10
+ * The output is a YAML string that can be written to a file, with comments and structure that guide users in filling out missing information.
11
+ */
12
+ export function buildServiceYaml({ baseConfig, schemaHeader, templatePath, templateReplacementPaths }) {
13
+ const templateContent = readFileSync(templatePath, 'utf8');
14
+ const templateDoc = parseDocument(templateContent);
15
+ const outputDoc = new Document(baseConfig);
16
+ // Both documents should be a YAML map at the root level.
17
+ if (!isMap(templateDoc.contents) || !isMap(outputDoc.contents)) {
18
+ throw new Error('Expected both template and base config to be YAML maps at the root level.');
19
+ }
20
+ // Recursively starts annotating the provided config given the template.
21
+ annotateLevelFromTemplate({ outputMap: outputDoc.contents, templateMap: templateDoc.contents });
22
+ /**
23
+ * For some values, such as the replication->connections array or the client_auth->jwks->keys array,
24
+ * we want to add a commented-out example from the template if the array (in the service config) is empty.
25
+ * This allows users to see example options, and gives a quick path for them to configure the config.
26
+ * This parsing is handled after the initial parsing of the template.
27
+ * We want to avoid rendering incomplete YAML sections such as
28
+ * ```yaml
29
+ * replication:
30
+ * connections: # No content here
31
+ * # No content here
32
+ * client_auth:
33
+ * # etc
34
+ * ```
35
+ * This typically causes a validation error.
36
+ * Instead, we want to render the section with a commented-out example from the template, such as:
37
+ * ```yaml
38
+ * #replication:
39
+ * # connections:
40
+ * # - name: example-connection
41
+ * # host: example.com
42
+ * # port: 1234
43
+ * client_auth:
44
+ * jwks:
45
+ * ```
46
+ * This implements a replacement for those empty arrays.
47
+ */
48
+ for (const { path, shouldReplace } of [
49
+ {
50
+ path: ['replication', 'connections'],
51
+ shouldReplace: baseConfig.replication?.connections?.length === 0
52
+ },
53
+ { path: ['client_auth', 'jwks', 'keys'], shouldReplace: baseConfig.client_auth?.jwks?.keys?.length === 0 },
54
+ ...(templateReplacementPaths?.map((path) => ({ path, shouldReplace: true })) ?? [])
55
+ ]) {
56
+ if (!shouldReplace)
57
+ continue;
58
+ replaceListWithComment({
59
+ outputRootDoc: outputDoc,
60
+ path,
61
+ templateDoc
62
+ });
63
+ }
64
+ const renderedYaml = outputDoc.toString();
65
+ return `${schemaHeader}\n\n${renderedYaml}`;
66
+ }
67
+ /**
68
+ * Adds a comment to the target YAML node. The comment can be either a comment on the same line (comment) or a comment on the line before (commentBefore).
69
+ */
70
+ function annotateComment(options) {
71
+ const { appendComments = true, comment, commentBefore, target } = options;
72
+ if (!comment && !commentBefore)
73
+ return;
74
+ if (isScalar(target)) {
75
+ if (comment)
76
+ target.comment = appendComments ? (target.comment ?? '') + '\n' + comment : comment;
77
+ if (commentBefore)
78
+ target.commentBefore = appendComments ? commentBefore + '\n\n' + (target.commentBefore ?? '') : commentBefore;
79
+ }
80
+ else if (isPair(target) && isScalar(target.key)) {
81
+ if (comment)
82
+ target.key.comment = appendComments ? (target.key.comment ?? '') + '\n' + comment : comment;
83
+ if (commentBefore)
84
+ target.key.commentBefore = appendComments
85
+ ? commentBefore + '\n\n' + (target.key.commentBefore ?? '')
86
+ : commentBefore;
87
+ }
88
+ }
89
+ function copyNodeComments(source, target) {
90
+ if (!isNode(source) || !isNode(target))
91
+ return;
92
+ target.comment = source.comment;
93
+ target.commentBefore = source.commentBefore;
94
+ }
95
+ /**
96
+ * Copies comments from the source YAML node to the target YAML node, including comments on the node itself, as well as comments on the key and value if the node is a pair. This ensures that all relevant comments from the template are preserved in the output YAML.
97
+ */
98
+ function copyComments(options) {
99
+ const { source, target } = options;
100
+ // Pair-level comments
101
+ copyNodeComments(source, target);
102
+ // Key comments
103
+ copyNodeComments(source.key, target.key);
104
+ if (isSeq(source.value) && isSeq(target.value) && target.value.items.length > 0) {
105
+ // Avoid copying template block comments for sequences when we already have data
106
+ // (e.g. replication->connections), otherwise example comments bleed into real configs.
107
+ return;
108
+ }
109
+ // Value comments (covers scalars and maps that carry block comments before the value)
110
+ copyNodeComments(source.value, target.value);
111
+ }
112
+ /**
113
+ * Copies comments from the template to the output YAML at all levels, and appends optional template snippets for any missing keys.
114
+ */
115
+ function annotateLevelFromTemplate(options) {
116
+ const { outputMap, templateMap } = options;
117
+ // For items not present in the currentConfig, we'll add commented out snippets from the template at the end of the section.
118
+ const missingPairs = [];
119
+ for (const templatePair of templateMap.items) {
120
+ const key = getPairKey(templatePair);
121
+ if (!key)
122
+ continue;
123
+ const outputPair = outputMap.items.find((pair) => getPairKey(pair) === key);
124
+ if (!outputMap.has(key) || !outputPair) {
125
+ // We need to add this pair as a commented-out snippet later.
126
+ missingPairs.push(templatePair);
127
+ continue;
128
+ }
129
+ copyComments({
130
+ source: templatePair,
131
+ target: outputPair
132
+ });
133
+ // Add spacing between pairs
134
+ if (isNode(outputPair.key) && isNode(templatePair.key)) {
135
+ outputPair.key.spaceBefore = templatePair.key.spaceBefore;
136
+ }
137
+ // Walk the tree recursively for maps and sequences
138
+ if (isMap(templatePair.value) && isMap(outputPair.value)) {
139
+ annotateLevelFromTemplate({ outputMap: outputPair.value, templateMap: templatePair.value });
140
+ }
141
+ else if (isSeq(templatePair.value) && isSeq(outputPair.value)) {
142
+ for (const outputItem of outputPair.value.items) {
143
+ // For sequences, we need a method to match the items.
144
+ // We currently only deeply traverse replication->connections and client_auth->jwks->keys, which both have a "type" or "kty" field we can use for matching.
145
+ const matchingTemplateItem = templatePair.value.items.find((templateItem) => {
146
+ if (isMap(templateItem) && isMap(outputItem)) {
147
+ return ((templateItem.has('type') &&
148
+ outputItem.has('type') &&
149
+ templateItem.get('type') === outputItem.get('type')) ||
150
+ (templateItem.has('kty') && outputItem.has('kty') && templateItem.get('kty') === outputItem.get('kty')));
151
+ }
152
+ return false;
153
+ });
154
+ if (!matchingTemplateItem)
155
+ continue;
156
+ annotateLevelFromTemplate({
157
+ outputMap: outputItem,
158
+ templateMap: matchingTemplateItem
159
+ });
160
+ }
161
+ }
162
+ }
163
+ if (missingPairs.length > 0) {
164
+ matchSorting({
165
+ orderedBy: templateMap.items,
166
+ toBeSorted: missingPairs
167
+ });
168
+ // The fact that we use a node comment means the indentation will be handled automatically.
169
+ const snippets = missingPairs.map((pair) => pairToYaml(pair)).join('\n');
170
+ outputMap.comment = (outputMap.comment ? outputMap.comment + '\n' : '') + snippets;
171
+ }
172
+ matchSorting({
173
+ orderedBy: templateMap.items,
174
+ toBeSorted: outputMap.items
175
+ });
176
+ }
177
+ function getPairKey(pair) {
178
+ if (!isScalar(pair.key))
179
+ return null;
180
+ const { value } = pair.key;
181
+ return typeof value === 'string' ? value : String(value);
182
+ }
183
+ function pairToYaml(pair) {
184
+ const map = new YAMLMap();
185
+ map.items = [pair];
186
+ return new Document(map).toString().trimEnd();
187
+ }
188
+ function replaceListWithComment(options) {
189
+ // This is only true if the array is present and empty.
190
+ // If the replication connections array is empty, add a commented-out example from the template.
191
+ const { outputRootDoc, path, templateDoc } = options;
192
+ const parentOutputContainer = outputRootDoc.getIn(path.slice(0, -1), true);
193
+ if (!isMap(parentOutputContainer)) {
194
+ throw new Error(`Expected parent of ${path.slice(0, -1).join('.')} to be a YAML map.`);
195
+ }
196
+ const finalOutputKey = path.at(-1);
197
+ const outputItemIndex = parentOutputContainer.items.findIndex((pair) => getPairKey(pair) === finalOutputKey);
198
+ if (outputItemIndex === -1) {
199
+ throw new Error(`Expected ${finalOutputKey} key to be present in the output YAML.`);
200
+ }
201
+ const outputItem = parentOutputContainer.items[outputItemIndex];
202
+ const templatePair = templateDoc.getIn(path, true);
203
+ const templateCommentString = pairToYaml(new Pair(finalOutputKey, templatePair));
204
+ /**
205
+ * We don't want any empty objects/maps in the output YAML.
206
+ * That causes validation errors and requires additional effort from users to input.
207
+ * Instead, if a map is empty, we traverse on level up and add the map item as a comment on
208
+ * that level.
209
+ */
210
+ const siblingPair = parentOutputContainer.items[outputItemIndex + 1];
211
+ if (siblingPair) {
212
+ // Add this example as a comment on the next sibling key.
213
+ // We also need to preserve the current comment on the current key.
214
+ const previousCommentBefore = (isScalar(outputItem.key) && outputItem.key.commentBefore && `${outputItem.key.commentBefore}\n`) || '';
215
+ annotateComment({ commentBefore: previousCommentBefore + templateCommentString, target: siblingPair });
216
+ }
217
+ else if (path.length === 1) {
218
+ // If there is no sibling and we are at the root, we just need to append it as a comment to the main doc
219
+ parentOutputContainer.comment = (parentOutputContainer.comment || '') + templateCommentString;
220
+ }
221
+ else {
222
+ // Move one level up and add the example as a comment on the parent key
223
+ return replaceListWithComment({
224
+ outputRootDoc,
225
+ path: path.slice(0, -1),
226
+ templateDoc
227
+ });
228
+ }
229
+ // Delete the original yaml node
230
+ parentOutputContainer.delete(outputItem.key);
231
+ }
232
+ /**
233
+ * Sorts on array of YAML items by the order of another array's keyed values.
234
+ */
235
+ function matchSorting(params) {
236
+ const { orderedBy, toBeSorted } = params;
237
+ const orderMap = new Map(orderedBy.map((item, index) => [getPairKey(item), index]));
238
+ toBeSorted.sort((a, b) => {
239
+ const aKey = getPairKey(a);
240
+ const bKey = getPairKey(b);
241
+ const aIndex = aKey ? (orderMap.get(aKey) ?? Number.POSITIVE_INFINITY) : Number.POSITIVE_INFINITY;
242
+ const bIndex = bKey ? (orderMap.get(bKey) ?? Number.POSITIVE_INFINITY) : Number.POSITIVE_INFINITY;
243
+ return aIndex - bIndex;
244
+ });
245
+ }
246
+ //# sourceMappingURL=build-service-yaml.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-service-yaml.js","sourceRoot":"","sources":["../../src/api/build-service-yaml.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAsBtG;;;;;;;;GAQG;AACH,MAAM,UAAU,gBAAgB,CAAC,EAC/B,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,wBAAwB,EACA;IACxB,MAAM,eAAe,GAAG,YAAY,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;IAC3D,MAAM,WAAW,GAAG,aAAa,CAAC,eAAe,CAAC,CAAC;IACnD,MAAM,SAAS,GAAG,IAAI,QAAQ,CAAC,UAAU,CAAC,CAAC;IAE3C,yDAAyD;IACzD,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC/D,MAAM,IAAI,KAAK,CAAC,2EAA2E,CAAC,CAAC;IAC/F,CAAC;IAED,wEAAwE;IACxE,yBAAyB,CAAC,EAAE,SAAS,EAAE,SAAS,CAAC,QAA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B,CAAC;QAClG,MAAM,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,iBAAiB,CAAC;QAClG,OAAO,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -17,3 +17,4 @@ export async function createCloudInstance(client, options) {
17
17
  });
18
18
  return { instanceId: result.id };
19
19
  }
20
+ //# sourceMappingURL=create-cloud-instance.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-cloud-instance.js","sourceRoot":"","sources":["../../../src/api/cloud/create-cloud-instance.ts"],"names":[],"mappings":"AAaA;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,MAAiC,EACjC,OAAmC;IAEnC,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAEnD,8FAA8F;IAC9F,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,WAAW,EAAE,CAAC;IAC3C,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC,EAAE,CAAC;QACpD,MAAM,IAAI,KAAK,CACb,UAAU,MAAM,iFAAiF,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAClJ,CAAC;IACJ,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,cAAc,CAAC;QACzC,MAAM,EAAE,SAAS;QACjB,IAAI;QACJ,MAAM,EAAE,KAAK;QACb,MAAM;KACP,CAAC,CAAC;IACH,OAAO,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC;AACnC,CAAC"}
@@ -0,0 +1,15 @@
1
+ export declare const CLOUD_TEMPLATES_DIR: string;
2
+ export declare const SERVICE_TEMPLATE_FILENAME = "service.template.yaml";
3
+ export declare const CLOUD_SERVICE_TEMPLATE_PATH: string;
4
+ export declare const CLOUD_SYNC_CONFIG_TEMPLATE_PATH: string;
5
+ export declare const CLOUD_CLI_TEMPLATE_PATH: string;
6
+ export type WriteCloudTemplateFilesParams = {
7
+ targetDir: string;
8
+ };
9
+ export declare function writeCloudSyncConfigFile(params: WriteCloudTemplateFilesParams): Promise<void>;
10
+ /**
11
+ * Copies the cloud template files to the provided destination.
12
+ * YAML schemas are applied to copied files.
13
+ * This copies the template Sync config and CLI config files.
14
+ */
15
+ export declare function writeCloudTemplateFiles(params: WriteCloudTemplateFilesParams): Promise<void>;
@@ -0,0 +1,33 @@
1
+ import { CLI_FILENAME, SYNC_FILENAME, YAML_CLI_SCHEMA, YAML_SYNC_RULES_SCHEMA } from '@powersync/cli-core';
2
+ import { copyFile, mkdir, readFile, writeFile } from 'node:fs/promises';
3
+ import { dirname, join } from 'node:path';
4
+ import { fileURLToPath } from 'node:url';
5
+ const __dirname = dirname(fileURLToPath(import.meta.url));
6
+ export const CLOUD_TEMPLATES_DIR = join(__dirname, '..', '..', '..', 'templates', 'cloud', 'powersync');
7
+ export const SERVICE_TEMPLATE_FILENAME = 'service.template.yaml';
8
+ export const CLOUD_SERVICE_TEMPLATE_PATH = join(CLOUD_TEMPLATES_DIR, SERVICE_TEMPLATE_FILENAME);
9
+ export const CLOUD_SYNC_CONFIG_TEMPLATE_PATH = join(CLOUD_TEMPLATES_DIR, SYNC_FILENAME);
10
+ export const CLOUD_CLI_TEMPLATE_PATH = join(CLOUD_TEMPLATES_DIR, CLI_FILENAME);
11
+ export async function writeCloudSyncConfigFile(params) {
12
+ const { targetDir } = params;
13
+ const syncOutputPath = join(targetDir, SYNC_FILENAME);
14
+ await copyFile(CLOUD_SYNC_CONFIG_TEMPLATE_PATH, syncOutputPath);
15
+ await writeFile(syncOutputPath, `${YAML_SYNC_RULES_SCHEMA}\n\n${await readFile(syncOutputPath, 'utf8')}`);
16
+ }
17
+ /**
18
+ * Copies the cloud template files to the provided destination.
19
+ * YAML schemas are applied to copied files.
20
+ * This copies the template Sync config and CLI config files.
21
+ */
22
+ export async function writeCloudTemplateFiles(params) {
23
+ const { targetDir } = params;
24
+ // Create the target directory if it doesn't exist
25
+ await mkdir(targetDir, { recursive: true });
26
+ // Initial copy of template files
27
+ const cliOutputPath = join(targetDir, CLI_FILENAME);
28
+ await copyFile(CLOUD_CLI_TEMPLATE_PATH, cliOutputPath);
29
+ // Add schemas to templates
30
+ await writeFile(cliOutputPath, `${YAML_CLI_SCHEMA}\n\n${await readFile(cliOutputPath, 'utf8')}`);
31
+ await writeCloudSyncConfigFile(params);
32
+ }
33
+ //# sourceMappingURL=create-cloud-template.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-cloud-template.js","sourceRoot":"","sources":["../../../src/api/cloud/create-cloud-template.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAC3G,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,MAAM,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAE1D,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC;AAExG,MAAM,CAAC,MAAM,yBAAyB,GAAG,uBAAu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ig(instanceConfig);
18
18
  }
19
+ //# sourceMappingURL=fetch-cloud-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch-cloud-config.js","sourceRoot":"","sources":["../../../src/api/cloud/fetch-cloud-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,kBAAkB,EAA6B,MAAM,wBAAwB,CAAC;AAS/G,MAAM,UAAU,wBAAwB,CAAC,cAA6C;IACpF,MAAM,eAAe,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,cAAc,CAAC,IAAI,EAAE,GAAG,cAAc,CAAC,MAAM,EAAE,CAAC;IAChG,8DAA8D;IAC9D,MAAM,MAAM,GAAG,kBAAkB,CAAC,MAAM,CAAC,eAAsB,CAAC,CAAC;IACjE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,cAAc,CAAC,UAAU,EAAE,CAAC;AAC1D,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,MAAiC,EACjC,MAA8B;IAE9B,MAAM,cAAc,GAAG,MAAM,MAAM,CAAC,iBAAiB,CAAC;QACpD,MAAM,EAAE,MAAM,CAAC,UAAU;QACzB,EAAE,EAAE,MAAM,CAAC,WAAW;QACtB,MAAM,EAAE,MAAM,CAAC,MAAM;KACtB,CAAC,CAAC;IACH,OAAO,wBAAwB,CAAC,cAAc,CAAC,CAAC;AAClD,CAAC"}
@@ -1,18 +1,16 @@
1
- import { createCloudClient, SYNC_FILENAME } from '@powersync/cli-core';
2
- import { existsSync, readFileSync } from 'node:fs';
3
- import { join } from 'node:path';
1
+ import { createCloudClient } from '@powersync/cli-core';
4
2
  /**
5
3
  * Fetches the sync config content for a cloud project.
6
4
  * @param project - The project to fetch the sync config content for.
7
5
  * @returns The sync config content.
8
6
  */
9
7
  export async function fetchCloudSyncRulesContent(project) {
10
- const { linked } = project;
11
- const client = await createCloudClient();
12
8
  // First try and use the local file
13
- if (existsSync(join(project.projectDirectory, SYNC_FILENAME))) {
14
- return readFileSync(join(project.projectDirectory, SYNC_FILENAME), 'utf8');
9
+ if (project.syncRulesContent) {
10
+ return project.syncRulesContent;
15
11
  }
12
+ const { linked } = project;
13
+ const client = createCloudClient();
16
14
  // Try and fetch from the cloud config
17
15
  const instanceConfig = await client.getInstanceConfig({
18
16
  app_id: linked.project_id,
@@ -24,3 +22,4 @@ export async function fetchCloudSyncRulesContent(project) {
24
22
  }
25
23
  return instanceConfig.sync_rules;
26
24
  }
25
+ //# sourceMappingURL=fetch-cloud-sync-rules-content.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch-cloud-sync-rules-content.js","sourceRoot":"","sources":["../../../src/api/cloud/fetch-cloud-sync-rules-content.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAEtE;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAAC,OAAqB;IACpE,mCAAmC;IACnC,IAAI,OAAO,CAAC,gBAAgB,EAAE,CAAC;QAC7B,OAAO,OAAO,CAAC,gBAAgB,CAAC;IAClC,CAAC;IAED,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAC3B,MAAM,MAAM,GAAG,iBAAiB,EAAE,CAAC;IAEnC,sCAAsC;IACtC,MAAM,cAAc,GAAG,MAAM,MAAM,CAAC,iBAAiB,CAAC;QACpD,MAAM,EAAE,MAAM,CAAC,UAAU;QACzB,EAAE,EAAE,MAAM,CAAC,WAAW;QACtB,MAAM,EAAE,MAAM,CAAC,MAAM;KACtB,CAAC,CAAC;IAEH,IAAI,CAAC,cAAc,CAAC,UAAU,EAAE,CAAC;QAC/B,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAC1C,CAAC;IAED,OAAO,cAAc,CAAC,UAAU,CAAC;AACnC,CAAC"}