@memberjunction/metadata-sync 2.55.0 → 2.56.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +92 -51
- package/dist/index.d.ts +21 -1
- package/dist/index.js +41 -3
- package/dist/index.js.map +1 -1
- package/dist/lib/file-backup-manager.js +2 -2
- package/dist/lib/file-backup-manager.js.map +1 -1
- package/dist/lib/sql-logger.d.ts +44 -0
- package/dist/lib/sql-logger.js +140 -0
- package/dist/lib/sql-logger.js.map +1 -0
- package/dist/lib/sync-engine.js +2 -2
- package/dist/lib/sync-engine.js.map +1 -1
- package/dist/lib/transaction-manager.d.ts +36 -0
- package/dist/lib/transaction-manager.js +117 -0
- package/dist/lib/transaction-manager.js.map +1 -0
- package/dist/services/FileResetService.d.ts +30 -0
- package/dist/services/FileResetService.js +182 -0
- package/dist/services/FileResetService.js.map +1 -0
- package/dist/services/InitService.d.ts +17 -0
- package/dist/services/InitService.js +118 -0
- package/dist/services/InitService.js.map +1 -0
- package/dist/services/PullService.d.ts +45 -0
- package/dist/services/PullService.js +564 -0
- package/dist/services/PullService.js.map +1 -0
- package/dist/services/PushService.d.ts +45 -0
- package/dist/services/PushService.js +394 -0
- package/dist/services/PushService.js.map +1 -0
- package/dist/services/StatusService.d.ts +32 -0
- package/dist/services/StatusService.js +138 -0
- package/dist/services/StatusService.js.map +1 -0
- package/dist/services/WatchService.d.ts +32 -0
- package/dist/services/WatchService.js +242 -0
- package/dist/services/WatchService.js.map +1 -0
- package/dist/services/index.d.ts +16 -0
- package/dist/services/index.js +28 -0
- package/dist/services/index.js.map +1 -0
- package/package.json +14 -45
- package/bin/debug.js +0 -7
- package/bin/run +0 -17
- package/bin/run.js +0 -6
- package/dist/commands/file-reset/index.d.ts +0 -15
- package/dist/commands/file-reset/index.js +0 -221
- package/dist/commands/file-reset/index.js.map +0 -1
- package/dist/commands/init/index.d.ts +0 -7
- package/dist/commands/init/index.js +0 -155
- package/dist/commands/init/index.js.map +0 -1
- package/dist/commands/pull/index.d.ts +0 -246
- package/dist/commands/pull/index.js +0 -1448
- package/dist/commands/pull/index.js.map +0 -1
- package/dist/commands/push/index.d.ts +0 -41
- package/dist/commands/push/index.js +0 -1129
- package/dist/commands/push/index.js.map +0 -1
- package/dist/commands/status/index.d.ts +0 -10
- package/dist/commands/status/index.js +0 -199
- package/dist/commands/status/index.js.map +0 -1
- package/dist/commands/validate/index.d.ts +0 -15
- package/dist/commands/validate/index.js +0 -149
- package/dist/commands/validate/index.js.map +0 -1
- package/dist/commands/watch/index.d.ts +0 -15
- package/dist/commands/watch/index.js +0 -300
- package/dist/commands/watch/index.js.map +0 -1
- package/dist/hooks/init.d.ts +0 -3
- package/dist/hooks/init.js +0 -59
- package/dist/hooks/init.js.map +0 -1
- package/oclif.manifest.json +0 -376
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Pull command implementation for MetadataSync
|
|
3
|
-
* @module commands/pull
|
|
4
|
-
*
|
|
5
|
-
* This module implements the pull command which retrieves metadata records from
|
|
6
|
-
* the MemberJunction database and saves them as local JSON files. It supports:
|
|
7
|
-
* - Filtering records with SQL expressions
|
|
8
|
-
* - Pulling related entities with foreign key relationships
|
|
9
|
-
* - Externalizing large text fields to separate files
|
|
10
|
-
* - Creating multi-record JSON files
|
|
11
|
-
* - Recursive directory search for entity configurations
|
|
12
|
-
*/
|
|
13
|
-
import { Command } from '@oclif/core';
|
|
14
|
-
/**
|
|
15
|
-
* Pull metadata records from database to local files
|
|
16
|
-
*
|
|
17
|
-
* @class Pull
|
|
18
|
-
* @extends Command
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* ```bash
|
|
22
|
-
* # Pull all records for an entity
|
|
23
|
-
* mj-sync pull --entity="AI Prompts"
|
|
24
|
-
*
|
|
25
|
-
* # Pull with filter
|
|
26
|
-
* mj-sync pull --entity="AI Prompts" --filter="CategoryID='123'"
|
|
27
|
-
*
|
|
28
|
-
* # Pull to multi-record file
|
|
29
|
-
* mj-sync pull --entity="AI Prompts" --multi-file="all-prompts.json"
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
|
-
export default class Pull extends Command {
|
|
33
|
-
static description: string;
|
|
34
|
-
static examples: string[];
|
|
35
|
-
static flags: {
|
|
36
|
-
entity: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
37
|
-
filter: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
38
|
-
'dry-run': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
39
|
-
'multi-file': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
40
|
-
verbose: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
41
|
-
'no-validate': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
42
|
-
};
|
|
43
|
-
run(): Promise<void>;
|
|
44
|
-
/**
|
|
45
|
-
* Find directories containing configuration for the specified entity
|
|
46
|
-
*
|
|
47
|
-
* Recursively searches the current working directory for .mj-sync.json files
|
|
48
|
-
* that specify the given entity name. Returns all matching directories to
|
|
49
|
-
* allow user selection when multiple locations exist.
|
|
50
|
-
*
|
|
51
|
-
* @param entityName - Name of the entity to search for
|
|
52
|
-
* @returns Promise resolving to array of directory paths
|
|
53
|
-
* @private
|
|
54
|
-
*/
|
|
55
|
-
private findEntityDirectories;
|
|
56
|
-
/**
|
|
57
|
-
* Process a single record and save to file
|
|
58
|
-
*
|
|
59
|
-
* Converts a database record into the file format and writes it to disk.
|
|
60
|
-
* This is a wrapper around processRecordData that handles file writing.
|
|
61
|
-
*
|
|
62
|
-
* @param record - Raw database record
|
|
63
|
-
* @param primaryKey - Primary key fields and values
|
|
64
|
-
* @param targetDir - Directory to save the file
|
|
65
|
-
* @param entityConfig - Entity configuration with pull settings
|
|
66
|
-
* @param syncEngine - Sync engine instance
|
|
67
|
-
* @returns Promise that resolves when file is written
|
|
68
|
-
* @private
|
|
69
|
-
*/
|
|
70
|
-
private processRecord;
|
|
71
|
-
/**
|
|
72
|
-
* Process record data for storage
|
|
73
|
-
*
|
|
74
|
-
* Transforms a raw database record into the RecordData format used for file storage.
|
|
75
|
-
* Handles field externalization, related entity pulling, and checksum calculation.
|
|
76
|
-
*
|
|
77
|
-
* @param record - Raw database record
|
|
78
|
-
* @param primaryKey - Primary key fields and values
|
|
79
|
-
* @param targetDir - Directory where files will be saved
|
|
80
|
-
* @param entityConfig - Entity configuration with defaults and settings
|
|
81
|
-
* @param syncEngine - Sync engine for checksum calculation
|
|
82
|
-
* @param flags - Command flags
|
|
83
|
-
* @param isNewRecord - Whether this is a new record
|
|
84
|
-
* @param existingRecordData - Existing record data to preserve field selection
|
|
85
|
-
* @param currentDepth - Current recursion depth for recursive entities
|
|
86
|
-
* @param ancestryPath - Set of IDs in current ancestry chain to prevent circular references
|
|
87
|
-
* @returns Promise resolving to formatted RecordData
|
|
88
|
-
* @private
|
|
89
|
-
*/
|
|
90
|
-
private processRecordData;
|
|
91
|
-
/**
|
|
92
|
-
* Convert a foreign key value to a @lookup reference
|
|
93
|
-
*
|
|
94
|
-
* Looks up the related record and creates a @lookup string that can be
|
|
95
|
-
* resolved during push operations.
|
|
96
|
-
*
|
|
97
|
-
* @param foreignKeyValue - The foreign key value (ID)
|
|
98
|
-
* @param targetEntity - Name of the target entity
|
|
99
|
-
* @param targetField - Field in target entity to use for lookup
|
|
100
|
-
* @param syncEngine - Sync engine instance
|
|
101
|
-
* @returns @lookup string or null if lookup fails
|
|
102
|
-
* @private
|
|
103
|
-
*/
|
|
104
|
-
private convertToLookup;
|
|
105
|
-
/**
|
|
106
|
-
* Determine if a field should be saved to an external file
|
|
107
|
-
*
|
|
108
|
-
* Checks if a field is configured for externalization or contains substantial
|
|
109
|
-
* text content that would be better stored in a separate file.
|
|
110
|
-
*
|
|
111
|
-
* @param fieldName - Name of the field to check
|
|
112
|
-
* @param fieldValue - Value of the field
|
|
113
|
-
* @param entityConfig - Entity configuration with externalization settings
|
|
114
|
-
* @returns Promise resolving to true if field should be externalized
|
|
115
|
-
* @private
|
|
116
|
-
*/
|
|
117
|
-
private shouldExternalizeField;
|
|
118
|
-
/**
|
|
119
|
-
* Create an external file for a field value
|
|
120
|
-
*
|
|
121
|
-
* Saves large text content to a separate file and returns the filename.
|
|
122
|
-
* Automatically determines appropriate file extension based on field name
|
|
123
|
-
* and content type (e.g., .md for prompts, .html for templates).
|
|
124
|
-
* Uses the entity's name field for the filename if available.
|
|
125
|
-
*
|
|
126
|
-
* @param targetDir - Directory to save the file
|
|
127
|
-
* @param record - Full record to extract name field from
|
|
128
|
-
* @param primaryKey - Primary key for filename generation fallback
|
|
129
|
-
* @param fieldName - Name of the field being externalized
|
|
130
|
-
* @param content - Content to write to the file
|
|
131
|
-
* @param entityConfig - Entity configuration
|
|
132
|
-
* @returns Promise resolving to the created filename
|
|
133
|
-
* @private
|
|
134
|
-
*/
|
|
135
|
-
private createExternalFile;
|
|
136
|
-
/**
|
|
137
|
-
* Build a filename from primary key values
|
|
138
|
-
*
|
|
139
|
-
* Creates a safe filename based on the entity's primary key values.
|
|
140
|
-
* Handles GUIDs by using first 8 characters, sanitizes special characters,
|
|
141
|
-
* and creates composite names for multi-field keys.
|
|
142
|
-
* Files are prefixed with a dot to follow the metadata file convention.
|
|
143
|
-
*
|
|
144
|
-
* @param primaryKey - Primary key fields and values
|
|
145
|
-
* @param entityConfig - Entity configuration (for future extension)
|
|
146
|
-
* @returns Filename with .json extension
|
|
147
|
-
* @private
|
|
148
|
-
*/
|
|
149
|
-
private buildFileName;
|
|
150
|
-
/**
|
|
151
|
-
* Pull related entities for a parent record
|
|
152
|
-
*
|
|
153
|
-
* Retrieves child records that have foreign key relationships to the parent.
|
|
154
|
-
* Converts foreign key values to @parent references and supports nested
|
|
155
|
-
* related entities for deep object graphs.
|
|
156
|
-
* NEW: Supports automatic recursive patterns for self-referencing entities.
|
|
157
|
-
*
|
|
158
|
-
* @param parentRecord - Parent entity record
|
|
159
|
-
* @param relatedConfig - Configuration for related entities to pull
|
|
160
|
-
* @param syncEngine - Sync engine instance
|
|
161
|
-
* @param entityConfig - Entity configuration
|
|
162
|
-
* @param flags - Command flags
|
|
163
|
-
* @param currentDepth - Current recursion depth for recursive entities
|
|
164
|
-
* @param ancestryPath - Set of IDs in current ancestry chain to prevent circular references
|
|
165
|
-
* @returns Promise resolving to map of entity names to related records
|
|
166
|
-
* @private
|
|
167
|
-
*/
|
|
168
|
-
private pullRelatedEntities;
|
|
169
|
-
/**
|
|
170
|
-
* Find which field in the parent record contains a specific value
|
|
171
|
-
*
|
|
172
|
-
* Used to convert foreign key references to @parent references by finding
|
|
173
|
-
* the parent field that contains the foreign key value. Typically finds
|
|
174
|
-
* the primary key field but can match any field.
|
|
175
|
-
*
|
|
176
|
-
* @param parentRecord - Parent record to search
|
|
177
|
-
* @param value - Value to search for
|
|
178
|
-
* @returns Field name containing the value, or null if not found
|
|
179
|
-
* @private
|
|
180
|
-
*/
|
|
181
|
-
private findParentField;
|
|
182
|
-
/**
|
|
183
|
-
* Find existing files in a directory matching a pattern
|
|
184
|
-
*
|
|
185
|
-
* Searches for files that match the configured file pattern, used to identify
|
|
186
|
-
* which records already exist locally for smart update functionality.
|
|
187
|
-
*
|
|
188
|
-
* @param dir - Directory to search in
|
|
189
|
-
* @param pattern - Glob pattern to match files (e.g., "*.json")
|
|
190
|
-
* @returns Promise resolving to array of file paths
|
|
191
|
-
* @private
|
|
192
|
-
*/
|
|
193
|
-
private findExistingFiles;
|
|
194
|
-
/**
|
|
195
|
-
* Load existing records from files and build a lookup map
|
|
196
|
-
*
|
|
197
|
-
* Reads all existing files and creates a map from primary key to file location,
|
|
198
|
-
* enabling efficient lookup during the update process.
|
|
199
|
-
*
|
|
200
|
-
* @param files - Array of file paths to load
|
|
201
|
-
* @param entityInfo - Entity metadata for primary key information
|
|
202
|
-
* @returns Map from primary key string to file info
|
|
203
|
-
* @private
|
|
204
|
-
*/
|
|
205
|
-
private loadExistingRecords;
|
|
206
|
-
/**
|
|
207
|
-
* Create a string lookup key from primary key values
|
|
208
|
-
*
|
|
209
|
-
* Generates a consistent string representation of primary key values
|
|
210
|
-
* for use in maps and comparisons.
|
|
211
|
-
*
|
|
212
|
-
* @param primaryKey - Primary key field names and values
|
|
213
|
-
* @returns String representation of the primary key
|
|
214
|
-
* @private
|
|
215
|
-
*/
|
|
216
|
-
private createPrimaryKeyLookup;
|
|
217
|
-
/**
|
|
218
|
-
* Merge two record data objects based on configured strategy
|
|
219
|
-
*
|
|
220
|
-
* Combines existing and new record data according to the merge strategy:
|
|
221
|
-
* - 'overwrite': Replace all fields with new values
|
|
222
|
-
* - 'merge': Combine fields, with new values taking precedence
|
|
223
|
-
* - 'skip': Keep existing record unchanged
|
|
224
|
-
*
|
|
225
|
-
* @param existing - Existing record data
|
|
226
|
-
* @param newData - New record data from database
|
|
227
|
-
* @param strategy - Merge strategy to apply
|
|
228
|
-
* @param preserveFields - Field names that should never be overwritten
|
|
229
|
-
* @returns Merged record data
|
|
230
|
-
* @private
|
|
231
|
-
*/
|
|
232
|
-
private mergeRecords;
|
|
233
|
-
/**
|
|
234
|
-
* Create a backup of a file before updating
|
|
235
|
-
*
|
|
236
|
-
* Creates a timestamped backup copy of the file in a backup directory
|
|
237
|
-
* with the original filename, timestamp suffix, and .backup extension.
|
|
238
|
-
* The backup directory defaults to .backups but can be configured.
|
|
239
|
-
*
|
|
240
|
-
* @param filePath - Path to the file to backup
|
|
241
|
-
* @param backupDirName - Name of the backup directory (optional)
|
|
242
|
-
* @returns Promise that resolves when backup is created
|
|
243
|
-
* @private
|
|
244
|
-
*/
|
|
245
|
-
private createBackup;
|
|
246
|
-
}
|