@xano/cli 0.0.63 → 0.0.65
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/dist/commands/release/pull/index.d.ts +0 -6
- package/dist/commands/release/pull/index.js +15 -62
- package/dist/commands/release/push/index.js +16 -6
- package/dist/commands/tenant/create/index.js +3 -0
- package/dist/commands/tenant/deploy_platform/index.js +1 -0
- package/dist/commands/tenant/deploy_release/index.js +1 -0
- package/dist/commands/tenant/pull/index.d.ts +0 -6
- package/dist/commands/tenant/pull/index.js +9 -56
- package/dist/commands/tenant/push/index.js +18 -8
- package/dist/commands/workspace/git/pull/index.js +7 -6
- package/dist/commands/workspace/pull/index.js +9 -6
- package/dist/commands/workspace/push/index.js +10 -1
- package/dist/utils/document-parser.d.ts +22 -0
- package/dist/utils/document-parser.js +54 -1
- package/oclif.manifest.json +1755 -1755
- package/package.json +2 -2
|
@@ -15,12 +15,6 @@ export default class ReleasePull extends BaseCommand {
|
|
|
15
15
|
};
|
|
16
16
|
run(): Promise<void>;
|
|
17
17
|
private loadCredentials;
|
|
18
|
-
/**
|
|
19
|
-
* Parse a single document to extract its type, name, and optional verb.
|
|
20
|
-
* Skips leading comment lines (starting with //) to find the first
|
|
21
|
-
* meaningful line containing the type keyword and name.
|
|
22
|
-
*/
|
|
23
|
-
private parseDocument;
|
|
24
18
|
private resolveReleaseName;
|
|
25
19
|
/**
|
|
26
20
|
* Sanitize a document name for use as a filename.
|
|
@@ -5,6 +5,7 @@ import * as os from 'node:os';
|
|
|
5
5
|
import * as path from 'node:path';
|
|
6
6
|
import snakeCase from 'lodash.snakecase';
|
|
7
7
|
import BaseCommand from '../../../base-command.js';
|
|
8
|
+
import { buildApiGroupFolderResolver, parseDocument } from '../../../utils/document-parser.js';
|
|
8
9
|
export default class ReleasePull extends BaseCommand {
|
|
9
10
|
static args = {
|
|
10
11
|
directory: Args.string({
|
|
@@ -122,7 +123,7 @@ Pulled 58 documents from release 'v1.0' to ./backup
|
|
|
122
123
|
if (!trimmed) {
|
|
123
124
|
continue;
|
|
124
125
|
}
|
|
125
|
-
const parsed =
|
|
126
|
+
const parsed = parseDocument(trimmed);
|
|
126
127
|
if (parsed) {
|
|
127
128
|
documents.push(parsed);
|
|
128
129
|
}
|
|
@@ -135,6 +136,8 @@ Pulled 58 documents from release 'v1.0' to ./backup
|
|
|
135
136
|
const outputDir = path.resolve(args.directory);
|
|
136
137
|
// Create the output directory if it doesn't exist
|
|
137
138
|
fs.mkdirSync(outputDir, { recursive: true });
|
|
139
|
+
// Resolve api_group names to unique folder names, disambiguating collisions
|
|
140
|
+
const getApiGroupFolder = buildApiGroupFolderResolver(documents, snakeCase);
|
|
138
141
|
// Track filenames per type to handle duplicates
|
|
139
142
|
const filenameCounters = new Map();
|
|
140
143
|
let writtenCount = 0;
|
|
@@ -192,14 +195,14 @@ Pulled 58 documents from release 'v1.0' to ./backup
|
|
|
192
195
|
baseName = this.sanitizeFilename(doc.name);
|
|
193
196
|
}
|
|
194
197
|
else if (doc.type === 'api_group') {
|
|
195
|
-
// api_group "test" → api/
|
|
196
|
-
const groupFolder =
|
|
198
|
+
// api_group "test" → api/{resolved_folder}/{name}.xs
|
|
199
|
+
const groupFolder = getApiGroupFolder(doc.name);
|
|
197
200
|
typeDir = path.join(outputDir, 'api', groupFolder);
|
|
198
|
-
baseName =
|
|
201
|
+
baseName = this.sanitizeFilename(doc.name);
|
|
199
202
|
}
|
|
200
203
|
else if (doc.type === 'query' && doc.apiGroup) {
|
|
201
|
-
// query in group "test" → api/
|
|
202
|
-
const groupFolder =
|
|
204
|
+
// query in group "test" → api/{resolved_folder}/{query_name}.xs
|
|
205
|
+
const groupFolder = getApiGroupFolder(doc.apiGroup);
|
|
203
206
|
const nameParts = doc.name.split('/');
|
|
204
207
|
const leafName = nameParts.pop();
|
|
205
208
|
const folderParts = nameParts.map((part) => snakeCase(part));
|
|
@@ -258,62 +261,12 @@ Pulled 58 documents from release 'v1.0' to ./backup
|
|
|
258
261
|
this.error(`Failed to parse credentials file: ${error}`);
|
|
259
262
|
}
|
|
260
263
|
}
|
|
261
|
-
/**
|
|
262
|
-
* Parse a single document to extract its type, name, and optional verb.
|
|
263
|
-
* Skips leading comment lines (starting with //) to find the first
|
|
264
|
-
* meaningful line containing the type keyword and name.
|
|
265
|
-
*/
|
|
266
|
-
parseDocument(content) {
|
|
267
|
-
const lines = content.split('\n');
|
|
268
|
-
// Find the first non-comment line
|
|
269
|
-
let firstLine = null;
|
|
270
|
-
for (const line of lines) {
|
|
271
|
-
const trimmedLine = line.trim();
|
|
272
|
-
if (trimmedLine && !trimmedLine.startsWith('//')) {
|
|
273
|
-
firstLine = trimmedLine;
|
|
274
|
-
break;
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
if (!firstLine) {
|
|
278
|
-
return null;
|
|
279
|
-
}
|
|
280
|
-
// Parse the type keyword and name from the first meaningful line
|
|
281
|
-
// Expected formats:
|
|
282
|
-
// type name {
|
|
283
|
-
// type name verb=GET {
|
|
284
|
-
// type "name with spaces" {
|
|
285
|
-
// type "name with spaces" verb=PATCH {
|
|
286
|
-
const match = firstLine.match(/^(\w+)\s+("(?:[^"\\]|\\.)*"|\S+)(?:\s+(.*))?/);
|
|
287
|
-
if (!match) {
|
|
288
|
-
return null;
|
|
289
|
-
}
|
|
290
|
-
const type = match[1];
|
|
291
|
-
let name = match[2];
|
|
292
|
-
const rest = match[3] || '';
|
|
293
|
-
// Strip surrounding quotes from the name
|
|
294
|
-
if (name.startsWith('"') && name.endsWith('"')) {
|
|
295
|
-
name = name.slice(1, -1);
|
|
296
|
-
}
|
|
297
|
-
// Extract verb if present (e.g., verb=GET)
|
|
298
|
-
let verb;
|
|
299
|
-
const verbMatch = rest.match(/verb=(\S+)/);
|
|
300
|
-
if (verbMatch) {
|
|
301
|
-
verb = verbMatch[1];
|
|
302
|
-
}
|
|
303
|
-
// Extract api_group if present (e.g., api_group = "test")
|
|
304
|
-
let apiGroup;
|
|
305
|
-
const apiGroupMatch = content.match(/api_group\s*=\s*"([^"]*)"/);
|
|
306
|
-
if (apiGroupMatch) {
|
|
307
|
-
apiGroup = apiGroupMatch[1];
|
|
308
|
-
}
|
|
309
|
-
return { apiGroup, content, name, type, verb };
|
|
310
|
-
}
|
|
311
264
|
async resolveReleaseName(profile, workspaceId, releaseName, verbose) {
|
|
312
265
|
const listUrl = `${profile.instance_origin}/api:meta/workspace/${workspaceId}/release`;
|
|
313
266
|
const response = await this.verboseFetch(listUrl, {
|
|
314
267
|
headers: {
|
|
315
|
-
|
|
316
|
-
|
|
268
|
+
accept: 'application/json',
|
|
269
|
+
Authorization: `Bearer ${profile.access_token}`,
|
|
317
270
|
},
|
|
318
271
|
method: 'GET',
|
|
319
272
|
}, verbose, profile.access_token);
|
|
@@ -321,15 +274,15 @@ Pulled 58 documents from release 'v1.0' to ./backup
|
|
|
321
274
|
const errorText = await response.text();
|
|
322
275
|
this.error(`Failed to list releases: ${response.status} ${response.statusText}\n${errorText}`);
|
|
323
276
|
}
|
|
324
|
-
const data = await response.json();
|
|
277
|
+
const data = (await response.json());
|
|
325
278
|
const releases = Array.isArray(data)
|
|
326
279
|
? data
|
|
327
|
-
:
|
|
280
|
+
: data && typeof data === 'object' && 'items' in data && Array.isArray(data.items)
|
|
328
281
|
? data.items
|
|
329
282
|
: [];
|
|
330
|
-
const match = releases.find(r => r.name === releaseName);
|
|
283
|
+
const match = releases.find((r) => r.name === releaseName);
|
|
331
284
|
if (!match) {
|
|
332
|
-
const available = releases.map(r => r.name).join(', ');
|
|
285
|
+
const available = releases.map((r) => r.name).join(', ');
|
|
333
286
|
this.error(`Release '${releaseName}' not found.${available ? ` Available releases: ${available}` : ''}`);
|
|
334
287
|
}
|
|
335
288
|
return match.id;
|
|
@@ -4,6 +4,7 @@ import * as fs from 'node:fs';
|
|
|
4
4
|
import * as os from 'node:os';
|
|
5
5
|
import * as path from 'node:path';
|
|
6
6
|
import BaseCommand from '../../../base-command.js';
|
|
7
|
+
import { findFilesWithGuid } from '../../../utils/document-parser.js';
|
|
7
8
|
export default class ReleasePush extends BaseCommand {
|
|
8
9
|
static args = {
|
|
9
10
|
directory: Args.string({
|
|
@@ -117,18 +118,18 @@ Output release details as JSON
|
|
|
117
118
|
if (files.length === 0) {
|
|
118
119
|
this.error(`No .xs files found in ${args.directory}`);
|
|
119
120
|
}
|
|
120
|
-
// Read each file and
|
|
121
|
-
const
|
|
121
|
+
// Read each file and track file path alongside content
|
|
122
|
+
const documentEntries = [];
|
|
122
123
|
for (const filePath of files) {
|
|
123
124
|
const content = fs.readFileSync(filePath, 'utf8').trim();
|
|
124
125
|
if (content) {
|
|
125
|
-
|
|
126
|
+
documentEntries.push({ content, filePath });
|
|
126
127
|
}
|
|
127
128
|
}
|
|
128
|
-
if (
|
|
129
|
+
if (documentEntries.length === 0) {
|
|
129
130
|
this.error(`All .xs files in ${args.directory} are empty`);
|
|
130
131
|
}
|
|
131
|
-
const multidoc =
|
|
132
|
+
const multidoc = documentEntries.map((d) => d.content).join('\n---\n');
|
|
132
133
|
// Construct the API URL with query params
|
|
133
134
|
const queryParams = new URLSearchParams({
|
|
134
135
|
description: flags.description,
|
|
@@ -164,6 +165,15 @@ Output release details as JSON
|
|
|
164
165
|
catch {
|
|
165
166
|
errorMessage += `\n${errorText}`;
|
|
166
167
|
}
|
|
168
|
+
// Surface local files involved in duplicate GUID errors
|
|
169
|
+
const guidMatch = errorMessage.match(/Duplicate \w+ guid: (\S+)/);
|
|
170
|
+
if (guidMatch) {
|
|
171
|
+
const dupeFiles = findFilesWithGuid(documentEntries, guidMatch[1]);
|
|
172
|
+
if (dupeFiles.length > 0) {
|
|
173
|
+
const relPaths = dupeFiles.map((f) => path.relative(inputDir, f));
|
|
174
|
+
errorMessage += `\n Local files with this GUID:\n${relPaths.map((f) => ` ${f}`).join('\n')}`;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
167
177
|
this.error(errorMessage);
|
|
168
178
|
}
|
|
169
179
|
const release = (await response.json());
|
|
@@ -179,7 +189,7 @@ Output release details as JSON
|
|
|
179
189
|
if (release.description)
|
|
180
190
|
this.log(` Description: ${release.description}`);
|
|
181
191
|
const elapsed = ((Date.now() - startTime) / 1000).toFixed(1);
|
|
182
|
-
this.log(` Documents: ${
|
|
192
|
+
this.log(` Documents: ${documentEntries.length}`);
|
|
183
193
|
this.log(` Time: ${elapsed}s`);
|
|
184
194
|
}
|
|
185
195
|
}
|
|
@@ -107,6 +107,9 @@ Created tenant: Production (production) - ID: 42
|
|
|
107
107
|
body.platform_id = flags.platform_id;
|
|
108
108
|
if (flags.domain)
|
|
109
109
|
body.domain = flags.domain;
|
|
110
|
+
if (flags.license === 'tier2' || flags.license === 'tier3' || flags.cluster_id) {
|
|
111
|
+
this.warn('This may take a few minutes. Please be patient.');
|
|
112
|
+
}
|
|
110
113
|
const apiUrl = `${profile.instance_origin}/api:meta/workspace/${workspaceId}/tenant`;
|
|
111
114
|
try {
|
|
112
115
|
const response = await this.verboseFetch(apiUrl, {
|
|
@@ -59,6 +59,7 @@ Deployed platform 5 to tenant: My Tenant (my-tenant)
|
|
|
59
59
|
const tenantName = args.tenant_name;
|
|
60
60
|
const platformId = flags.platform_id;
|
|
61
61
|
const apiUrl = `${profile.instance_origin}/api:meta/workspace/${workspaceId}/tenant/${tenantName}/platform/deploy`;
|
|
62
|
+
this.warn('This may take a few minutes. Please be patient.');
|
|
62
63
|
const startTime = Date.now();
|
|
63
64
|
try {
|
|
64
65
|
const response = await this.verboseFetch(apiUrl, {
|
|
@@ -60,6 +60,7 @@ Deployed release "v1.0" to tenant: My Tenant (my-tenant)
|
|
|
60
60
|
const releaseName = flags.release;
|
|
61
61
|
const tenantName = args.tenant_name;
|
|
62
62
|
const apiUrl = `${profile.instance_origin}/api:meta/workspace/${workspaceId}/tenant/${tenantName}/deploy`;
|
|
63
|
+
this.warn('This may take a few minutes. Please be patient.');
|
|
63
64
|
const startTime = Date.now();
|
|
64
65
|
try {
|
|
65
66
|
const response = await this.verboseFetch(apiUrl, {
|
|
@@ -16,12 +16,6 @@ export default class Pull extends BaseCommand {
|
|
|
16
16
|
};
|
|
17
17
|
run(): Promise<void>;
|
|
18
18
|
private loadCredentials;
|
|
19
|
-
/**
|
|
20
|
-
* Parse a single document to extract its type, name, and optional verb.
|
|
21
|
-
* Skips leading comment lines (starting with //) to find the first
|
|
22
|
-
* meaningful line containing the type keyword and name.
|
|
23
|
-
*/
|
|
24
|
-
private parseDocument;
|
|
25
19
|
/**
|
|
26
20
|
* Sanitize a document name for use as a filename.
|
|
27
21
|
* Strips quotes, replaces spaces with underscores, and removes
|
|
@@ -5,6 +5,7 @@ import * as os from 'node:os';
|
|
|
5
5
|
import * as path from 'node:path';
|
|
6
6
|
import snakeCase from 'lodash.snakecase';
|
|
7
7
|
import BaseCommand from '../../../base-command.js';
|
|
8
|
+
import { buildApiGroupFolderResolver, parseDocument } from '../../../utils/document-parser.js';
|
|
8
9
|
export default class Pull extends BaseCommand {
|
|
9
10
|
static args = {
|
|
10
11
|
directory: Args.string({
|
|
@@ -130,7 +131,7 @@ Pulled 42 documents from tenant my-tenant to ./my-tenant
|
|
|
130
131
|
if (!trimmed) {
|
|
131
132
|
continue;
|
|
132
133
|
}
|
|
133
|
-
const parsed =
|
|
134
|
+
const parsed = parseDocument(trimmed);
|
|
134
135
|
if (parsed) {
|
|
135
136
|
documents.push(parsed);
|
|
136
137
|
}
|
|
@@ -143,6 +144,8 @@ Pulled 42 documents from tenant my-tenant to ./my-tenant
|
|
|
143
144
|
const outputDir = path.resolve(args.directory);
|
|
144
145
|
// Create the output directory if it doesn't exist
|
|
145
146
|
fs.mkdirSync(outputDir, { recursive: true });
|
|
147
|
+
// Resolve api_group names to unique folder names, disambiguating collisions
|
|
148
|
+
const getApiGroupFolder = buildApiGroupFolderResolver(documents, snakeCase);
|
|
146
149
|
// Track filenames per type to handle duplicates
|
|
147
150
|
const filenameCounters = new Map();
|
|
148
151
|
let writtenCount = 0;
|
|
@@ -200,14 +203,14 @@ Pulled 42 documents from tenant my-tenant to ./my-tenant
|
|
|
200
203
|
baseName = this.sanitizeFilename(doc.name);
|
|
201
204
|
}
|
|
202
205
|
else if (doc.type === 'api_group') {
|
|
203
|
-
// api_group "test" → api/
|
|
204
|
-
const groupFolder =
|
|
206
|
+
// api_group "test" → api/{resolved_folder}/{name}.xs
|
|
207
|
+
const groupFolder = getApiGroupFolder(doc.name);
|
|
205
208
|
typeDir = path.join(outputDir, 'api', groupFolder);
|
|
206
|
-
baseName =
|
|
209
|
+
baseName = this.sanitizeFilename(doc.name);
|
|
207
210
|
}
|
|
208
211
|
else if (doc.type === 'query' && doc.apiGroup) {
|
|
209
|
-
// query in group "test" → api/
|
|
210
|
-
const groupFolder =
|
|
212
|
+
// query in group "test" → api/{resolved_folder}/{query_name}.xs
|
|
213
|
+
const groupFolder = getApiGroupFolder(doc.apiGroup);
|
|
211
214
|
const nameParts = doc.name.split('/');
|
|
212
215
|
const leafName = nameParts.pop();
|
|
213
216
|
const folderParts = nameParts.map((part) => snakeCase(part));
|
|
@@ -266,56 +269,6 @@ Pulled 42 documents from tenant my-tenant to ./my-tenant
|
|
|
266
269
|
this.error(`Failed to parse credentials file: ${error}`);
|
|
267
270
|
}
|
|
268
271
|
}
|
|
269
|
-
/**
|
|
270
|
-
* Parse a single document to extract its type, name, and optional verb.
|
|
271
|
-
* Skips leading comment lines (starting with //) to find the first
|
|
272
|
-
* meaningful line containing the type keyword and name.
|
|
273
|
-
*/
|
|
274
|
-
parseDocument(content) {
|
|
275
|
-
const lines = content.split('\n');
|
|
276
|
-
// Find the first non-comment line
|
|
277
|
-
let firstLine = null;
|
|
278
|
-
for (const line of lines) {
|
|
279
|
-
const trimmedLine = line.trim();
|
|
280
|
-
if (trimmedLine && !trimmedLine.startsWith('//')) {
|
|
281
|
-
firstLine = trimmedLine;
|
|
282
|
-
break;
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
if (!firstLine) {
|
|
286
|
-
return null;
|
|
287
|
-
}
|
|
288
|
-
// Parse the type keyword and name from the first meaningful line
|
|
289
|
-
// Expected formats:
|
|
290
|
-
// type name {
|
|
291
|
-
// type name verb=GET {
|
|
292
|
-
// type "name with spaces" {
|
|
293
|
-
// type "name with spaces" verb=PATCH {
|
|
294
|
-
const match = firstLine.match(/^(\w+)\s+("(?:[^"\\]|\\.)*"|\S+)(?:\s+(.*))?/);
|
|
295
|
-
if (!match) {
|
|
296
|
-
return null;
|
|
297
|
-
}
|
|
298
|
-
const type = match[1];
|
|
299
|
-
let name = match[2];
|
|
300
|
-
const rest = match[3] || '';
|
|
301
|
-
// Strip surrounding quotes from the name
|
|
302
|
-
if (name.startsWith('"') && name.endsWith('"')) {
|
|
303
|
-
name = name.slice(1, -1);
|
|
304
|
-
}
|
|
305
|
-
// Extract verb if present (e.g., verb=GET)
|
|
306
|
-
let verb;
|
|
307
|
-
const verbMatch = rest.match(/verb=(\S+)/);
|
|
308
|
-
if (verbMatch) {
|
|
309
|
-
verb = verbMatch[1];
|
|
310
|
-
}
|
|
311
|
-
// Extract api_group if present (e.g., api_group = "test")
|
|
312
|
-
let apiGroup;
|
|
313
|
-
const apiGroupMatch = content.match(/api_group\s*=\s*"([^"]*)"/);
|
|
314
|
-
if (apiGroupMatch) {
|
|
315
|
-
apiGroup = apiGroupMatch[1];
|
|
316
|
-
}
|
|
317
|
-
return { apiGroup, content, name, type, verb };
|
|
318
|
-
}
|
|
319
272
|
/**
|
|
320
273
|
* Sanitize a document name for use as a filename.
|
|
321
274
|
* Strips quotes, replaces spaces with underscores, and removes
|
|
@@ -4,6 +4,7 @@ import * as fs from 'node:fs';
|
|
|
4
4
|
import * as os from 'node:os';
|
|
5
5
|
import * as path from 'node:path';
|
|
6
6
|
import BaseCommand from '../../../base-command.js';
|
|
7
|
+
import { findFilesWithGuid } from '../../../utils/document-parser.js';
|
|
7
8
|
export default class Push extends BaseCommand {
|
|
8
9
|
static args = {
|
|
9
10
|
directory: Args.string({
|
|
@@ -142,18 +143,18 @@ Truncate all table records before importing
|
|
|
142
143
|
if (files.length === 0) {
|
|
143
144
|
this.error(`No .xs files found in ${args.directory}`);
|
|
144
145
|
}
|
|
145
|
-
// Read each file and
|
|
146
|
-
const
|
|
146
|
+
// Read each file and track file path alongside content
|
|
147
|
+
const documentEntries = [];
|
|
147
148
|
for (const filePath of files) {
|
|
148
149
|
const content = fs.readFileSync(filePath, 'utf8').trim();
|
|
149
150
|
if (content) {
|
|
150
|
-
|
|
151
|
+
documentEntries.push({ content, filePath });
|
|
151
152
|
}
|
|
152
153
|
}
|
|
153
|
-
if (
|
|
154
|
+
if (documentEntries.length === 0) {
|
|
154
155
|
this.error(`All .xs files in ${args.directory} are empty`);
|
|
155
156
|
}
|
|
156
|
-
const multidoc =
|
|
157
|
+
const multidoc = documentEntries.map((d) => d.content).join('\n---\n');
|
|
157
158
|
// Construct the API URL
|
|
158
159
|
const queryParams = new URLSearchParams({
|
|
159
160
|
env: flags.env.toString(),
|
|
@@ -187,11 +188,20 @@ Truncate all table records before importing
|
|
|
187
188
|
catch {
|
|
188
189
|
errorMessage += `\n${errorText}`;
|
|
189
190
|
}
|
|
191
|
+
// Surface local files involved in duplicate GUID errors
|
|
192
|
+
const guidMatch = errorMessage.match(/Duplicate \w+ guid: (\S+)/);
|
|
193
|
+
if (guidMatch) {
|
|
194
|
+
const dupeFiles = findFilesWithGuid(documentEntries, guidMatch[1]);
|
|
195
|
+
if (dupeFiles.length > 0) {
|
|
196
|
+
const relPaths = dupeFiles.map((f) => path.relative(inputDir, f));
|
|
197
|
+
errorMessage += `\n Local files with this GUID:\n${relPaths.map((f) => ` ${f}`).join('\n')}`;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
190
200
|
this.error(errorMessage);
|
|
191
201
|
}
|
|
192
|
-
//
|
|
202
|
+
// Parse the response (suppress raw output; only show in verbose mode)
|
|
193
203
|
const responseText = await response.text();
|
|
194
|
-
if (responseText && responseText !== 'null') {
|
|
204
|
+
if (responseText && responseText !== 'null' && flags.verbose) {
|
|
195
205
|
this.log(responseText);
|
|
196
206
|
}
|
|
197
207
|
}
|
|
@@ -204,7 +214,7 @@ Truncate all table records before importing
|
|
|
204
214
|
}
|
|
205
215
|
}
|
|
206
216
|
const elapsed = ((Date.now() - startTime) / 1000).toFixed(1);
|
|
207
|
-
this.log(`Pushed ${
|
|
217
|
+
this.log(`Pushed ${documentEntries.length} documents to tenant ${tenantName} from ${args.directory} in ${elapsed}s`);
|
|
208
218
|
}
|
|
209
219
|
/**
|
|
210
220
|
* Recursively collect all .xs files from a directory, sorted by
|
|
@@ -5,7 +5,7 @@ import * as os from 'node:os';
|
|
|
5
5
|
import * as path from 'node:path';
|
|
6
6
|
import snakeCase from 'lodash.snakecase';
|
|
7
7
|
import BaseCommand from '../../../../base-command.js';
|
|
8
|
-
import { parseDocument } from '../../../../utils/document-parser.js';
|
|
8
|
+
import { buildApiGroupFolderResolver, parseDocument } from '../../../../utils/document-parser.js';
|
|
9
9
|
export default class GitPull extends BaseCommand {
|
|
10
10
|
static args = {
|
|
11
11
|
directory: Args.string({
|
|
@@ -95,10 +95,11 @@ export default class GitPull extends BaseCommand {
|
|
|
95
95
|
}
|
|
96
96
|
// Write documents to output directory using the same file tree logic as workspace pull
|
|
97
97
|
fs.mkdirSync(outputDir, { recursive: true });
|
|
98
|
+
const getApiGroupFolder = buildApiGroupFolderResolver(documents, snakeCase);
|
|
98
99
|
const filenameCounters = new Map();
|
|
99
100
|
let writtenCount = 0;
|
|
100
101
|
for (const doc of documents) {
|
|
101
|
-
const { baseName, typeDir } = this.resolveOutputPath(outputDir, doc);
|
|
102
|
+
const { baseName, typeDir } = this.resolveOutputPath(outputDir, doc, getApiGroupFolder);
|
|
102
103
|
fs.mkdirSync(typeDir, { recursive: true });
|
|
103
104
|
// Track duplicates per directory
|
|
104
105
|
const dirKey = path.relative(outputDir, typeDir);
|
|
@@ -323,7 +324,7 @@ export default class GitPull extends BaseCommand {
|
|
|
323
324
|
* Resolve the output directory and base filename for a parsed document.
|
|
324
325
|
* Uses the same type-to-directory mapping as workspace pull.
|
|
325
326
|
*/
|
|
326
|
-
resolveOutputPath(outputDir, doc) {
|
|
327
|
+
resolveOutputPath(outputDir, doc, getApiGroupFolder) {
|
|
327
328
|
let typeDir;
|
|
328
329
|
let baseName;
|
|
329
330
|
if (doc.type === 'workspace') {
|
|
@@ -367,12 +368,12 @@ export default class GitPull extends BaseCommand {
|
|
|
367
368
|
baseName = this.sanitizeFilename(doc.name);
|
|
368
369
|
}
|
|
369
370
|
else if (doc.type === 'api_group') {
|
|
370
|
-
const groupFolder =
|
|
371
|
+
const groupFolder = getApiGroupFolder(doc.name);
|
|
371
372
|
typeDir = path.join(outputDir, 'api', groupFolder);
|
|
372
|
-
baseName =
|
|
373
|
+
baseName = this.sanitizeFilename(doc.name);
|
|
373
374
|
}
|
|
374
375
|
else if (doc.type === 'query' && doc.apiGroup) {
|
|
375
|
-
const groupFolder =
|
|
376
|
+
const groupFolder = getApiGroupFolder(doc.apiGroup);
|
|
376
377
|
const nameParts = doc.name.split('/');
|
|
377
378
|
const leafName = nameParts.pop();
|
|
378
379
|
const folderParts = nameParts.map((part) => snakeCase(part));
|
|
@@ -5,7 +5,7 @@ import * as os from 'node:os';
|
|
|
5
5
|
import * as path from 'node:path';
|
|
6
6
|
import snakeCase from 'lodash.snakecase';
|
|
7
7
|
import BaseCommand from '../../../base-command.js';
|
|
8
|
-
import { parseDocument } from '../../../utils/document-parser.js';
|
|
8
|
+
import { buildApiGroupFolderResolver, parseDocument } from '../../../utils/document-parser.js';
|
|
9
9
|
export default class Pull extends BaseCommand {
|
|
10
10
|
static args = {
|
|
11
11
|
directory: Args.string({
|
|
@@ -149,6 +149,9 @@ Pulled 42 documents to ./my-workspace
|
|
|
149
149
|
const outputDir = path.resolve(args.directory);
|
|
150
150
|
// Create the output directory if it doesn't exist
|
|
151
151
|
fs.mkdirSync(outputDir, { recursive: true });
|
|
152
|
+
// Resolve api_group names to unique folder names, disambiguating collisions
|
|
153
|
+
// where different names produce the same snakeCase (e.g., "Authentication" vs "authentication")
|
|
154
|
+
const getApiGroupFolder = buildApiGroupFolderResolver(documents, snakeCase);
|
|
152
155
|
// Track filenames per type to handle duplicates
|
|
153
156
|
const filenameCounters = new Map();
|
|
154
157
|
let writtenCount = 0;
|
|
@@ -206,14 +209,14 @@ Pulled 42 documents to ./my-workspace
|
|
|
206
209
|
baseName = this.sanitizeFilename(doc.name);
|
|
207
210
|
}
|
|
208
211
|
else if (doc.type === 'api_group') {
|
|
209
|
-
// api_group "test" → api/
|
|
210
|
-
const groupFolder =
|
|
212
|
+
// api_group "test" → api/{resolved_folder}/{name}.xs
|
|
213
|
+
const groupFolder = getApiGroupFolder(doc.name);
|
|
211
214
|
typeDir = path.join(outputDir, 'api', groupFolder);
|
|
212
|
-
baseName =
|
|
215
|
+
baseName = this.sanitizeFilename(doc.name);
|
|
213
216
|
}
|
|
214
217
|
else if (doc.type === 'query' && doc.apiGroup) {
|
|
215
|
-
// query in group "test" → api/
|
|
216
|
-
const groupFolder =
|
|
218
|
+
// query in group "test" → api/{resolved_folder}/{query_name}.xs
|
|
219
|
+
const groupFolder = getApiGroupFolder(doc.apiGroup);
|
|
217
220
|
const nameParts = doc.name.split('/');
|
|
218
221
|
const leafName = nameParts.pop();
|
|
219
222
|
const folderParts = nameParts.map((part) => snakeCase(part));
|
|
@@ -4,7 +4,7 @@ import * as fs from 'node:fs';
|
|
|
4
4
|
import * as os from 'node:os';
|
|
5
5
|
import * as path from 'node:path';
|
|
6
6
|
import BaseCommand from '../../../base-command.js';
|
|
7
|
-
import { buildDocumentKey, parseDocument } from '../../../utils/document-parser.js';
|
|
7
|
+
import { buildDocumentKey, findFilesWithGuid, parseDocument } from '../../../utils/document-parser.js';
|
|
8
8
|
export default class Push extends BaseCommand {
|
|
9
9
|
static args = {
|
|
10
10
|
directory: Args.string({
|
|
@@ -201,6 +201,15 @@ Push schema only, skip records and environment variables
|
|
|
201
201
|
catch {
|
|
202
202
|
errorMessage += `\n${errorText}`;
|
|
203
203
|
}
|
|
204
|
+
// Surface local files involved in duplicate GUID errors
|
|
205
|
+
const guidMatch = errorMessage.match(/Duplicate \w+ guid: (\S+)/);
|
|
206
|
+
if (guidMatch) {
|
|
207
|
+
const dupeFiles = findFilesWithGuid(documentEntries, guidMatch[1]);
|
|
208
|
+
if (dupeFiles.length > 0) {
|
|
209
|
+
const relPaths = dupeFiles.map((f) => path.relative(inputDir, f));
|
|
210
|
+
errorMessage += `\n Local files with this GUID:\n${relPaths.map((f) => ` ${f}`).join('\n')}`;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
204
213
|
this.error(errorMessage);
|
|
205
214
|
}
|
|
206
215
|
// Parse the response for GUID map
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export interface ParsedDocument {
|
|
2
2
|
apiGroup?: string;
|
|
3
|
+
canonical?: string;
|
|
3
4
|
content: string;
|
|
5
|
+
guid?: string;
|
|
4
6
|
name: string;
|
|
5
7
|
type: string;
|
|
6
8
|
verb?: string;
|
|
@@ -15,3 +17,23 @@ export declare function parseDocument(content: string): null | ParsedDocument;
|
|
|
15
17
|
* Used to match server GUID map entries back to local files.
|
|
16
18
|
*/
|
|
17
19
|
export declare function buildDocumentKey(type: string, name: string, verb?: string, apiGroup?: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* Build a map of api_group name → unique folder name for a set of documents.
|
|
22
|
+
*
|
|
23
|
+
* When two api_groups produce the same snakeCase folder (e.g., "Authentication" and
|
|
24
|
+
* "authentication" both → "authentication"), the first group keeps the base name
|
|
25
|
+
* and subsequent groups get a numeric suffix (authentication_2, authentication_3, etc.).
|
|
26
|
+
*
|
|
27
|
+
* @param documents - Parsed documents (only api_group type docs are considered)
|
|
28
|
+
* @param snakeCaseFn - The snakeCase function to use for folder name generation
|
|
29
|
+
* @returns A function that resolves an api_group name to its unique folder name
|
|
30
|
+
*/
|
|
31
|
+
export declare function buildApiGroupFolderResolver(documents: ParsedDocument[], snakeCaseFn: (s: string) => string): (groupName: string) => string;
|
|
32
|
+
/**
|
|
33
|
+
* Find local .xs files that contain a specific GUID.
|
|
34
|
+
* Used to surface which files are involved when the server reports a duplicate GUID error.
|
|
35
|
+
*/
|
|
36
|
+
export declare function findFilesWithGuid(entries: Array<{
|
|
37
|
+
content: string;
|
|
38
|
+
filePath: string;
|
|
39
|
+
}>, guid: string): string[];
|
|
@@ -45,7 +45,19 @@ export function parseDocument(content) {
|
|
|
45
45
|
if (apiGroupMatch) {
|
|
46
46
|
apiGroup = apiGroupMatch[1];
|
|
47
47
|
}
|
|
48
|
-
|
|
48
|
+
// Extract canonical if present (e.g., canonical = "abc123")
|
|
49
|
+
let canonical;
|
|
50
|
+
const canonicalMatch = content.match(/canonical\s*=\s*"([^"]*)"/);
|
|
51
|
+
if (canonicalMatch) {
|
|
52
|
+
canonical = canonicalMatch[1];
|
|
53
|
+
}
|
|
54
|
+
// Extract guid if present (e.g., guid = "abc123")
|
|
55
|
+
let guid;
|
|
56
|
+
const guidMatch = content.match(/guid\s*=\s*"([^"]*)"/);
|
|
57
|
+
if (guidMatch) {
|
|
58
|
+
guid = guidMatch[1];
|
|
59
|
+
}
|
|
60
|
+
return { apiGroup, canonical, content, guid, name, type, verb };
|
|
49
61
|
}
|
|
50
62
|
/**
|
|
51
63
|
* Build a unique key for a document based on its type, name, verb, and api_group.
|
|
@@ -59,3 +71,44 @@ export function buildDocumentKey(type, name, verb, apiGroup) {
|
|
|
59
71
|
parts.push(apiGroup);
|
|
60
72
|
return parts.join(':');
|
|
61
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* Build a map of api_group name → unique folder name for a set of documents.
|
|
76
|
+
*
|
|
77
|
+
* When two api_groups produce the same snakeCase folder (e.g., "Authentication" and
|
|
78
|
+
* "authentication" both → "authentication"), the first group keeps the base name
|
|
79
|
+
* and subsequent groups get a numeric suffix (authentication_2, authentication_3, etc.).
|
|
80
|
+
*
|
|
81
|
+
* @param documents - Parsed documents (only api_group type docs are considered)
|
|
82
|
+
* @param snakeCaseFn - The snakeCase function to use for folder name generation
|
|
83
|
+
* @returns A function that resolves an api_group name to its unique folder name
|
|
84
|
+
*/
|
|
85
|
+
export function buildApiGroupFolderResolver(documents, snakeCaseFn) {
|
|
86
|
+
const apiGroupFolderMap = new Map();
|
|
87
|
+
const folderClaims = new Map();
|
|
88
|
+
for (const doc of documents) {
|
|
89
|
+
if (doc.type !== 'api_group')
|
|
90
|
+
continue;
|
|
91
|
+
const folder = snakeCaseFn(doc.name);
|
|
92
|
+
const names = folderClaims.get(folder) ?? [];
|
|
93
|
+
if (!names.includes(doc.name)) {
|
|
94
|
+
names.push(doc.name);
|
|
95
|
+
}
|
|
96
|
+
folderClaims.set(folder, names);
|
|
97
|
+
}
|
|
98
|
+
for (const [folder, names] of folderClaims) {
|
|
99
|
+
apiGroupFolderMap.set(names[0], folder);
|
|
100
|
+
for (let i = 1; i < names.length; i++) {
|
|
101
|
+
apiGroupFolderMap.set(names[i], `${folder}_${i + 1}`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return (groupName) => {
|
|
105
|
+
return apiGroupFolderMap.get(groupName) ?? snakeCaseFn(groupName);
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Find local .xs files that contain a specific GUID.
|
|
110
|
+
* Used to surface which files are involved when the server reports a duplicate GUID error.
|
|
111
|
+
*/
|
|
112
|
+
export function findFilesWithGuid(entries, guid) {
|
|
113
|
+
return entries.filter((e) => e.content.includes(guid)).map((e) => e.filePath);
|
|
114
|
+
}
|