@pmate/cli 0.20.11 → 0.21.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/dist/index.d.ts +1 -0
- package/dist/index.js +67 -13
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -158,7 +158,15 @@ function loadExistingSessionStoreOrEmpty() {
|
|
|
158
158
|
sessions: {}
|
|
159
159
|
};
|
|
160
160
|
}
|
|
161
|
-
|
|
161
|
+
try {
|
|
162
|
+
return loadSessionStore();
|
|
163
|
+
} catch {
|
|
164
|
+
return {
|
|
165
|
+
version: SESSION_STORE_VERSION,
|
|
166
|
+
activeAppRef: DEFAULT_APP_ID,
|
|
167
|
+
sessions: {}
|
|
168
|
+
};
|
|
169
|
+
}
|
|
162
170
|
}
|
|
163
171
|
function loadSessionStoreWithPath() {
|
|
164
172
|
const sessionPath = buildSessionStorePath();
|
|
@@ -21009,15 +21017,24 @@ var ServiceRegistryClient = class {
|
|
|
21009
21017
|
if (repository) {
|
|
21010
21018
|
searchParams.set("repo", repository);
|
|
21011
21019
|
}
|
|
21020
|
+
const server = filters?.server?.trim();
|
|
21021
|
+
if (server) {
|
|
21022
|
+
searchParams.set("server", server);
|
|
21023
|
+
}
|
|
21012
21024
|
const payload = await this.request(
|
|
21013
21025
|
"GET",
|
|
21014
21026
|
`/services${searchParams.size > 0 ? `?${searchParams.toString()}` : ""}`
|
|
21015
21027
|
);
|
|
21016
21028
|
const namespace = filters?.namespace?.trim();
|
|
21017
|
-
|
|
21018
|
-
|
|
21019
|
-
|
|
21020
|
-
|
|
21029
|
+
return payload.items.filter((item) => {
|
|
21030
|
+
if (namespace && item.namespace !== namespace) {
|
|
21031
|
+
return false;
|
|
21032
|
+
}
|
|
21033
|
+
if (server && item.deploy?.server?.trim() !== server) {
|
|
21034
|
+
return false;
|
|
21035
|
+
}
|
|
21036
|
+
return true;
|
|
21037
|
+
});
|
|
21021
21038
|
}
|
|
21022
21039
|
async getService(namespace, name) {
|
|
21023
21040
|
return this.request(
|
|
@@ -21087,7 +21104,8 @@ var ServiceCommandHandler = class {
|
|
|
21087
21104
|
case "list": {
|
|
21088
21105
|
const items = await registry.listServices({
|
|
21089
21106
|
namespace: args.namespace,
|
|
21090
|
-
repository: args.repository
|
|
21107
|
+
repository: args.repository,
|
|
21108
|
+
server: args.server
|
|
21091
21109
|
});
|
|
21092
21110
|
this.renderList(items, args.json);
|
|
21093
21111
|
return;
|
|
@@ -21101,6 +21119,7 @@ var ServiceCommandHandler = class {
|
|
|
21101
21119
|
case "create": {
|
|
21102
21120
|
const payload = this.readJsonFile(args.filePath);
|
|
21103
21121
|
await this.requireNamespace(payload, baseUrl);
|
|
21122
|
+
await this.requireUniqueServerPort(payload, registry);
|
|
21104
21123
|
const record = await this.request(
|
|
21105
21124
|
baseUrl,
|
|
21106
21125
|
"POST",
|
|
@@ -21113,6 +21132,10 @@ var ServiceCommandHandler = class {
|
|
|
21113
21132
|
}
|
|
21114
21133
|
case "update": {
|
|
21115
21134
|
const payload = this.readJsonFile(args.filePath);
|
|
21135
|
+
await this.requireUniqueServerPort(payload, registry, {
|
|
21136
|
+
namespace: args.namespace,
|
|
21137
|
+
name: args.name
|
|
21138
|
+
});
|
|
21116
21139
|
const record = await this.request(
|
|
21117
21140
|
baseUrl,
|
|
21118
21141
|
"PUT",
|
|
@@ -21225,6 +21248,37 @@ var ServiceCommandHandler = class {
|
|
|
21225
21248
|
throw new Error(`Namespace "${namespace}" is not registered. Run: pmate ns create ${namespace}`);
|
|
21226
21249
|
}
|
|
21227
21250
|
}
|
|
21251
|
+
async requireUniqueServerPort(payload, registry, currentService) {
|
|
21252
|
+
if (!payload || typeof payload !== "object") {
|
|
21253
|
+
return;
|
|
21254
|
+
}
|
|
21255
|
+
const deploy = payload.deploy;
|
|
21256
|
+
if (!deploy || typeof deploy !== "object") {
|
|
21257
|
+
return;
|
|
21258
|
+
}
|
|
21259
|
+
const serverValue = deploy.server;
|
|
21260
|
+
const portValue = deploy.port;
|
|
21261
|
+
const server = typeof serverValue === "string" ? serverValue.trim() : "";
|
|
21262
|
+
const port = typeof portValue === "number" ? portValue : typeof portValue === "string" && portValue.trim() ? Number(portValue) : void 0;
|
|
21263
|
+
if (!server || port === void 0 || !Number.isFinite(port)) {
|
|
21264
|
+
return;
|
|
21265
|
+
}
|
|
21266
|
+
const services = await registry.listServices({ server });
|
|
21267
|
+
const conflict = services.find((service) => {
|
|
21268
|
+
if (service.deploy?.port !== port) {
|
|
21269
|
+
return false;
|
|
21270
|
+
}
|
|
21271
|
+
if (!currentService) {
|
|
21272
|
+
return true;
|
|
21273
|
+
}
|
|
21274
|
+
return !(service.namespace === currentService.namespace && service.name === currentService.name);
|
|
21275
|
+
});
|
|
21276
|
+
if (conflict) {
|
|
21277
|
+
throw new Error(
|
|
21278
|
+
`Port ${port} is already used on server ${server} by ${formatNamespacedDisplayId(conflict.namespace, conflict.name)}`
|
|
21279
|
+
);
|
|
21280
|
+
}
|
|
21281
|
+
}
|
|
21228
21282
|
renderList(items, asJson) {
|
|
21229
21283
|
if (asJson) {
|
|
21230
21284
|
ui.plain(JSON.stringify(items, null, 2));
|
|
@@ -21235,11 +21289,7 @@ var ServiceCommandHandler = class {
|
|
|
21235
21289
|
return;
|
|
21236
21290
|
}
|
|
21237
21291
|
for (const item of items) {
|
|
21238
|
-
ui.info(formatNamespacedDisplayId(item.namespace, item.name),
|
|
21239
|
-
kind: item.kind,
|
|
21240
|
-
runtimeType: item.runtimeType,
|
|
21241
|
-
status: item.status
|
|
21242
|
-
});
|
|
21292
|
+
ui.info(formatNamespacedDisplayId(item.namespace, item.name), item);
|
|
21243
21293
|
}
|
|
21244
21294
|
}
|
|
21245
21295
|
renderJson(value, asJson) {
|
|
@@ -22375,6 +22425,7 @@ function parseServiceArgs(tokens) {
|
|
|
22375
22425
|
if (action === "list") {
|
|
22376
22426
|
let namespace;
|
|
22377
22427
|
let repository;
|
|
22428
|
+
let server;
|
|
22378
22429
|
while (rest.length > 0) {
|
|
22379
22430
|
const token = rest.shift();
|
|
22380
22431
|
switch (token) {
|
|
@@ -22384,6 +22435,9 @@ function parseServiceArgs(tokens) {
|
|
|
22384
22435
|
case "--repo":
|
|
22385
22436
|
repository = requireValue5(rest, token);
|
|
22386
22437
|
break;
|
|
22438
|
+
case "--server":
|
|
22439
|
+
server = requireValue5(rest, token);
|
|
22440
|
+
break;
|
|
22387
22441
|
case "--base-url":
|
|
22388
22442
|
baseUrl = requireValue5(rest, token);
|
|
22389
22443
|
break;
|
|
@@ -22394,7 +22448,7 @@ function parseServiceArgs(tokens) {
|
|
|
22394
22448
|
throw new Error(`Unknown service list option: ${token}`);
|
|
22395
22449
|
}
|
|
22396
22450
|
}
|
|
22397
|
-
return { type: "service" /* Service */, action, namespace, repository, baseUrl, json };
|
|
22451
|
+
return { type: "service" /* Service */, action, namespace, repository, server, baseUrl, json };
|
|
22398
22452
|
}
|
|
22399
22453
|
if (action === "view") {
|
|
22400
22454
|
const ref = rest.shift();
|
|
@@ -22935,7 +22989,7 @@ var HELP_TEXT = [
|
|
|
22935
22989
|
` ${import_chalk4.default.gray(" delete <ns:objectId> [--base-url <url>] [--json]")}`,
|
|
22936
22990
|
` ${import_chalk4.default.gray(" default base URL: https://apps-api.pmate.chat")}`,
|
|
22937
22991
|
` ${import_chalk4.default.cyan("service")} Manage service registry entries via apps-api`,
|
|
22938
|
-
` ${import_chalk4.default.gray(" list [--namespace <ns>] [--repo <owner/name|https://github.com/owner/name>] [--base-url <url>] [--json]")}`,
|
|
22992
|
+
` ${import_chalk4.default.gray(" list [--namespace <ns>] [--repo <owner/name|https://github.com/owner/name>] [--server <name>] [--base-url <url>] [--json]")}`,
|
|
22939
22993
|
` ${import_chalk4.default.gray(" get <ns:objectId> [--base-url <url>] [--json]")}`,
|
|
22940
22994
|
` ${import_chalk4.default.gray(" view <ns:objectId> [--base-url <url>]")}`,
|
|
22941
22995
|
` ${import_chalk4.default.gray(" create --file <path> [--base-url <url>] [--json]")}`,
|