@apso/cli 0.7.4 → 0.8.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/dist/autogen/index.d.ts +2 -0
- package/dist/autogen/index.js +3 -0
- package/dist/commands/server/new.d.ts +4 -1
- package/dist/commands/server/new.js +115 -22
- package/dist/commands/server/scaffold.d.ts +10 -0
- package/dist/commands/server/scaffold.js +200 -10
- package/dist/lib/api/client.d.ts +65 -0
- package/dist/lib/api/client.js +305 -0
- package/dist/lib/api/index.d.ts +8 -0
- package/dist/lib/api/index.js +22 -0
- package/dist/lib/api/services.d.ts +166 -0
- package/dist/lib/api/services.js +202 -0
- package/dist/lib/api/types.d.ts +212 -0
- package/dist/lib/api/types.js +7 -0
- package/dist/lib/apsorc-parser.d.ts +3 -0
- package/dist/lib/apsorc-parser.js +4 -0
- package/dist/lib/config/index.d.ts +8 -0
- package/dist/lib/config/index.js +17 -0
- package/dist/lib/config/manager.d.ts +127 -0
- package/dist/lib/config/manager.js +304 -0
- package/dist/lib/config/paths.d.ts +65 -0
- package/dist/lib/config/paths.js +127 -0
- package/dist/lib/config/types.d.ts +230 -0
- package/dist/lib/config/types.js +30 -0
- package/dist/lib/generators/base.d.ts +93 -0
- package/dist/lib/generators/base.js +90 -0
- package/dist/lib/generators/go.d.ts +37 -0
- package/dist/lib/generators/go.js +340 -0
- package/dist/lib/generators/index.d.ts +21 -0
- package/dist/lib/generators/index.js +51 -0
- package/dist/lib/generators/python.d.ts +21 -0
- package/dist/lib/generators/python.js +253 -0
- package/dist/lib/generators/typescript.d.ts +25 -0
- package/dist/lib/generators/typescript.js +373 -0
- package/dist/lib/index.d.ts +2 -0
- package/dist/lib/index.js +9 -1
- package/dist/lib/templates/entities/entity-col-timestamp.eta +9 -2
- package/dist/lib/templates/entities/entity-col-timestamptz.eta +9 -2
- package/dist/lib/templates/entities/entity.eta +18 -5
- package/dist/lib/templates/go/dto/dto-col-array.eta +7 -0
- package/dist/lib/templates/go/dto/dto-col-boolean.eta +7 -0
- package/dist/lib/templates/go/dto/dto-col-date.eta +7 -0
- package/dist/lib/templates/go/dto/dto-col-decimal.eta +7 -0
- package/dist/lib/templates/go/dto/dto-col-enum.eta +8 -0
- package/dist/lib/templates/go/dto/dto-col-float.eta +7 -0
- package/dist/lib/templates/go/dto/dto-col-integer.eta +7 -0
- package/dist/lib/templates/go/dto/dto-col-json.eta +7 -0
- package/dist/lib/templates/go/dto/dto-col-jsonb.eta +7 -0
- package/dist/lib/templates/go/dto/dto-col-numeric.eta +7 -0
- package/dist/lib/templates/go/dto/dto-col-string.eta +7 -0
- package/dist/lib/templates/go/dto/dto-col-text.eta +7 -0
- package/dist/lib/templates/go/dto/dto-col-timestamp.eta +7 -0
- package/dist/lib/templates/go/dto/dto-col-timestamptz.eta +7 -0
- package/dist/lib/templates/go/dto/dto-col-uuid.eta +7 -0
- package/dist/lib/templates/go/dto/dto-col-varchar.eta +7 -0
- package/dist/lib/templates/go/dto/dto.eta +78 -0
- package/dist/lib/templates/go/enums.eta +44 -0
- package/dist/lib/templates/go/handlers/handler.eta +212 -0
- package/dist/lib/templates/go/header.eta +3 -0
- package/dist/lib/templates/go/index-module.eta +53 -0
- package/dist/lib/templates/go/middleware/auth.eta +101 -0
- package/dist/lib/templates/go/models/model-col-array.eta +1 -0
- package/dist/lib/templates/go/models/model-col-boolean.eta +1 -0
- package/dist/lib/templates/go/models/model-col-date.eta +1 -0
- package/dist/lib/templates/go/models/model-col-decimal.eta +1 -0
- package/dist/lib/templates/go/models/model-col-enum.eta +2 -0
- package/dist/lib/templates/go/models/model-col-float.eta +1 -0
- package/dist/lib/templates/go/models/model-col-integer.eta +1 -0
- package/dist/lib/templates/go/models/model-col-json.eta +1 -0
- package/dist/lib/templates/go/models/model-col-jsonb.eta +1 -0
- package/dist/lib/templates/go/models/model-col-numeric.eta +1 -0
- package/dist/lib/templates/go/models/model-col-string.eta +1 -0
- package/dist/lib/templates/go/models/model-col-text.eta +1 -0
- package/dist/lib/templates/go/models/model-col-timestamp.eta +1 -0
- package/dist/lib/templates/go/models/model-col-timestamptz.eta +1 -0
- package/dist/lib/templates/go/models/model-col-uuid.eta +1 -0
- package/dist/lib/templates/go/models/model-col-varchar.eta +1 -0
- package/dist/lib/templates/go/models/model.eta +53 -0
- package/dist/lib/templates/go/services/service.eta +190 -0
- package/dist/lib/templates/python/enums.eta +10 -0
- package/dist/lib/templates/python/header.eta +6 -0
- package/dist/lib/templates/python/index-module.eta +18 -0
- package/dist/lib/templates/python/models/model-col-array.eta +4 -0
- package/dist/lib/templates/python/models/model-col-boolean.eta +5 -0
- package/dist/lib/templates/python/models/model-col-date.eta +4 -0
- package/dist/lib/templates/python/models/model-col-decimal.eta +4 -0
- package/dist/lib/templates/python/models/model-col-enum.eta +16 -0
- package/dist/lib/templates/python/models/model-col-float.eta +5 -0
- package/dist/lib/templates/python/models/model-col-integer.eta +6 -0
- package/dist/lib/templates/python/models/model-col-json.eta +4 -0
- package/dist/lib/templates/python/models/model-col-jsonb.eta +4 -0
- package/dist/lib/templates/python/models/model-col-numeric.eta +4 -0
- package/dist/lib/templates/python/models/model-col-string.eta +6 -0
- package/dist/lib/templates/python/models/model-col-text.eta +6 -0
- package/dist/lib/templates/python/models/model-col-timestamp.eta +11 -0
- package/dist/lib/templates/python/models/model-col-timestamptz.eta +11 -0
- package/dist/lib/templates/python/models/model-col-uuid.eta +5 -0
- package/dist/lib/templates/python/models/model-col-varchar.eta +6 -0
- package/dist/lib/templates/python/models/model.eta +124 -0
- package/dist/lib/templates/python/routers/router.eta +206 -0
- package/dist/lib/templates/python/schemas/schema-col-array.eta +1 -0
- package/dist/lib/templates/python/schemas/schema-col-boolean.eta +1 -0
- package/dist/lib/templates/python/schemas/schema-col-date.eta +1 -0
- package/dist/lib/templates/python/schemas/schema-col-decimal.eta +1 -0
- package/dist/lib/templates/python/schemas/schema-col-enum.eta +6 -0
- package/dist/lib/templates/python/schemas/schema-col-float.eta +1 -0
- package/dist/lib/templates/python/schemas/schema-col-integer.eta +1 -0
- package/dist/lib/templates/python/schemas/schema-col-json.eta +1 -0
- package/dist/lib/templates/python/schemas/schema-col-jsonb.eta +1 -0
- package/dist/lib/templates/python/schemas/schema-col-numeric.eta +1 -0
- package/dist/lib/templates/python/schemas/schema-col-string.eta +1 -0
- package/dist/lib/templates/python/schemas/schema-col-text.eta +1 -0
- package/dist/lib/templates/python/schemas/schema-col-timestamp.eta +1 -0
- package/dist/lib/templates/python/schemas/schema-col-timestamptz.eta +1 -0
- package/dist/lib/templates/python/schemas/schema-col-uuid.eta +1 -0
- package/dist/lib/templates/python/schemas/schema-col-varchar.eta +1 -0
- package/dist/lib/templates/python/schemas/schema.eta +87 -0
- package/dist/lib/templates/python/services/service.eta +163 -0
- package/dist/lib/templates/rest/controller-rest.eta +13 -12
- package/dist/lib/templates/rest/dto-rest.eta +173 -59
- package/dist/lib/types/generator.d.ts +241 -0
- package/dist/lib/types/generator.js +2 -0
- package/dist/lib/types/index.d.ts +1 -0
- package/dist/lib/utils/casing.d.ts +1 -0
- package/dist/lib/utils/casing.js +11 -1
- package/oclif.manifest.json +32 -3
- package/package.json +4 -2
- package/dist/lib/utils/relationships/parse.spec.d.ts +0 -1
- package/dist/lib/utils/relationships/parse.spec.js +0 -402
- package/dist/tests/templates/entities/types/array-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/array-template.spec.js +0 -82
- package/dist/tests/templates/entities/types/bigint-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/bigint-template.spec.js +0 -82
- package/dist/tests/templates/entities/types/boolean-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/boolean-template.spec.js +0 -77
- package/dist/tests/templates/entities/types/bytea-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/bytea-template.spec.js +0 -68
- package/dist/tests/templates/entities/types/char-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/char-template.spec.js +0 -68
- package/dist/tests/templates/entities/types/date-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/date-template.spec.js +0 -56
- package/dist/tests/templates/entities/types/decimal-field-validation.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/decimal-field-validation.spec.js +0 -100
- package/dist/tests/templates/entities/types/decimal-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/decimal-template.spec.js +0 -86
- package/dist/tests/templates/entities/types/double-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/double-template.spec.js +0 -70
- package/dist/tests/templates/entities/types/enum-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/enum-template.spec.js +0 -85
- package/dist/tests/templates/entities/types/float-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/float-template.spec.js +0 -70
- package/dist/tests/templates/entities/types/geometry-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/geometry-template.spec.js +0 -58
- package/dist/tests/templates/entities/types/inet-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/inet-template.spec.js +0 -69
- package/dist/tests/templates/entities/types/int4range-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/int4range-template.spec.js +0 -72
- package/dist/tests/templates/entities/types/integer-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/integer-template.spec.js +0 -79
- package/dist/tests/templates/entities/types/interval-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/interval-template.spec.js +0 -68
- package/dist/tests/templates/entities/types/json-plain-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/json-plain-template.spec.js +0 -54
- package/dist/tests/templates/entities/types/json-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/json-template.spec.js +0 -40
- package/dist/tests/templates/entities/types/jsonb-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/jsonb-template.spec.js +0 -40
- package/dist/tests/templates/entities/types/money-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/money-template.spec.js +0 -68
- package/dist/tests/templates/entities/types/numeric-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/numeric-template.spec.js +0 -84
- package/dist/tests/templates/entities/types/point-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/point-template.spec.js +0 -64
- package/dist/tests/templates/entities/types/polygon-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/polygon-template.spec.js +0 -70
- package/dist/tests/templates/entities/types/real-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/real-template.spec.js +0 -67
- package/dist/tests/templates/entities/types/serial-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/serial-template.spec.js +0 -113
- package/dist/tests/templates/entities/types/smallint-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/smallint-template.spec.js +0 -82
- package/dist/tests/templates/entities/types/string-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/string-template.spec.js +0 -111
- package/dist/tests/templates/entities/types/text-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/text-template.spec.js +0 -70
- package/dist/tests/templates/entities/types/time-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/time-template.spec.js +0 -68
- package/dist/tests/templates/entities/types/timestamp-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/timestamp-template.spec.js +0 -74
- package/dist/tests/templates/entities/types/timetz-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/timetz-template.spec.js +0 -68
- package/dist/tests/templates/entities/types/tsvector-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/tsvector-template.spec.js +0 -55
- package/dist/tests/templates/entities/types/uuid-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/uuid-template.spec.js +0 -82
- package/dist/tests/templates/entities/types/varchar-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/varchar-template.spec.js +0 -105
- package/dist/tests/templates/entities/types/xml-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/xml-template.spec.js +0 -55
- package/dist/tests/templates/entities/uuid-entity-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/uuid-entity-template.spec.js +0 -277
- package/dist/tests/utils/relationship-deduplication.spec.d.ts +0 -1
- package/dist/tests/utils/relationship-deduplication.spec.js +0 -98
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Configuration Manager
|
|
4
|
+
*
|
|
5
|
+
* Handles reading/writing configuration and credentials files
|
|
6
|
+
* with proper security measures.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.createBackup = exports.syncQueue = exports.projectLink = exports.credentials = exports.globalConfig = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const fs = tslib_1.__importStar(require("fs"));
|
|
12
|
+
const path = tslib_1.__importStar(require("path"));
|
|
13
|
+
const types_1 = require("./types");
|
|
14
|
+
const paths_1 = require("./paths");
|
|
15
|
+
// Get CLI version from package.json
|
|
16
|
+
let cliVersion = "0.0.0";
|
|
17
|
+
try {
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
19
|
+
const pkg = require("../../../package.json");
|
|
20
|
+
cliVersion = pkg.version;
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
// Ignore if package.json not found
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Read JSON file safely
|
|
27
|
+
*/
|
|
28
|
+
function readJsonFile(filePath) {
|
|
29
|
+
try {
|
|
30
|
+
if (!fs.existsSync(filePath)) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
// eslint-disable-next-line unicorn/prefer-json-parse-buffer
|
|
34
|
+
const content = fs.readFileSync(filePath, "utf8");
|
|
35
|
+
return JSON.parse(content);
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Write JSON file with optional restrictive permissions
|
|
43
|
+
*/
|
|
44
|
+
function writeJsonFile(filePath, data, secure = false) {
|
|
45
|
+
const dir = path.dirname(filePath);
|
|
46
|
+
(0, paths_1.ensureDir)(dir);
|
|
47
|
+
const content = JSON.stringify(data, null, 2);
|
|
48
|
+
fs.writeFileSync(filePath, content, "utf-8");
|
|
49
|
+
// Set restrictive permissions for sensitive files on Unix
|
|
50
|
+
if (secure && process.platform !== "win32") {
|
|
51
|
+
try {
|
|
52
|
+
fs.chmodSync(filePath, 0o600);
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
// Ignore permission errors
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Global Configuration Manager
|
|
61
|
+
*/
|
|
62
|
+
exports.globalConfig = {
|
|
63
|
+
/**
|
|
64
|
+
* Read global configuration, merging defaults and environment variables
|
|
65
|
+
*/
|
|
66
|
+
read() {
|
|
67
|
+
(0, paths_1.ensureGlobalConfigDir)();
|
|
68
|
+
const fileConfig = readJsonFile((0, paths_1.getGlobalConfigPath)());
|
|
69
|
+
// Start with defaults
|
|
70
|
+
const config = { ...types_1.DEFAULT_GLOBAL_CONFIG };
|
|
71
|
+
// Merge file config
|
|
72
|
+
if (fileConfig) {
|
|
73
|
+
Object.assign(config, fileConfig);
|
|
74
|
+
}
|
|
75
|
+
// Override with environment variables
|
|
76
|
+
if (process.env.APSO_API_URL) {
|
|
77
|
+
config.apiUrl = process.env.APSO_API_URL;
|
|
78
|
+
}
|
|
79
|
+
if (process.env.APSO_WEB_URL) {
|
|
80
|
+
config.webUrl = process.env.APSO_WEB_URL;
|
|
81
|
+
}
|
|
82
|
+
if (process.env.APSO_DEBUG === "true" || process.env.APSO_DEBUG === "1") {
|
|
83
|
+
config.verbose = true;
|
|
84
|
+
}
|
|
85
|
+
if (process.env.APSO_NO_COLOR === "true" ||
|
|
86
|
+
process.env.APSO_NO_COLOR === "1" ||
|
|
87
|
+
process.env.NO_COLOR) {
|
|
88
|
+
config.noColor = true;
|
|
89
|
+
}
|
|
90
|
+
return config;
|
|
91
|
+
},
|
|
92
|
+
/**
|
|
93
|
+
* Write global configuration
|
|
94
|
+
*/
|
|
95
|
+
write(config) {
|
|
96
|
+
(0, paths_1.ensureGlobalConfigDir)();
|
|
97
|
+
const existing = this.read();
|
|
98
|
+
const merged = { ...existing, ...config };
|
|
99
|
+
writeJsonFile((0, paths_1.getGlobalConfigPath)(), merged);
|
|
100
|
+
},
|
|
101
|
+
/**
|
|
102
|
+
* Get a specific configuration value
|
|
103
|
+
*/
|
|
104
|
+
get(key) {
|
|
105
|
+
return this.read()[key];
|
|
106
|
+
},
|
|
107
|
+
/**
|
|
108
|
+
* Set a specific configuration value
|
|
109
|
+
*/
|
|
110
|
+
set(key, value) {
|
|
111
|
+
this.write({ [key]: value });
|
|
112
|
+
},
|
|
113
|
+
/**
|
|
114
|
+
* Reset configuration to defaults
|
|
115
|
+
*/
|
|
116
|
+
reset() {
|
|
117
|
+
writeJsonFile((0, paths_1.getGlobalConfigPath)(), types_1.DEFAULT_GLOBAL_CONFIG);
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* Credentials Manager
|
|
122
|
+
*/
|
|
123
|
+
exports.credentials = {
|
|
124
|
+
/**
|
|
125
|
+
* Read stored credentials
|
|
126
|
+
*/
|
|
127
|
+
read() {
|
|
128
|
+
return readJsonFile((0, paths_1.getCredentialsPath)());
|
|
129
|
+
},
|
|
130
|
+
/**
|
|
131
|
+
* Write credentials (with secure file permissions)
|
|
132
|
+
*/
|
|
133
|
+
write(creds) {
|
|
134
|
+
(0, paths_1.ensureGlobalConfigDir)();
|
|
135
|
+
const fullCreds = {
|
|
136
|
+
...creds,
|
|
137
|
+
updatedAt: new Date().toISOString(),
|
|
138
|
+
cliVersion,
|
|
139
|
+
};
|
|
140
|
+
writeJsonFile((0, paths_1.getCredentialsPath)(), fullCreds, true);
|
|
141
|
+
},
|
|
142
|
+
/**
|
|
143
|
+
* Clear stored credentials
|
|
144
|
+
*/
|
|
145
|
+
clear() {
|
|
146
|
+
const credsPath = (0, paths_1.getCredentialsPath)();
|
|
147
|
+
if (fs.existsSync(credsPath)) {
|
|
148
|
+
fs.unlinkSync(credsPath);
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
/**
|
|
152
|
+
* Check if credentials exist and are not expired
|
|
153
|
+
*/
|
|
154
|
+
isValid() {
|
|
155
|
+
const creds = this.read();
|
|
156
|
+
if (!creds) {
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
// Check if access token is expired
|
|
160
|
+
const expiresAt = new Date(creds.tokens.expiresAt);
|
|
161
|
+
const now = new Date();
|
|
162
|
+
return expiresAt > now;
|
|
163
|
+
},
|
|
164
|
+
/**
|
|
165
|
+
* Check if credentials exist (may be expired)
|
|
166
|
+
*/
|
|
167
|
+
exists() {
|
|
168
|
+
return this.read() !== null;
|
|
169
|
+
},
|
|
170
|
+
/**
|
|
171
|
+
* Check if token needs refresh (expires within 5 minutes)
|
|
172
|
+
*/
|
|
173
|
+
needsRefresh() {
|
|
174
|
+
const creds = this.read();
|
|
175
|
+
if (!creds) {
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
const expiresAt = new Date(creds.tokens.expiresAt);
|
|
179
|
+
const fiveMinutesFromNow = new Date(Date.now() + 5 * 60 * 1000);
|
|
180
|
+
return expiresAt <= fiveMinutesFromNow;
|
|
181
|
+
},
|
|
182
|
+
};
|
|
183
|
+
/**
|
|
184
|
+
* Project Link Manager
|
|
185
|
+
*/
|
|
186
|
+
exports.projectLink = {
|
|
187
|
+
/**
|
|
188
|
+
* Read project link configuration
|
|
189
|
+
*/
|
|
190
|
+
read(projectDir) {
|
|
191
|
+
return readJsonFile((0, paths_1.getProjectLinkPath)(projectDir));
|
|
192
|
+
},
|
|
193
|
+
/**
|
|
194
|
+
* Write project link configuration
|
|
195
|
+
*/
|
|
196
|
+
write(link, projectDir) {
|
|
197
|
+
(0, paths_1.ensureProjectConfigDir)(projectDir);
|
|
198
|
+
writeJsonFile((0, paths_1.getProjectLinkPath)(projectDir), link);
|
|
199
|
+
},
|
|
200
|
+
/**
|
|
201
|
+
* Remove project link
|
|
202
|
+
*/
|
|
203
|
+
remove(projectDir) {
|
|
204
|
+
const linkPath = (0, paths_1.getProjectLinkPath)(projectDir);
|
|
205
|
+
if (fs.existsSync(linkPath)) {
|
|
206
|
+
fs.unlinkSync(linkPath);
|
|
207
|
+
}
|
|
208
|
+
},
|
|
209
|
+
/**
|
|
210
|
+
* Check if project is linked
|
|
211
|
+
*/
|
|
212
|
+
exists(projectDir) {
|
|
213
|
+
return this.read(projectDir) !== null;
|
|
214
|
+
},
|
|
215
|
+
/**
|
|
216
|
+
* Update sync metadata after successful sync
|
|
217
|
+
*/
|
|
218
|
+
updateSyncMetadata(metadata, projectDir) {
|
|
219
|
+
const link = this.read(projectDir);
|
|
220
|
+
if (link) {
|
|
221
|
+
this.write({ ...link, ...metadata }, projectDir);
|
|
222
|
+
}
|
|
223
|
+
},
|
|
224
|
+
};
|
|
225
|
+
/**
|
|
226
|
+
* Sync Queue Manager
|
|
227
|
+
*/
|
|
228
|
+
exports.syncQueue = {
|
|
229
|
+
/**
|
|
230
|
+
* Read sync queue
|
|
231
|
+
*/
|
|
232
|
+
read(projectDir) {
|
|
233
|
+
const queue = readJsonFile((0, paths_1.getSyncQueuePath)(projectDir));
|
|
234
|
+
return queue || { version: 1, operations: [] };
|
|
235
|
+
},
|
|
236
|
+
/**
|
|
237
|
+
* Write sync queue
|
|
238
|
+
*/
|
|
239
|
+
write(queue, projectDir) {
|
|
240
|
+
(0, paths_1.ensureProjectConfigDir)(projectDir);
|
|
241
|
+
writeJsonFile((0, paths_1.getSyncQueuePath)(projectDir), queue);
|
|
242
|
+
},
|
|
243
|
+
/**
|
|
244
|
+
* Add operation to queue
|
|
245
|
+
*/
|
|
246
|
+
add(operation, projectDir) {
|
|
247
|
+
const queue = this.read(projectDir);
|
|
248
|
+
const id = `${Date.now()}-${Math.random().toString(36).slice(2, 9)}`;
|
|
249
|
+
const item = {
|
|
250
|
+
...operation,
|
|
251
|
+
id,
|
|
252
|
+
queuedAt: new Date().toISOString(),
|
|
253
|
+
retryCount: 0,
|
|
254
|
+
};
|
|
255
|
+
queue.operations.push(item);
|
|
256
|
+
this.write(queue, projectDir);
|
|
257
|
+
return id;
|
|
258
|
+
},
|
|
259
|
+
/**
|
|
260
|
+
* Remove operation from queue
|
|
261
|
+
*/
|
|
262
|
+
remove(id, projectDir) {
|
|
263
|
+
const queue = this.read(projectDir);
|
|
264
|
+
queue.operations = queue.operations.filter((op) => op.id !== id);
|
|
265
|
+
this.write(queue, projectDir);
|
|
266
|
+
},
|
|
267
|
+
/**
|
|
268
|
+
* Get pending operations count
|
|
269
|
+
*/
|
|
270
|
+
count(projectDir) {
|
|
271
|
+
return this.read(projectDir).operations.length;
|
|
272
|
+
},
|
|
273
|
+
/**
|
|
274
|
+
* Clear all operations
|
|
275
|
+
*/
|
|
276
|
+
clear(projectDir) {
|
|
277
|
+
this.write({ version: 1, operations: [] }, projectDir);
|
|
278
|
+
},
|
|
279
|
+
/**
|
|
280
|
+
* Update operation retry count and error
|
|
281
|
+
*/
|
|
282
|
+
updateRetry(id, error, projectDir) {
|
|
283
|
+
const queue = this.read(projectDir);
|
|
284
|
+
const op = queue.operations.find((o) => o.id === id);
|
|
285
|
+
if (op) {
|
|
286
|
+
op.retryCount += 1;
|
|
287
|
+
op.lastError = error;
|
|
288
|
+
this.write(queue, projectDir);
|
|
289
|
+
}
|
|
290
|
+
},
|
|
291
|
+
};
|
|
292
|
+
/**
|
|
293
|
+
* Create a backup of a file
|
|
294
|
+
*/
|
|
295
|
+
function createBackup(filePath, projectDir) {
|
|
296
|
+
const backupsDir = (0, paths_1.getProjectBackupsDir)(projectDir);
|
|
297
|
+
(0, paths_1.ensureDir)(backupsDir);
|
|
298
|
+
const timestamp = new Date().toISOString().replace(/[.:]/g, "-");
|
|
299
|
+
const fileName = path.basename(filePath);
|
|
300
|
+
const backupPath = path.join(backupsDir, `${fileName}-${timestamp}`);
|
|
301
|
+
fs.copyFileSync(filePath, backupPath);
|
|
302
|
+
return backupPath;
|
|
303
|
+
}
|
|
304
|
+
exports.createBackup = createBackup;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Platform CLI Configuration Paths
|
|
3
|
+
*
|
|
4
|
+
* Manages file paths for global and project-level configuration.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Get the global configuration directory (~/.apso/)
|
|
8
|
+
* Can be overridden with APSO_CONFIG_DIR environment variable
|
|
9
|
+
*/
|
|
10
|
+
export declare function getGlobalConfigDir(): string;
|
|
11
|
+
/**
|
|
12
|
+
* Get path to global config file (~/.apso/config.json)
|
|
13
|
+
*/
|
|
14
|
+
export declare function getGlobalConfigPath(): string;
|
|
15
|
+
/**
|
|
16
|
+
* Get path to credentials file (~/.apso/credentials.json)
|
|
17
|
+
*/
|
|
18
|
+
export declare function getCredentialsPath(): string;
|
|
19
|
+
/**
|
|
20
|
+
* Get path to cache directory (~/.apso/cache/)
|
|
21
|
+
*/
|
|
22
|
+
export declare function getCacheDir(): string;
|
|
23
|
+
/**
|
|
24
|
+
* Get project-level config directory (.apso/)
|
|
25
|
+
* @param projectDir - The project directory (defaults to cwd)
|
|
26
|
+
*/
|
|
27
|
+
export declare function getProjectConfigDir(projectDir?: string): string;
|
|
28
|
+
/**
|
|
29
|
+
* Get path to project link file (.apso/link.json)
|
|
30
|
+
* @param projectDir - The project directory (defaults to cwd)
|
|
31
|
+
*/
|
|
32
|
+
export declare function getProjectLinkPath(projectDir?: string): string;
|
|
33
|
+
/**
|
|
34
|
+
* Get path to sync queue file (.apso/sync-queue.json)
|
|
35
|
+
* @param projectDir - The project directory (defaults to cwd)
|
|
36
|
+
*/
|
|
37
|
+
export declare function getSyncQueuePath(projectDir?: string): string;
|
|
38
|
+
/**
|
|
39
|
+
* Get path to project backups directory (.apso/backups/)
|
|
40
|
+
* @param projectDir - The project directory (defaults to cwd)
|
|
41
|
+
*/
|
|
42
|
+
export declare function getProjectBackupsDir(projectDir?: string): string;
|
|
43
|
+
/**
|
|
44
|
+
* Ensure a directory exists, creating it if necessary
|
|
45
|
+
* @param dirPath - Path to the directory
|
|
46
|
+
*/
|
|
47
|
+
export declare function ensureDir(dirPath: string): void;
|
|
48
|
+
/**
|
|
49
|
+
* Ensure the global config directory exists with correct permissions
|
|
50
|
+
*/
|
|
51
|
+
export declare function ensureGlobalConfigDir(): void;
|
|
52
|
+
/**
|
|
53
|
+
* Ensure the project config directory exists
|
|
54
|
+
* @param projectDir - The project directory (defaults to cwd)
|
|
55
|
+
*/
|
|
56
|
+
export declare function ensureProjectConfigDir(projectDir?: string): void;
|
|
57
|
+
/**
|
|
58
|
+
* Check if a project is linked to the platform
|
|
59
|
+
* @param projectDir - The project directory (defaults to cwd)
|
|
60
|
+
*/
|
|
61
|
+
export declare function isProjectLinked(projectDir?: string): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Check if user is authenticated (credentials file exists)
|
|
64
|
+
*/
|
|
65
|
+
export declare function hasCredentials(): boolean;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Platform CLI Configuration Paths
|
|
4
|
+
*
|
|
5
|
+
* Manages file paths for global and project-level configuration.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.hasCredentials = exports.isProjectLinked = exports.ensureProjectConfigDir = exports.ensureGlobalConfigDir = exports.ensureDir = exports.getProjectBackupsDir = exports.getSyncQueuePath = exports.getProjectLinkPath = exports.getProjectConfigDir = exports.getCacheDir = exports.getCredentialsPath = exports.getGlobalConfigPath = exports.getGlobalConfigDir = void 0;
|
|
9
|
+
const tslib_1 = require("tslib");
|
|
10
|
+
const path = tslib_1.__importStar(require("path"));
|
|
11
|
+
const os = tslib_1.__importStar(require("os"));
|
|
12
|
+
const fs = tslib_1.__importStar(require("fs"));
|
|
13
|
+
/**
|
|
14
|
+
* Get the global configuration directory (~/.apso/)
|
|
15
|
+
* Can be overridden with APSO_CONFIG_DIR environment variable
|
|
16
|
+
*/
|
|
17
|
+
function getGlobalConfigDir() {
|
|
18
|
+
const envDir = process.env.APSO_CONFIG_DIR;
|
|
19
|
+
if (envDir) {
|
|
20
|
+
return envDir;
|
|
21
|
+
}
|
|
22
|
+
return path.join(os.homedir(), ".apso");
|
|
23
|
+
}
|
|
24
|
+
exports.getGlobalConfigDir = getGlobalConfigDir;
|
|
25
|
+
/**
|
|
26
|
+
* Get path to global config file (~/.apso/config.json)
|
|
27
|
+
*/
|
|
28
|
+
function getGlobalConfigPath() {
|
|
29
|
+
return path.join(getGlobalConfigDir(), "config.json");
|
|
30
|
+
}
|
|
31
|
+
exports.getGlobalConfigPath = getGlobalConfigPath;
|
|
32
|
+
/**
|
|
33
|
+
* Get path to credentials file (~/.apso/credentials.json)
|
|
34
|
+
*/
|
|
35
|
+
function getCredentialsPath() {
|
|
36
|
+
return path.join(getGlobalConfigDir(), "credentials.json");
|
|
37
|
+
}
|
|
38
|
+
exports.getCredentialsPath = getCredentialsPath;
|
|
39
|
+
/**
|
|
40
|
+
* Get path to cache directory (~/.apso/cache/)
|
|
41
|
+
*/
|
|
42
|
+
function getCacheDir() {
|
|
43
|
+
return path.join(getGlobalConfigDir(), "cache");
|
|
44
|
+
}
|
|
45
|
+
exports.getCacheDir = getCacheDir;
|
|
46
|
+
/**
|
|
47
|
+
* Get project-level config directory (.apso/)
|
|
48
|
+
* @param projectDir - The project directory (defaults to cwd)
|
|
49
|
+
*/
|
|
50
|
+
function getProjectConfigDir(projectDir) {
|
|
51
|
+
return path.join(projectDir || process.cwd(), ".apso");
|
|
52
|
+
}
|
|
53
|
+
exports.getProjectConfigDir = getProjectConfigDir;
|
|
54
|
+
/**
|
|
55
|
+
* Get path to project link file (.apso/link.json)
|
|
56
|
+
* @param projectDir - The project directory (defaults to cwd)
|
|
57
|
+
*/
|
|
58
|
+
function getProjectLinkPath(projectDir) {
|
|
59
|
+
return path.join(getProjectConfigDir(projectDir), "link.json");
|
|
60
|
+
}
|
|
61
|
+
exports.getProjectLinkPath = getProjectLinkPath;
|
|
62
|
+
/**
|
|
63
|
+
* Get path to sync queue file (.apso/sync-queue.json)
|
|
64
|
+
* @param projectDir - The project directory (defaults to cwd)
|
|
65
|
+
*/
|
|
66
|
+
function getSyncQueuePath(projectDir) {
|
|
67
|
+
return path.join(getProjectConfigDir(projectDir), "sync-queue.json");
|
|
68
|
+
}
|
|
69
|
+
exports.getSyncQueuePath = getSyncQueuePath;
|
|
70
|
+
/**
|
|
71
|
+
* Get path to project backups directory (.apso/backups/)
|
|
72
|
+
* @param projectDir - The project directory (defaults to cwd)
|
|
73
|
+
*/
|
|
74
|
+
function getProjectBackupsDir(projectDir) {
|
|
75
|
+
return path.join(getProjectConfigDir(projectDir), "backups");
|
|
76
|
+
}
|
|
77
|
+
exports.getProjectBackupsDir = getProjectBackupsDir;
|
|
78
|
+
/**
|
|
79
|
+
* Ensure a directory exists, creating it if necessary
|
|
80
|
+
* @param dirPath - Path to the directory
|
|
81
|
+
*/
|
|
82
|
+
function ensureDir(dirPath) {
|
|
83
|
+
if (!fs.existsSync(dirPath)) {
|
|
84
|
+
fs.mkdirSync(dirPath, { recursive: true });
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.ensureDir = ensureDir;
|
|
88
|
+
/**
|
|
89
|
+
* Ensure the global config directory exists with correct permissions
|
|
90
|
+
*/
|
|
91
|
+
function ensureGlobalConfigDir() {
|
|
92
|
+
const configDir = getGlobalConfigDir();
|
|
93
|
+
ensureDir(configDir);
|
|
94
|
+
// Set restrictive permissions on Unix systems
|
|
95
|
+
if (process.platform !== "win32") {
|
|
96
|
+
try {
|
|
97
|
+
fs.chmodSync(configDir, 0o700);
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
// Ignore permission errors (e.g., on some CI systems)
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
exports.ensureGlobalConfigDir = ensureGlobalConfigDir;
|
|
105
|
+
/**
|
|
106
|
+
* Ensure the project config directory exists
|
|
107
|
+
* @param projectDir - The project directory (defaults to cwd)
|
|
108
|
+
*/
|
|
109
|
+
function ensureProjectConfigDir(projectDir) {
|
|
110
|
+
ensureDir(getProjectConfigDir(projectDir));
|
|
111
|
+
}
|
|
112
|
+
exports.ensureProjectConfigDir = ensureProjectConfigDir;
|
|
113
|
+
/**
|
|
114
|
+
* Check if a project is linked to the platform
|
|
115
|
+
* @param projectDir - The project directory (defaults to cwd)
|
|
116
|
+
*/
|
|
117
|
+
function isProjectLinked(projectDir) {
|
|
118
|
+
return fs.existsSync(getProjectLinkPath(projectDir));
|
|
119
|
+
}
|
|
120
|
+
exports.isProjectLinked = isProjectLinked;
|
|
121
|
+
/**
|
|
122
|
+
* Check if user is authenticated (credentials file exists)
|
|
123
|
+
*/
|
|
124
|
+
function hasCredentials() {
|
|
125
|
+
return fs.existsSync(getCredentialsPath());
|
|
126
|
+
}
|
|
127
|
+
exports.hasCredentials = hasCredentials;
|