@spica/cli 0.9.25 → 0.9.27
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/index.js +1 -1
- package/package.json +3 -2
- package/src/commands/asset/apply.js +50 -0
- package/src/commands/asset/apply.js.map +1 -0
- package/src/commands/asset/delete.js +34 -0
- package/src/commands/asset/delete.js.map +1 -0
- package/src/commands/bucket/orm.d.ts +4 -1
- package/src/commands/bucket/orm.js +313 -80
- package/src/commands/bucket/orm.js.map +1 -1
- package/src/representative.d.ts +13 -0
- package/src/representative.js +124 -0
- package/src/representative.js.map +1 -0
- package/src/commands/objects/apply.js +0 -69
- package/src/commands/objects/apply.js.map +0 -1
- package/src/commands/objects/delete.js +0 -53
- package/src/commands/objects/delete.js.map +0 -1
- package/src/commands/objects/get.d.ts +0 -2
- package/src/commands/objects/get.js +0 -94
- package/src/commands/objects/get.js.map +0 -1
- /package/src/commands/{objects → asset}/apply.d.ts +0 -0
- /package/src/commands/{objects → asset}/delete.d.ts +0 -0
package/index.js
CHANGED
|
@@ -21,7 +21,7 @@ function run(argv) {
|
|
|
21
21
|
const commandPath = path.join(__dirname, "src", "commands");
|
|
22
22
|
cleanUpDts(commandPath);
|
|
23
23
|
core_1.program
|
|
24
|
-
.version("0.9.
|
|
24
|
+
.version("0.9.27")
|
|
25
25
|
.name("spica")
|
|
26
26
|
.bin("spica")
|
|
27
27
|
.description("Command line interface for spica.")
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spica/cli",
|
|
3
3
|
"license": "AGPLv3",
|
|
4
|
-
"version": "0.9.
|
|
4
|
+
"version": "0.9.27",
|
|
5
5
|
"description": "Command line interface for Spica",
|
|
6
6
|
"author": "spica",
|
|
7
7
|
"main": "index.js",
|
|
@@ -23,7 +23,8 @@
|
|
|
23
23
|
"jsonpath": "^1.0.2",
|
|
24
24
|
"cli-color": "^2.0.0",
|
|
25
25
|
"semver": "^7.3.2",
|
|
26
|
-
"typescript": "^4.5.4"
|
|
26
|
+
"typescript": "^4.5.4",
|
|
27
|
+
"dotenv":"^16.0.3"
|
|
27
28
|
},
|
|
28
29
|
"devDependencies": {
|
|
29
30
|
"@bazel/typescript": "^4.6.0",
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const http_1 = require("../../http");
|
|
4
|
+
const representative_1 = require("../../representative");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const fs = require("fs");
|
|
7
|
+
const YAML = require("yaml");
|
|
8
|
+
async function apply({ options }) {
|
|
9
|
+
const folderPath = options.path || process.cwd();
|
|
10
|
+
const repManager = new representative_1.RepresentativeManager(folderPath);
|
|
11
|
+
const moduleAndFiles = new Map();
|
|
12
|
+
moduleAndFiles.set("bucket", ["schema.yaml"]);
|
|
13
|
+
moduleAndFiles.set("function", [
|
|
14
|
+
"schema.yaml",
|
|
15
|
+
"package.json",
|
|
16
|
+
"env.env",
|
|
17
|
+
"index.ts",
|
|
18
|
+
"index.js"
|
|
19
|
+
]);
|
|
20
|
+
moduleAndFiles.set("preference", ["schema.yaml"]);
|
|
21
|
+
moduleAndFiles.set("dashboard", ["schema.yaml"]);
|
|
22
|
+
moduleAndFiles.set("apikey", ["schema.yaml"]);
|
|
23
|
+
const resourceNameValidator = id => id.match(/^([0-9a-fA-F]{24}$)|identity/);
|
|
24
|
+
const resources = [];
|
|
25
|
+
for (let [_module, fileNames] of moduleAndFiles.entries()) {
|
|
26
|
+
let resource = await repManager.read(_module, resourceNameValidator, fileNames);
|
|
27
|
+
resource = resource.map(r => {
|
|
28
|
+
r.module = _module;
|
|
29
|
+
return r;
|
|
30
|
+
});
|
|
31
|
+
resources.push(...resource);
|
|
32
|
+
}
|
|
33
|
+
const filename = path.relative(folderPath, "asset.yaml");
|
|
34
|
+
const rawDocument = fs.readFileSync(filename).toString();
|
|
35
|
+
const assetMeta = YAML.parseDocument(rawDocument);
|
|
36
|
+
const body = {
|
|
37
|
+
...assetMeta.toJSON(),
|
|
38
|
+
resources
|
|
39
|
+
};
|
|
40
|
+
const client = await http_1.httpService.createFromCurrentCtx();
|
|
41
|
+
await client.post("/asset", body);
|
|
42
|
+
return console.info(`Asset ${body.name} has been uploaded successfully`);
|
|
43
|
+
}
|
|
44
|
+
function default_1({ createCommand }) {
|
|
45
|
+
return createCommand("Put objects to the API.")
|
|
46
|
+
.option("--path <path>", "Path of the folder that container asset.yaml file and resources of it. Current working directory is the default value.")
|
|
47
|
+
.action(apply);
|
|
48
|
+
}
|
|
49
|
+
exports.default = default_1;
|
|
50
|
+
//# sourceMappingURL=apply.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply.js","sourceRoot":"","sources":["../../../../../../../../stacks/cli/src/commands/asset/apply.ts"],"names":[],"mappings":";;AACA,qCAAuC;AACvC,yDAA2D;AAE3D,6BAA6B;AAC7B,yBAAyB;AACzB,6BAA6B;AAE7B,KAAK,UAAU,KAAK,CAAC,EAAC,OAAO,EAAmB;IAC9C,MAAM,UAAU,GAAI,OAAO,CAAC,IAAe,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;IAC7D,MAAM,UAAU,GAAG,IAAI,sCAAqB,CAAC,UAAU,CAAC,CAAC;IACzD,MAAM,cAAc,GAAG,IAAI,GAAG,EAAoB,CAAC;IAEnD,cAAc,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC;IAC9C,cAAc,CAAC,GAAG,CAAC,UAAU,EAAE;QAC7B,aAAa;QACb,cAAc;QACd,SAAS;QACT,UAAU;QACV,UAAU;KACX,CAAC,CAAC;IACH,cAAc,CAAC,GAAG,CAAC,YAAY,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC;IAClD,cAAc,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC;IACjD,cAAc,CAAC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AAwH,CACzH;SACA,MAAM,CAAE,KAA2B,CAAC,CAAC;AAC1C,CAAC;AAPD,4BAOC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const http_1 = require("../../http");
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const YAML = require("yaml");
|
|
6
|
+
async function _delete({ options }) {
|
|
7
|
+
const type = options.type;
|
|
8
|
+
const folderPath = options.path || process.cwd();
|
|
9
|
+
const rawDocument = fs.readFileSync(folderPath).toString();
|
|
10
|
+
const assetMeta = YAML.parseDocument(rawDocument).toJSON();
|
|
11
|
+
const client = await http_1.httpService.createFromCurrentCtx();
|
|
12
|
+
const asset = await client
|
|
13
|
+
.get("/asset", {
|
|
14
|
+
params: {
|
|
15
|
+
name: assetMeta.name
|
|
16
|
+
}
|
|
17
|
+
})
|
|
18
|
+
.then(r => r[0]);
|
|
19
|
+
if (!asset) {
|
|
20
|
+
console.error(`Asset ${assetMeta.name} does not exist`);
|
|
21
|
+
}
|
|
22
|
+
await client.delete(`/asset/${asset._id}`, { params: { type } });
|
|
23
|
+
return console.info("Asset ${assetMeta.name} has been deleted successfully");
|
|
24
|
+
}
|
|
25
|
+
function default_1({ createCommand }) {
|
|
26
|
+
return createCommand("Delete objects of the API.")
|
|
27
|
+
.option("--path <path>", "Path of the folder that container asset.yaml file and resources of it. Current working directory is the default value.")
|
|
28
|
+
.option("--type <type>", "Deletion type. Available options are 'soft' and 'hard'", {
|
|
29
|
+
required: true
|
|
30
|
+
})
|
|
31
|
+
.action(_delete);
|
|
32
|
+
}
|
|
33
|
+
exports.default = default_1;
|
|
34
|
+
//# sourceMappingURL=delete.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete.js","sourceRoot":"","sources":["../../../../../../../../stacks/cli/src/commands/asset/delete.ts"],"names":[],"mappings":";;AACA,qCAAuC;AACvC,yBAAyB;AACzB,6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1
1
|
import { Command, CreateCommandParameters } from "@caporal/core";
|
|
2
2
|
export default function ({ createCommand }: CreateCommandParameters): Command;
|
|
3
3
|
export declare namespace Schema {
|
|
4
|
-
function createFileContent(buckets: BucketSchema[], apiurl: string, warnings: string[]): string;
|
|
4
|
+
function createFileContent(buckets: BucketSchema[], languages: string[], apiurl: string, warnings: string[]): string;
|
|
5
5
|
}
|
|
6
6
|
export interface BucketSchema {
|
|
7
7
|
_id: string;
|
|
@@ -21,6 +21,9 @@ interface IProperty {
|
|
|
21
21
|
}
|
|
22
22
|
interface BasicProperty extends IProperty {
|
|
23
23
|
type: "string" | "textarea" | "color" | "richtext" | "storage" | "number" | "date" | "boolean";
|
|
24
|
+
options: {
|
|
25
|
+
translate: boolean;
|
|
26
|
+
};
|
|
24
27
|
}
|
|
25
28
|
interface ArrayProperty extends IProperty {
|
|
26
29
|
type: "array" | "multiselect";
|
|
@@ -15,9 +15,12 @@ async function orm({ options }) {
|
|
|
15
15
|
text: "Fetching buckets..",
|
|
16
16
|
op: async (spinner) => {
|
|
17
17
|
const buckets = await httpClient.get("/bucket");
|
|
18
|
+
const languages = await httpClient
|
|
19
|
+
.get("/preference/bucket")
|
|
20
|
+
.then(r => Object.keys(r.language.available));
|
|
18
21
|
spinner.text = "Building interface and method definitions..";
|
|
19
22
|
const warnings = [];
|
|
20
|
-
const content = Schema.createFileContent(buckets, url, warnings);
|
|
23
|
+
const content = Schema.createFileContent(buckets, languages, url, warnings);
|
|
21
24
|
spinner.text = "Writing to the destination..";
|
|
22
25
|
fs.writeFileSync(DESTINATION, content);
|
|
23
26
|
spinner.text = `Succesfully completed! File url is ${PATH ? DESTINATION : path.join(process.cwd(), "bucket.ts")}`;
|
|
@@ -35,7 +38,8 @@ function default_1({ createCommand }) {
|
|
|
35
38
|
exports.default = default_1;
|
|
36
39
|
var Schema;
|
|
37
40
|
(function (Schema) {
|
|
38
|
-
function createFileContent(buckets, apiurl, warnings) {
|
|
41
|
+
function createFileContent(buckets, languages, apiurl, warnings) {
|
|
42
|
+
const languagesDefinition = `${languages.map(i => `'${i}'`).join("|")}`;
|
|
39
43
|
let lines = [];
|
|
40
44
|
lines.push("import * as Bucket from '@spica-devkit/bucket';");
|
|
41
45
|
lines.push(`
|
|
@@ -55,86 +59,285 @@ var Schema;
|
|
|
55
59
|
lines.push("\ntype realtimeGetArgs = Rest<Parameters<typeof Bucket.data.realtime.get>>;");
|
|
56
60
|
lines.push("\ntype realtimeGetAllArgs = Rest<Parameters<typeof Bucket.data.realtime.getAll>>;");
|
|
57
61
|
lines.push("\ntype id = { _id: string };");
|
|
62
|
+
lines.push(`
|
|
63
|
+
|
|
64
|
+
type Find<Targets extends string[], Search extends string> = {
|
|
65
|
+
[K in keyof Targets]: Targets[K] extends \`\${Search}.$\{infer Rest}\`
|
|
66
|
+
? Targets[K]
|
|
67
|
+
: Targets[K] extends \`\${Search}\`
|
|
68
|
+
? Targets[K]
|
|
69
|
+
: never;
|
|
70
|
+
}[number];
|
|
71
|
+
|
|
72
|
+
type FindRest<T extends string[], S extends string> = {
|
|
73
|
+
[K in keyof T]: T[K] extends \`\${S}.$\{infer Rest}\`
|
|
74
|
+
? Rest
|
|
75
|
+
: never
|
|
76
|
+
}[number];
|
|
77
|
+
|
|
78
|
+
type ConvertEnumToSelection<T extends string[]> = T extends []
|
|
79
|
+
? []
|
|
80
|
+
: T extends (infer U)[]
|
|
81
|
+
? [U, ...U[]]
|
|
82
|
+
: [];
|
|
83
|
+
|
|
84
|
+
type Props<T> = {
|
|
85
|
+
[K in keyof T]: K;
|
|
86
|
+
}[keyof T];
|
|
87
|
+
|
|
88
|
+
type RemoveProps<TClass, TProps extends keyof TClass> = {
|
|
89
|
+
[K in keyof TClass as K extends TProps ? never : K]: TClass[K];
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
type AvailableLanguages = ${languagesDefinition}
|
|
93
|
+
|
|
94
|
+
`);
|
|
58
95
|
buckets = makeTitlesUnique(buckets, warnings);
|
|
59
96
|
for (const bucket of buckets) {
|
|
60
|
-
buildInterface(bucket, lines);
|
|
61
|
-
buildMethod(bucket, lines);
|
|
97
|
+
buildInterface(bucket, languages, lines);
|
|
62
98
|
}
|
|
63
99
|
lines = replaceRelations(buckets, lines);
|
|
100
|
+
lines = addCrud(lines, buckets, languages);
|
|
64
101
|
return lines.join("");
|
|
65
102
|
}
|
|
66
103
|
Schema.createFileContent = createFileContent;
|
|
67
|
-
function
|
|
104
|
+
function addCrud(lines, buckets, languages) {
|
|
105
|
+
const crud = `
|
|
106
|
+
class CRUD<Scheme,Paginate extends boolean = false> {
|
|
107
|
+
protected options: {
|
|
108
|
+
headers: {
|
|
109
|
+
'accept-language'?: string;
|
|
110
|
+
};
|
|
111
|
+
queryParams: {
|
|
112
|
+
limit?: number;
|
|
113
|
+
skip?: number;
|
|
114
|
+
sort?: {
|
|
115
|
+
[T in keyof Scheme]: -1 | 1;
|
|
116
|
+
};
|
|
117
|
+
paginate?: boolean;
|
|
118
|
+
|
|
119
|
+
relation?: string[];
|
|
120
|
+
localize?: boolean;
|
|
121
|
+
filter?: any;
|
|
122
|
+
};
|
|
123
|
+
} = {
|
|
124
|
+
headers: {},
|
|
125
|
+
queryParams: {},
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
constructor(
|
|
129
|
+
protected bucketId: string,
|
|
130
|
+
protected bdService: typeof Bucket.data,
|
|
131
|
+
protected relationalFields: string[]
|
|
132
|
+
) {}
|
|
133
|
+
|
|
134
|
+
private normalizeRelations(document: any) {
|
|
135
|
+
this.relationalFields.forEach((field) => {
|
|
136
|
+
if (typeof document[field] == 'object') {
|
|
137
|
+
document[field] = Array.isArray(document[field])
|
|
138
|
+
? document[field].map((v: any) => v._id || v)
|
|
139
|
+
: document[field]._id;
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
return document;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
private buildOptions(options: any) {
|
|
146
|
+
options = options ? options : this.options;
|
|
147
|
+
this.options = {
|
|
148
|
+
headers: {},
|
|
149
|
+
queryParams: {},
|
|
150
|
+
};
|
|
151
|
+
return options;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
get(...args: getArgs) {
|
|
155
|
+
args[1] = this.buildOptions(args[1]);
|
|
156
|
+
return this.bdService.get<Scheme & id>(this.bucketId, ...args);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
getAll(
|
|
160
|
+
...args: getAllArgs
|
|
161
|
+
): Paginate extends true
|
|
162
|
+
? Promise<Bucket.IndexResult<Scheme>>
|
|
163
|
+
: Promise<Scheme[]> {
|
|
164
|
+
args[0] = this.buildOptions(args[0]);
|
|
165
|
+
return this.bdService.getAll<Scheme & id>(
|
|
166
|
+
this.bucketId,
|
|
167
|
+
...args
|
|
168
|
+
) as Paginate extends true
|
|
169
|
+
? Promise<Bucket.IndexResult<Scheme>>
|
|
170
|
+
: Promise<Scheme[]>;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
insert(document: Omit<Scheme, '_id'>) {
|
|
174
|
+
document = this.normalizeRelations(document);
|
|
175
|
+
return this.bdService.insert(this.bucketId, document);
|
|
176
|
+
}
|
|
177
|
+
update(document: Scheme & id) {
|
|
178
|
+
document = this.normalizeRelations(document);
|
|
179
|
+
return this.bdService.update(this.bucketId, document._id, document);
|
|
180
|
+
}
|
|
181
|
+
patch(document: Partial<Scheme> & id) {
|
|
182
|
+
document = this.normalizeRelations(document);
|
|
183
|
+
return this.bdService.patch(this.bucketId, document._id, document);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
remove(documentId: string) {
|
|
187
|
+
return this.bdService.remove(this.bucketId, documentId);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
realtime = {
|
|
191
|
+
get: (...args: realtimeGetArgs) => {
|
|
192
|
+
return this.bdService.realtime.get<Scheme & id>(
|
|
193
|
+
this.bucketId,
|
|
194
|
+
...args
|
|
195
|
+
);
|
|
196
|
+
},
|
|
197
|
+
getAll: (...args: realtimeGetAllArgs) => {
|
|
198
|
+
return this.bdService.realtime.getAll<Scheme & id>(
|
|
199
|
+
this.bucketId,
|
|
200
|
+
...args
|
|
201
|
+
);
|
|
202
|
+
},
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
class Cursor<Scheme,Paginate extends boolean = false> extends CRUD<Scheme,Paginate>{
|
|
207
|
+
limit(limit: number): any {
|
|
208
|
+
this.options.queryParams.limit = limit;
|
|
209
|
+
return this;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
skip(skip: number): any {
|
|
213
|
+
this.options.queryParams.skip = skip;
|
|
214
|
+
return this;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
sort(sort: { [T in keyof Scheme]: -1 | 1 }): any {
|
|
218
|
+
this.options.queryParams.sort = sort;
|
|
219
|
+
return this;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
filter(filter: any): any {
|
|
223
|
+
this.options.queryParams.filter = filter;
|
|
224
|
+
return this;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
translate(language: AvailableLanguages): any {
|
|
228
|
+
this.options.headers['accept-language'] = language;
|
|
229
|
+
return this;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
paginate(): any {
|
|
233
|
+
this.options.queryParams.paginate = true;
|
|
234
|
+
return this;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
nonLocalize(): any {
|
|
238
|
+
this.options.queryParams.localize = false;
|
|
239
|
+
return this;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
resolveRelations(relation:any): any {
|
|
243
|
+
this.options.queryParams.relation = relation;
|
|
244
|
+
return this;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
`;
|
|
248
|
+
lines.push("\n");
|
|
249
|
+
lines.push(crud);
|
|
250
|
+
for (let bucket of buckets) {
|
|
251
|
+
const property = prepareNamespace(bucket.title);
|
|
252
|
+
const interfaceName = prepareInterfaceTitle(bucket.title);
|
|
253
|
+
const bucketId = bucket._id;
|
|
254
|
+
const bdService = "Bucket.data";
|
|
255
|
+
const relationalFields = getRelationFields(bucket.properties);
|
|
256
|
+
const relationalFieldsDefinition = `[${relationalFields.map(i => `'${i}'`).join(",")}]`;
|
|
257
|
+
const resolveRelationEnums = getResolveRelationEnums(bucket._id, buckets);
|
|
258
|
+
const resolveRelationEnumsDefinition = resolveRelationEnums.length
|
|
259
|
+
? `(${resolveRelationEnums.map(i => `'${i}'`).join("|")})[]`
|
|
260
|
+
: "[]";
|
|
261
|
+
const crudDefinition = `
|
|
262
|
+
const ${interfaceName}RelationFields: string[] = ${relationalFieldsDefinition}
|
|
263
|
+
type ${interfaceName}RelationEnum = ${resolveRelationEnumsDefinition}
|
|
264
|
+
type ${interfaceName}RelationSelection = ConvertEnumToSelection<${interfaceName}RelationEnum>
|
|
265
|
+
type ${interfaceName}CursorMethods<
|
|
266
|
+
R extends string[] = [],
|
|
267
|
+
P extends boolean = false,
|
|
268
|
+
L extends boolean = true
|
|
269
|
+
> = RemoveProps<
|
|
270
|
+
${interfaceName}Cursor<R, P, L>,
|
|
271
|
+
Exclude<Props<CRUD<${interfaceName}<R, L>, P>>, 'get' | 'getAll'>
|
|
272
|
+
>;
|
|
273
|
+
|
|
274
|
+
class ${interfaceName}Cursor<R extends string[] = [], P extends boolean = false, L extends boolean = true> extends Cursor<${interfaceName}<R,L>,P>{
|
|
275
|
+
|
|
276
|
+
override resolveRelations<Selecteds extends ${interfaceName}RelationSelection>(
|
|
277
|
+
relations: Selecteds
|
|
278
|
+
): ${interfaceName}CursorMethods<Selecteds, P, L> {
|
|
279
|
+
return super.resolveRelations(relations);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
override nonLocalize(): ${interfaceName}CursorMethods<R, P, false> {
|
|
283
|
+
return super.nonLocalize();
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
override limit(limit: number): ${interfaceName}CursorMethods<R, P, L> {
|
|
287
|
+
return super.limit(limit);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
override skip(skip: number): ${interfaceName}CursorMethods<R, P, L> {
|
|
291
|
+
return super.skip(skip);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
override sort(sort: {
|
|
295
|
+
[T in keyof ${interfaceName}]: -1 | 1;
|
|
296
|
+
}): ${interfaceName}CursorMethods<R, P, L> {
|
|
297
|
+
return super.sort(sort);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
override filter(filter: any): ${interfaceName}CursorMethods<R, P, L> {
|
|
301
|
+
return super.filter(filter);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
override translate(
|
|
305
|
+
language: AvailableLanguages
|
|
306
|
+
): ${interfaceName}CursorMethods<R, P, L> {
|
|
307
|
+
return super.translate(language);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
override paginate(): ${interfaceName}CursorMethods<R, true, L> {
|
|
311
|
+
return super.paginate();
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
}
|
|
315
|
+
`;
|
|
316
|
+
lines.push(crudDefinition);
|
|
317
|
+
const definition = `
|
|
318
|
+
export const ${property} = new ${interfaceName}Cursor('${bucketId}',${bdService},${interfaceName}RelationFields)
|
|
319
|
+
`;
|
|
320
|
+
lines.push(definition);
|
|
321
|
+
}
|
|
322
|
+
return lines;
|
|
323
|
+
}
|
|
324
|
+
function buildInterface(schema, languages, lines) {
|
|
68
325
|
const name = prepareInterfaceTitle(schema.title);
|
|
69
|
-
lines.push(`\n\nexport interface ${name}{`);
|
|
326
|
+
lines.push(`\n\nexport interface ${name}<Relations extends string[] = [], Localize extends boolean = true>{`);
|
|
70
327
|
lines.push(`\n _id?: string;`);
|
|
71
|
-
buildProperties(schema.properties, schema.required || [], "bucket", lines);
|
|
328
|
+
buildProperties(schema.properties, languages, schema.required || [], "bucket", lines);
|
|
72
329
|
lines.push("\n}");
|
|
73
330
|
}
|
|
74
331
|
function prepareInterfaceTitle(str) {
|
|
75
332
|
str = replaceNonWords(str);
|
|
76
333
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
77
334
|
}
|
|
78
|
-
function buildMethod(schema, lines) {
|
|
79
|
-
const namespace = prepareNamespace(schema.title);
|
|
80
|
-
const interfaceName = prepareInterfaceTitle(schema.title);
|
|
81
|
-
lines.push(`\nexport namespace ${namespace} {`);
|
|
82
|
-
lines.push(`\n const BUCKET_ID = '${schema._id}';`);
|
|
83
|
-
lines.push(`
|
|
84
|
-
export function get (...args: getArgs) {
|
|
85
|
-
return Bucket.data.get<${interfaceName} & id>(BUCKET_ID, ...args);
|
|
86
|
-
};`);
|
|
87
|
-
lines.push(`
|
|
88
|
-
export function getAll (...args: getAllArgs) {
|
|
89
|
-
return Bucket.data.getAll<${interfaceName} & id>(BUCKET_ID, ...args);
|
|
90
|
-
};`);
|
|
91
|
-
const relationFields = getRelationFields(schema.properties);
|
|
92
|
-
const normalizeRelationCode = relationFields.length
|
|
93
|
-
? getNormalizeRelationCode(relationFields)
|
|
94
|
-
: "";
|
|
95
|
-
lines.push(`
|
|
96
|
-
export function insert (document: Omit<${interfaceName}, "_id">) {
|
|
97
|
-
${normalizeRelationCode}
|
|
98
|
-
return Bucket.data.insert(BUCKET_ID, document);
|
|
99
|
-
};`);
|
|
100
|
-
lines.push(`
|
|
101
|
-
export function update (document: ${interfaceName} & id) {
|
|
102
|
-
${normalizeRelationCode}
|
|
103
|
-
return Bucket.data.update(
|
|
104
|
-
BUCKET_ID,
|
|
105
|
-
document._id,
|
|
106
|
-
document
|
|
107
|
-
);
|
|
108
|
-
};`);
|
|
109
|
-
lines.push(`
|
|
110
|
-
export function patch (
|
|
111
|
-
document: Partial<${interfaceName}> & id
|
|
112
|
-
) {
|
|
113
|
-
${normalizeRelationCode}
|
|
114
|
-
return Bucket.data.patch(BUCKET_ID, document._id, document);
|
|
115
|
-
};`);
|
|
116
|
-
lines.push(`
|
|
117
|
-
export function remove (documentId: string) {
|
|
118
|
-
return Bucket.data.remove(BUCKET_ID, documentId);
|
|
119
|
-
};`);
|
|
120
|
-
lines.push("\n export namespace realtime {");
|
|
121
|
-
lines.push(`
|
|
122
|
-
export function get (...args: realtimeGetArgs) {
|
|
123
|
-
return Bucket.data.realtime.get<${interfaceName} & id>(BUCKET_ID, ...args);
|
|
124
|
-
};`);
|
|
125
|
-
lines.push(`
|
|
126
|
-
export function getAll (...args: realtimeGetAllArgs) {
|
|
127
|
-
return Bucket.data.realtime.getAll<${interfaceName} & id>(BUCKET_ID, ...args);
|
|
128
|
-
};`);
|
|
129
|
-
lines.push("\n }");
|
|
130
|
-
lines.push("\n}");
|
|
131
|
-
}
|
|
132
335
|
function replaceRelations(buckets, lines) {
|
|
133
336
|
for (const bucket of buckets) {
|
|
134
337
|
const target = `<${bucket._id}>`;
|
|
135
338
|
lines = lines.map(line => {
|
|
136
339
|
if (line.includes(target)) {
|
|
137
|
-
return line.replace(target, prepareInterfaceTitle(bucket.title)
|
|
340
|
+
return line.replace(target, prepareInterfaceTitle(bucket.title));
|
|
138
341
|
}
|
|
139
342
|
return line;
|
|
140
343
|
});
|
|
@@ -142,25 +345,25 @@ var Schema;
|
|
|
142
345
|
return lines;
|
|
143
346
|
}
|
|
144
347
|
})(Schema = exports.Schema || (exports.Schema = {}));
|
|
145
|
-
function buildProperties(props, reqs, bucketOrObject, lines) {
|
|
348
|
+
function buildProperties(props, languages, reqs, bucketOrObject, lines) {
|
|
146
349
|
if (bucketOrObject == "object") {
|
|
147
350
|
lines.push("{");
|
|
148
351
|
}
|
|
149
352
|
for (const [key, value] of Object.entries(props)) {
|
|
150
353
|
const reqFlag = !reqs.includes(key) ? "?" : "";
|
|
151
354
|
lines.push(`\n ${key + reqFlag}: `);
|
|
152
|
-
buildPropDef(value, lines);
|
|
355
|
+
buildPropDef(key, value, languages, lines);
|
|
153
356
|
lines.push(";");
|
|
154
357
|
}
|
|
155
358
|
if (bucketOrObject == "object") {
|
|
156
359
|
lines.push("}");
|
|
157
360
|
}
|
|
158
361
|
}
|
|
159
|
-
function buildArray(def, lines) {
|
|
160
|
-
buildPropDef(def, lines);
|
|
362
|
+
function buildArray(key, def, languages, lines) {
|
|
363
|
+
buildPropDef(key, def, languages, lines);
|
|
161
364
|
lines.push("[]");
|
|
162
365
|
}
|
|
163
|
-
function buildPropDef(prop, lines) {
|
|
366
|
+
function buildPropDef(key, prop, languages, lines) {
|
|
164
367
|
if (prop.enum) {
|
|
165
368
|
lines.push("(");
|
|
166
369
|
lines.push(prop.enum.map(v => (prop.type == "string" ? `'${v.replace(/'/g, "\\'")}'` : v)).join("|"));
|
|
@@ -173,7 +376,14 @@ function buildPropDef(prop, lines) {
|
|
|
173
376
|
case "color":
|
|
174
377
|
case "richtext":
|
|
175
378
|
case "storage":
|
|
176
|
-
|
|
379
|
+
let def = "string";
|
|
380
|
+
if (prop.options && prop.options.translate) {
|
|
381
|
+
let nonLocalizedType = {};
|
|
382
|
+
languages.forEach(l => (nonLocalizedType[l] = "string"));
|
|
383
|
+
nonLocalizedType = JSON.stringify(nonLocalizedType);
|
|
384
|
+
def = `Localize extends true ? string : ${nonLocalizedType}`;
|
|
385
|
+
}
|
|
386
|
+
lines.push(def);
|
|
177
387
|
break;
|
|
178
388
|
case "number":
|
|
179
389
|
lines.push("number");
|
|
@@ -185,14 +395,16 @@ function buildPropDef(prop, lines) {
|
|
|
185
395
|
lines.push("boolean");
|
|
186
396
|
break;
|
|
187
397
|
case "object":
|
|
188
|
-
buildProperties(prop.properties, prop.required || [], "object", lines);
|
|
398
|
+
buildProperties(prop.properties, prop.required || [], languages, "object", lines);
|
|
189
399
|
break;
|
|
190
400
|
case "array":
|
|
191
401
|
case "multiselect":
|
|
192
|
-
buildArray(prop.items, lines);
|
|
402
|
+
buildArray(key, prop.items, languages, lines);
|
|
193
403
|
break;
|
|
194
404
|
case "relation":
|
|
195
|
-
|
|
405
|
+
const suffix = prop.relationType == "onetomany" ? "[]" : "";
|
|
406
|
+
const definition = `Find<Relations,"${key}">[] extends never[] ? string${suffix} : (<${prop.bucketId}><FindRest<Relations,"${key}">[]>&id)${suffix}`;
|
|
407
|
+
lines.push(definition);
|
|
196
408
|
break;
|
|
197
409
|
case "location":
|
|
198
410
|
lines.push(`{ type: "Point", coordinates: [number,number]}`);
|
|
@@ -222,15 +434,6 @@ function getRelationFields(properties) {
|
|
|
222
434
|
}
|
|
223
435
|
return fields;
|
|
224
436
|
}
|
|
225
|
-
function getNormalizeRelationCode(fields) {
|
|
226
|
-
return `[${fields.map(f => `'${f}'`)}].forEach((field) => {
|
|
227
|
-
if (typeof document[field] == 'object') {
|
|
228
|
-
document[field] = Array.isArray(document[field])
|
|
229
|
-
? document[field].map((v) => v._id || v)
|
|
230
|
-
: document[field]._id;
|
|
231
|
-
}
|
|
232
|
-
});`;
|
|
233
|
-
}
|
|
234
437
|
function makeTitlesUnique(buckets, warnings) {
|
|
235
438
|
const titles = [];
|
|
236
439
|
for (const bucket of buckets) {
|
|
@@ -245,4 +448,34 @@ Number suffix will be added but should use unique titles for the best practice.`
|
|
|
245
448
|
}
|
|
246
449
|
return buckets;
|
|
247
450
|
}
|
|
451
|
+
function getResolveRelationEnums(id, buckets) {
|
|
452
|
+
const enums = [];
|
|
453
|
+
const maxDepth = 5;
|
|
454
|
+
const _getResolveRelationEnums = (_bucket, prefix) => {
|
|
455
|
+
const hasRelation = Object.values(_bucket.properties).some(v => v.type == "relation");
|
|
456
|
+
if (!hasRelation) {
|
|
457
|
+
if (prefix && !enums.includes(prefix)) {
|
|
458
|
+
enums.push(prefix);
|
|
459
|
+
}
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
462
|
+
Object.entries(_bucket.properties).forEach(([key, value]) => {
|
|
463
|
+
if (value.type == "relation") {
|
|
464
|
+
const paths = prefix ? `${prefix}.${key}` : key;
|
|
465
|
+
const isMaxLengthExceeded = paths.split(".").length > maxDepth;
|
|
466
|
+
if (isMaxLengthExceeded) {
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
if (!enums.includes(paths)) {
|
|
470
|
+
enums.push(paths);
|
|
471
|
+
}
|
|
472
|
+
const relatedBuckets = buckets.filter(b => b._id == value.bucketId);
|
|
473
|
+
relatedBuckets.forEach(b => _getResolveRelationEnums(b, paths));
|
|
474
|
+
}
|
|
475
|
+
});
|
|
476
|
+
};
|
|
477
|
+
const targetBucket = buckets.find(b => b._id == id);
|
|
478
|
+
_getResolveRelationEnums(targetBucket);
|
|
479
|
+
return enums;
|
|
480
|
+
}
|
|
248
481
|
//# sourceMappingURL=orm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"orm.js","sourceRoot":"","sources":["../../../../../../../../stacks/cli/src/commands/bucket/orm.ts"],"names":[],"mappings":";;;AACA,yBAAyB;AACzB,6BAA6B;AAE7B,2CAAsC;AACtC,2CAAmC;AACnC,qCAAuC;AAEvC,KAAK,UAAU,GAAG,CAAC,EAAC,OAAO,EAAmB;IAC5C,MAAM,IAAI,GAAI,OAAO,CAAC,IAAe,IAAI,EAAE,CAAC;IAC5C,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;IAEjD,MAAM,UAAU,GAAG,MAAM,kBAAW,CAAC,oBAAoB,EAAE,CAAC;IAE5D,MAAM,EAAC,GAAG,EAAC,GAAG,MAAM,iBAAO,CAAC,UAAU,EAAE,CAAC;IAEzC,MAAM,IAAA,cAAI,EAAC;QACT,IAAI,EAAE,oBAAoB;QAC1B,EAAE,EAAE,KAAK,EAAC,OAAO,EAAC,EAAE;YAClB,MAAM,OAAO,GAAG,MAAM,UAAU,CAAC,GAAG,CAAiB,SAAS,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"orm.js","sourceRoot":"","sources":["../../../../../../../../stacks/cli/src/commands/bucket/orm.ts"],"names":[],"mappings":";;;AACA,yBAAyB;AACzB,6BAA6B;AAE7B,2CAAsC;AACtC,2CAAmC;AACnC,qCAAuC;AAEvC,KAAK,UAAU,GAAG,CAAC,EAAC,OAAO,E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;aACjE;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;IAEF,MAAM,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC;IACpD,wBAAwB,CAAC,YAAY,CAAC,CAAC;IAEvC,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare class RepresentativeManager {
|
|
2
|
+
private cwd;
|
|
3
|
+
private serializer;
|
|
4
|
+
private parsers;
|
|
5
|
+
constructor(cwd: string);
|
|
6
|
+
private getModuleDir;
|
|
7
|
+
private serializeContent;
|
|
8
|
+
private parseContent;
|
|
9
|
+
write(module: string, id: string, fileName: string, content: any, extension: string): Promise<void>;
|
|
10
|
+
readResource(module: string, id: string, fileNames?: any[]): Promise<any>;
|
|
11
|
+
read(module: string, resNameValidator: (name: string) => boolean, fileNameFilter?: any[]): Promise<any[]>;
|
|
12
|
+
rm(module?: string, id?: string): Promise<void>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RepresentativeManager = void 0;
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const YAML = require("yaml");
|
|
7
|
+
const dotenv = require("dotenv");
|
|
8
|
+
class RepresentativeManager {
|
|
9
|
+
constructor(cwd) {
|
|
10
|
+
this.cwd = cwd;
|
|
11
|
+
this.serializer = new Map();
|
|
12
|
+
this.parsers = new Map();
|
|
13
|
+
this.serializer.set("json", val => JSON.stringify(val));
|
|
14
|
+
this.parsers.set("json", val => JSON.parse(val));
|
|
15
|
+
this.serializer.set("yaml", val => {
|
|
16
|
+
const document = new YAML.Document();
|
|
17
|
+
document.contents = val;
|
|
18
|
+
return document.toString();
|
|
19
|
+
});
|
|
20
|
+
this.parsers.set("yaml", val => YAML.parse(val));
|
|
21
|
+
this.serializer.set("js", val => val);
|
|
22
|
+
this.parsers.set("js", val => val);
|
|
23
|
+
this.serializer.set("ts", val => val);
|
|
24
|
+
this.parsers.set("ts", val => val);
|
|
25
|
+
this.serializer.set("env", content => {
|
|
26
|
+
let lines = [];
|
|
27
|
+
for (const [key, value] of Object.entries(content)) {
|
|
28
|
+
lines.push(`${key}=${value}`);
|
|
29
|
+
}
|
|
30
|
+
return lines.join("\n");
|
|
31
|
+
});
|
|
32
|
+
this.parsers.set("env", content => {
|
|
33
|
+
return dotenv.parse(content);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
getModuleDir(module) {
|
|
37
|
+
return path.join(this.cwd, module);
|
|
38
|
+
}
|
|
39
|
+
serializeContent(content, extension) {
|
|
40
|
+
const serializer = this.serializer.get(extension);
|
|
41
|
+
if (!serializer) {
|
|
42
|
+
throw Error(`Unknown extension type ${extension}`);
|
|
43
|
+
}
|
|
44
|
+
return serializer(content);
|
|
45
|
+
}
|
|
46
|
+
parseContent(content, extension) {
|
|
47
|
+
const parser = this.parsers.get(extension);
|
|
48
|
+
if (!parser) {
|
|
49
|
+
throw Error(`Unknown extension type ${extension}`);
|
|
50
|
+
}
|
|
51
|
+
return parser(content);
|
|
52
|
+
}
|
|
53
|
+
write(module, id, fileName, content, extension) {
|
|
54
|
+
const resourcesDirectory = path.join(this.cwd, module, id);
|
|
55
|
+
if (!fs.existsSync(resourcesDirectory)) {
|
|
56
|
+
fs.mkdirSync(resourcesDirectory, { recursive: true });
|
|
57
|
+
}
|
|
58
|
+
const fullPath = path.join(resourcesDirectory, `${fileName}.${extension}`);
|
|
59
|
+
content = this.serializeContent(content, extension);
|
|
60
|
+
return fs.promises.writeFile(fullPath, content);
|
|
61
|
+
}
|
|
62
|
+
readResource(module, id, fileNames = []) {
|
|
63
|
+
const moduleDir = this.getModuleDir(module);
|
|
64
|
+
const resourcesPath = path.join(moduleDir, id);
|
|
65
|
+
const contents = {};
|
|
66
|
+
if (!fs.existsSync(resourcesPath)) {
|
|
67
|
+
return Promise.resolve(contents);
|
|
68
|
+
}
|
|
69
|
+
let resources = fs.readdirSync(resourcesPath);
|
|
70
|
+
if (fileNames.length) {
|
|
71
|
+
resources = resources.filter(resource => fileNames.includes(resource));
|
|
72
|
+
}
|
|
73
|
+
const promises = [];
|
|
74
|
+
for (const resource of resources) {
|
|
75
|
+
const resourcePath = path.join(resourcesPath, resource);
|
|
76
|
+
const promise = fs.promises.readFile(resourcePath).then(content => {
|
|
77
|
+
const extension = resource.split(".").pop();
|
|
78
|
+
const key = resource.replace(`.${extension}`, "");
|
|
79
|
+
const value = this.parseContent(content.toString(), extension);
|
|
80
|
+
contents[key] = value;
|
|
81
|
+
});
|
|
82
|
+
promises.push(promise);
|
|
83
|
+
}
|
|
84
|
+
return Promise.all(promises).then(() => {
|
|
85
|
+
return { _id: id, contents };
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
read(module, resNameValidator, fileNameFilter = []) {
|
|
89
|
+
const moduleDir = this.getModuleDir(module);
|
|
90
|
+
let ids;
|
|
91
|
+
if (!fs.existsSync(moduleDir)) {
|
|
92
|
+
ids = [];
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
ids = fs.readdirSync(moduleDir);
|
|
96
|
+
}
|
|
97
|
+
const promises = [];
|
|
98
|
+
const results = [];
|
|
99
|
+
for (const id of ids) {
|
|
100
|
+
if (!resNameValidator(id)) {
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
const promise = this.readResource(module, id, fileNameFilter).then(resource => {
|
|
104
|
+
if (resource.contents && Object.keys(resource.contents).length) {
|
|
105
|
+
results.push(resource);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
promises.push(promise);
|
|
109
|
+
}
|
|
110
|
+
return Promise.all(promises).then(() => results);
|
|
111
|
+
}
|
|
112
|
+
rm(module, id) {
|
|
113
|
+
let dir = this.cwd;
|
|
114
|
+
if (module) {
|
|
115
|
+
dir = path.join(dir, module);
|
|
116
|
+
}
|
|
117
|
+
if (id) {
|
|
118
|
+
dir = path.join(dir, id);
|
|
119
|
+
}
|
|
120
|
+
return fs.promises.rmdir(dir, { recursive: true });
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
exports.RepresentativeManager = RepresentativeManager;
|
|
124
|
+
//# sourceMappingURL=representative.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"representative.js","sourceRoot":"","sources":["../../../../../../stacks/cli/src/representative.ts"],"names":[],"mappings":";;;AAAA,yBAAyB;AACzB,6BAA6B;AAC7B,6BAA6B;AAC7B,iCAAiC;AAEjC,MAAa,qBAAqB;IAIhC,YAAoB,GAAW;QAAX,QAAG,GAAH,GAAG,CAAQ;QAHvB,eAAU,GAAG,IAAI,GAAG,EAAgC,CAAC;QACrD,YAAO,GAAG,IAAI,GAAG,EAAgC,CAAC;QAIxD,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;QACxD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;QAGjD,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE;YAChC,MAAM,QAAQ,GAAG,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YACrC,QAAQ,CAAC,QAAQ,GAAG,GAAG,CAAC;YACxB,OAAO,QAAQ,CAAC,QAAQ,EAAE,CAAC;QAC7B,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;QAGjD,IAAI,CAAC,UAAU,CAAC,GAAG,C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EAAC,CAAC,CAAC;IACnD,CAAC;CACF;AA1JD,sDA0JC"}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const core_1 = require("@caporal/core");
|
|
4
|
-
const fs = require("fs");
|
|
5
|
-
const path = require("path");
|
|
6
|
-
const YAML = require("yaml");
|
|
7
|
-
const http_1 = require("../../http");
|
|
8
|
-
const status_1 = require("../../status");
|
|
9
|
-
async function apply({ options }) {
|
|
10
|
-
const filename = path.relative(process.cwd(), options.filename);
|
|
11
|
-
const rawDocument = fs.readFileSync(filename).toString();
|
|
12
|
-
const documents = YAML.parseAllDocuments(rawDocument);
|
|
13
|
-
const machineryClient = await http_1.httpService.createFromCurrentCtx();
|
|
14
|
-
for (const document of documents) {
|
|
15
|
-
const { apiVersion, kind, metadata, spec } = document.toJSON();
|
|
16
|
-
const resourceList = await machineryClient.get(`/apis/${apiVersion}`);
|
|
17
|
-
if ((0, status_1.isFailureStatus)(resourceList)) {
|
|
18
|
-
return console.error((0, status_1.formatFailureStatus)(resourceList));
|
|
19
|
-
}
|
|
20
|
-
let resource;
|
|
21
|
-
for (const _resource of resourceList.resources) {
|
|
22
|
-
if (_resource.kind == kind) {
|
|
23
|
-
resource = _resource;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
if (!resource) {
|
|
27
|
-
return console.error(`the server doesn't have a resource type "${kind}"`);
|
|
28
|
-
}
|
|
29
|
-
if (apiVersion == "function/v1" && kind == "Function") {
|
|
30
|
-
const basePath = path.dirname(filename);
|
|
31
|
-
spec.code = fs.readFileSync(path.resolve(basePath, spec.code)).toString();
|
|
32
|
-
}
|
|
33
|
-
let result = await machineryClient.post(`/apis/${apiVersion}/${resource.plural}`, {
|
|
34
|
-
metadata,
|
|
35
|
-
spec
|
|
36
|
-
});
|
|
37
|
-
let type = "created";
|
|
38
|
-
if ((0, status_1.isFailureStatus)(result) && result.reason == "AlreadyExists") {
|
|
39
|
-
const upstream = await machineryClient.get(`/apis/${apiVersion}/${resource.plural}/${metadata.name}`);
|
|
40
|
-
if (JSON.stringify(upstream.spec) == JSON.stringify(spec)) {
|
|
41
|
-
type = "up-to date";
|
|
42
|
-
result = {};
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
result = await machineryClient.put(`/apis/${apiVersion}/${resource.plural}/${metadata.name}`, { metadata, spec });
|
|
46
|
-
type = "replaced";
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
if ((0, status_1.isFailureStatus)(result)) {
|
|
50
|
-
if ((0, status_1.isValidationError)(result)) {
|
|
51
|
-
return console.error((0, status_1.formatValidationErrors)(result, document, rawDocument, filename));
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
return console.error((0, status_1.formatFailureStatus)(result));
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
console.info(`${resource.singular} "${metadata.name}" ${type}.`);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
function default_1({ createCommand }) {
|
|
61
|
-
return createCommand("Put objects to the API.")
|
|
62
|
-
.option("-f, --filename", "that contains the configuration to apply", {
|
|
63
|
-
required: true,
|
|
64
|
-
validator: core_1.CaporalValidator.STRING
|
|
65
|
-
})
|
|
66
|
-
.action(apply);
|
|
67
|
-
}
|
|
68
|
-
exports.default = default_1;
|
|
69
|
-
//# sourceMappingURL=apply.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"apply.js","sourceRoot":"","sources":["../../../../../../../../stacks/cli/src/commands/objects/apply.ts"],"names":[],"mappings":";;AAAA,wCAMuB;AACvB,yBAAyB;AACzB,6BAA6B;AAC7B,6BAA6B;AAC7B,qCAAuC;AACvC,yCAKsB;AAEtB,KAAK,UAAU,KAAK,CAAC,EAAC,OAAO,EAAmB;IAC9C,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,OAAO,CA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OAAO,aAAa,CAAC,yBAAyB,CAAC;SAC5C,MAAM,CAAC,gBAAgB,EAAE,0CAA0C,EAAE;QACpE,QAAQ,EAAE,IAAI;QACd,SAAS,EAAE,uBAAgB,CAAC,MAAM;KACnC,CAAC;SACD,MAAM,CAAE,KAA2B,CAAC,CAAC;AAC1C,CAAC;AAPD,4BAOC"}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const core_1 = require("@caporal/core");
|
|
4
|
-
const fs = require("fs");
|
|
5
|
-
const path = require("path");
|
|
6
|
-
const YAML = require("yaml");
|
|
7
|
-
const http_1 = require("../../http");
|
|
8
|
-
const status_1 = require("../../status");
|
|
9
|
-
async function _delete({ options }) {
|
|
10
|
-
const machineryClient = await http_1.httpService.createFromCurrentCtx();
|
|
11
|
-
const filename = path.normalize(options.filename);
|
|
12
|
-
const documents = YAML.parseAllDocuments(fs.readFileSync(filename).toString());
|
|
13
|
-
const ignoreNotFound = options.ignoreNotFound;
|
|
14
|
-
for (const document of documents) {
|
|
15
|
-
const { apiVersion, kind, metadata } = document.toJSON();
|
|
16
|
-
const resourceList = await machineryClient.get(`/apis/${apiVersion}`);
|
|
17
|
-
if ((0, status_1.isFailureStatus)(resourceList)) {
|
|
18
|
-
return console.error((0, status_1.formatFailureStatus)(resourceList));
|
|
19
|
-
}
|
|
20
|
-
let resource;
|
|
21
|
-
for (const _resource of resourceList.resources) {
|
|
22
|
-
if (_resource.kind == kind) {
|
|
23
|
-
resource = _resource;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
if (!resource) {
|
|
27
|
-
return console.error(`the server doesn't have a resource type "${kind}"`);
|
|
28
|
-
}
|
|
29
|
-
const result = await machineryClient.delete(`/apis/${apiVersion}/${resource.plural}/${metadata.name}`);
|
|
30
|
-
if ((0, status_1.isFailureStatus)(result) && result.reason == "NotFound") {
|
|
31
|
-
if (!ignoreNotFound) {
|
|
32
|
-
return console.error((0, status_1.formatFailureStatus)(result));
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
else if ((0, status_1.isFailureStatus)(result)) {
|
|
36
|
-
return console.error((0, status_1.formatFailureStatus)(result));
|
|
37
|
-
}
|
|
38
|
-
console.info(`${resource.singular} "${metadata.name}" deleted.`);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
function default_1({ createCommand }) {
|
|
42
|
-
return createCommand("Delete object(s) from the API.")
|
|
43
|
-
.option("-f, --filename", "that contains the configuration to apply", {
|
|
44
|
-
required: true,
|
|
45
|
-
validator: core_1.CaporalValidator.STRING
|
|
46
|
-
})
|
|
47
|
-
.option("--ignore-not-found", 'Treat "resource not found" as a successful delete. Defaults to "true" when --all is specified.', {
|
|
48
|
-
default: false
|
|
49
|
-
})
|
|
50
|
-
.action(_delete);
|
|
51
|
-
}
|
|
52
|
-
exports.default = default_1;
|
|
53
|
-
//# sourceMappingURL=delete.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"delete.js","sourceRoot":"","sources":["../../../../../../../../stacks/cli/src/commands/objects/delete.ts"],"names":[],"mappings":";;AAAA,wCAAmG;AACnG,yBAAyB;AACzB,6BAA6B;AAC7B,6BAA6B;AAC7B,qCAAuC;AACvC,yCAAkE;AAElE,KAAK,UAAU,OAAO,CAAC,EAAC,OAAO,EAAmB;IAChD,MAAM,eAAe,GAAG,MAAM,kBAAW,CAAC,oBAAoB,EAAE,CAAC;IAEjE,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,QAAkB,CAAC,CAAC;IAC5D,MAAM,SAAS,GAAG,IAAI,CAAC,iBAAiB,CAAC,EAAE,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;IAE/E,MAAM,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC;IAE9C,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE;QAChC,M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CAAC,gCAAgC,CAAC;SACnD,MAAM,CAAC,gBAAgB,EAAE,0CAA0C,EAAE;QACpE,QAAQ,EAAE,IAAI;QACd,SAAS,EAAE,uBAAgB,CAAC,MAAM;KACnC,CAAC;SACD,MAAM,CACL,oBAAoB,EACpB,gGAAgG,EAChG;QACE,OAAO,EAAE,KAAK;KACf,CACF;SACA,MAAM,CAAC,OAAO,CAAC,CAAC;AACrB,CAAC;AAdD,4BAcC"}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const jsonpath = require("jsonpath");
|
|
4
|
-
const duration = require("pretty-ms");
|
|
5
|
-
const http_1 = require("../../http");
|
|
6
|
-
const status_1 = require("../../status");
|
|
7
|
-
async function get({ args }) {
|
|
8
|
-
const machineryClient = await http_1.httpService.createFromCurrentCtx();
|
|
9
|
-
const groupList = await machineryClient.get("/apis");
|
|
10
|
-
const kind = args.kind;
|
|
11
|
-
for (const group of groupList.groups) {
|
|
12
|
-
const preferredVersion = group.versions[0];
|
|
13
|
-
const resourceList = await machineryClient.get(`/apis/${group.name}/${preferredVersion}`);
|
|
14
|
-
for (const resource of resourceList.resources) {
|
|
15
|
-
if (kind == "all" ||
|
|
16
|
-
resource.singular == kind ||
|
|
17
|
-
resource.plural == kind ||
|
|
18
|
-
resource.shortNames.indexOf(kind) != -1) {
|
|
19
|
-
const { rows, columns } = await printTable(machineryClient, `${group.name}/${preferredVersion}`, resource);
|
|
20
|
-
if (kind == "all") {
|
|
21
|
-
console.log(`${resource.plural.toLocaleUpperCase()}`);
|
|
22
|
-
}
|
|
23
|
-
console.table(rows, columns);
|
|
24
|
-
if (kind != "all") {
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
console.log("\n");
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
if (kind !== "all") {
|
|
34
|
-
console.error(`the server has no resource with kind ${kind}`);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
async function printTable(client, groupVersion, resource) {
|
|
38
|
-
const table = await client.get(`/apis/${groupVersion}/${resource.plural}`, {
|
|
39
|
-
headers: {
|
|
40
|
-
Accept: "application/json;as=Table;v=1"
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
if ((0, status_1.isFailureStatus)(table)) {
|
|
44
|
-
console.error((0, status_1.formatFailureStatus)(table));
|
|
45
|
-
return Promise.reject();
|
|
46
|
-
}
|
|
47
|
-
const rows = [];
|
|
48
|
-
const columns = [];
|
|
49
|
-
for (const column of table.columnDefinitions) {
|
|
50
|
-
column.name = column.name.toLocaleUpperCase();
|
|
51
|
-
columns.push(column.name);
|
|
52
|
-
}
|
|
53
|
-
for (const row of table.rows) {
|
|
54
|
-
const data = {};
|
|
55
|
-
for (const column of table.columnDefinitions) {
|
|
56
|
-
const rawCellData = jsonpath.query(row.cells, `$${column.jsonPath}`);
|
|
57
|
-
switch (column.type) {
|
|
58
|
-
case "string":
|
|
59
|
-
data[column.name] = rawCellData;
|
|
60
|
-
break;
|
|
61
|
-
case "date":
|
|
62
|
-
data[column.name] = duration(Date.now() - new Date(rawCellData).getTime(), {
|
|
63
|
-
compact: true
|
|
64
|
-
});
|
|
65
|
-
break;
|
|
66
|
-
default:
|
|
67
|
-
throw new Error(`unhandled type ${column.type}`);
|
|
68
|
-
}
|
|
69
|
-
switch (column.format) {
|
|
70
|
-
case "password":
|
|
71
|
-
data[column.name] = rawCellData.map(data => hideText(data ? String(data) : data));
|
|
72
|
-
break;
|
|
73
|
-
case undefined:
|
|
74
|
-
break;
|
|
75
|
-
default:
|
|
76
|
-
throw new Error(`unhandled format ${column.format}`);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
rows.push(data);
|
|
80
|
-
}
|
|
81
|
-
return { rows, columns };
|
|
82
|
-
}
|
|
83
|
-
function hideText(text) {
|
|
84
|
-
return new Array(Math.min(text.length, 10)).fill("*").join(" ");
|
|
85
|
-
}
|
|
86
|
-
function default_1({ createCommand }) {
|
|
87
|
-
return createCommand("Get an object from the API.")
|
|
88
|
-
.argument("<kind>", "Kind of the object")
|
|
89
|
-
.argument("[name]", "Name of the object")
|
|
90
|
-
.option("-n, --namespace", "Namespace of the object.")
|
|
91
|
-
.action(get);
|
|
92
|
-
}
|
|
93
|
-
exports.default = default_1;
|
|
94
|
-
//# sourceMappingURL=get.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"get.js","sourceRoot":"","sources":["../../../../../../../../stacks/cli/src/commands/objects/get.ts"],"names":[],"mappings":";;AACA,qCAAqC;AACrC,sCAAsC;AACtC,qCAAuC;AACvC,yCAAkE;AAElE,KAAK,UAAU,GAAG,CAAC,EAAC,IAAI,EAAmB;IACzC,MAAM,eAAe,GAAG,MAAM,kBAAW,CAAC,oBAAoB,EAAE,CAAC;IACjE,MAAM,SAAS,GAAG,MAAM,eAAe,CAAC,GAAG,CAAM,OAAO,CAAC,CAAC;IAC1D,MAAM,IAAI,GAAG,IAAI,CAAC,IAAc,CAAC;IAEjC,KAAK,MAAM,KAAK,IAAI,SAAS,CAAC,MAAM,EAAE;QAEpC,MAAM,gBAAgB,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;QAC3C,MAAM,YAAY,GAAG,MAAM,eAAe,CAAC,GAAG,CAAM,SAAS,KAAK,CAAC,IAAI,IAAI,gBAAgB,EAAE,CAAC,CAAC;QAE/F,KAAK,MAAM,QAAQ,IAAI,YAAY,CAAC,SAAS,EAAE;YAC7C,IACE,IAAI,IAAI,KAAK;gBACb,QAAQ,CAAC,QAAQ,IAAI,IAAI;gBACzB,QAAQ,CAAC,MAAM,IAAI,IAAI;gBACvB,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,EACvC;gBACA,MAAM,EAAC,IAAI,EAAE,OAAO,EAAC,GAAG,M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