@kokimoki/kit 1.0.3 → 1.3.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 +1 -0
- package/dist/kokimoki-kit-plugin.d.ts +11 -1
- package/dist/kokimoki-kit-plugin.js +27 -3
- package/dist/schema-builder.d.ts +95 -0
- package/dist/schema-builder.js +166 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +4 -0
- package/package.json +2 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
17
|
__exportStar(require("./kokimoki-kit-plugin"), exports);
|
18
18
|
__exportStar(require("./preprocess-style"), exports);
|
19
|
+
__exportStar(require("./schema-builder"), exports);
|
@@ -1,2 +1,12 @@
|
|
1
1
|
import type { Plugin } from "vite";
|
2
|
-
|
2
|
+
import type { Form } from "./schema-builder";
|
3
|
+
export interface KokimokiKitConfig {
|
4
|
+
conceptId: string;
|
5
|
+
form: Form<any, any>;
|
6
|
+
deployCodes: {
|
7
|
+
name: string;
|
8
|
+
description: string;
|
9
|
+
clientContext: any;
|
10
|
+
}[];
|
11
|
+
}
|
12
|
+
export declare function kokimokiKitPlugin(config: KokimokiKitConfig): Plugin;
|
@@ -7,7 +7,8 @@ exports.kokimokiKitPlugin = void 0;
|
|
7
7
|
const bson_objectid_1 = __importDefault(require("bson-objectid"));
|
8
8
|
const promises_1 = __importDefault(require("fs/promises"));
|
9
9
|
const preprocess_style_1 = require("./preprocess-style");
|
10
|
-
const
|
10
|
+
const version_1 = require("./version");
|
11
|
+
function kokimokiKitPlugin(config) {
|
11
12
|
return {
|
12
13
|
name: "kokimoki-kit",
|
13
14
|
async transform(code, id) {
|
@@ -36,7 +37,13 @@ const kokimokiKitPlugin = () => {
|
|
36
37
|
}
|
37
38
|
</script>
|
38
39
|
<script>
|
39
|
-
window.__toAssetsUrl = (path) =>
|
40
|
+
window.__toAssetsUrl = (path) => {
|
41
|
+
if (path.startsWith("km-proxy")) {
|
42
|
+
return "/%KM_BUILD_ID%/" + path;
|
43
|
+
}
|
44
|
+
|
45
|
+
return "%KM_ASSETS%/" + path;
|
46
|
+
};
|
40
47
|
</script>
|
41
48
|
`)
|
42
49
|
.replace(/<link.*?href="(.*?)".*?>/g, (match, p1) => {
|
@@ -80,12 +87,29 @@ const kokimokiKitPlugin = () => {
|
|
80
87
|
"test": true,
|
81
88
|
"host": "y-wss.kokimoki.com",
|
82
89
|
"appId": "${appId}",
|
90
|
+
"configObject": ${JSON.stringify(config.form.value)},
|
83
91
|
"base": "/",
|
84
92
|
"assets": "/"
|
85
93
|
}
|
86
94
|
</script>`);
|
87
95
|
return html;
|
88
96
|
},
|
97
|
+
// write kokimoki metadata to .kokimoki directory
|
98
|
+
async generateBundle(_, _bundle) {
|
99
|
+
// write config
|
100
|
+
await promises_1.default.writeFile(".kokimoki/config.json", JSON.stringify({
|
101
|
+
kokimokiKitVersion: version_1.KOKIMOKI_KIT_VERSION,
|
102
|
+
conceptId: config.conceptId,
|
103
|
+
deployCodes: config.deployCodes,
|
104
|
+
build: "dist",
|
105
|
+
}, null, 2));
|
106
|
+
// write schema
|
107
|
+
const schema = JSON.stringify(config.form.schema, null, 2);
|
108
|
+
await promises_1.default.writeFile(".kokimoki/schema.json", schema);
|
109
|
+
// write scheme defaults
|
110
|
+
const defaultValue = JSON.stringify(config.form.value, null, 2);
|
111
|
+
await promises_1.default.writeFile(".kokimoki/schema-defaults.json", defaultValue);
|
112
|
+
},
|
89
113
|
};
|
90
|
-
}
|
114
|
+
}
|
91
115
|
exports.kokimokiKitPlugin = kokimokiKitPlugin;
|
@@ -0,0 +1,95 @@
|
|
1
|
+
export interface FieldOptions {
|
2
|
+
label?: string;
|
3
|
+
}
|
4
|
+
export declare abstract class Field<T> {
|
5
|
+
readonly options: FieldOptions;
|
6
|
+
constructor(options: FieldOptions);
|
7
|
+
abstract get value(): T;
|
8
|
+
abstract get schema(): any;
|
9
|
+
}
|
10
|
+
export declare class BooleanField extends Field<boolean> {
|
11
|
+
value: boolean;
|
12
|
+
constructor(value: boolean, options?: FieldOptions);
|
13
|
+
get schema(): {
|
14
|
+
type: string;
|
15
|
+
default: boolean;
|
16
|
+
};
|
17
|
+
}
|
18
|
+
export declare class ConstField<T extends string> extends Field<string extends T ? never : T> {
|
19
|
+
value: string extends T ? never : T;
|
20
|
+
constructor(value: string extends T ? never : T, options?: FieldOptions);
|
21
|
+
get schema(): {
|
22
|
+
const: string extends T ? never : T;
|
23
|
+
};
|
24
|
+
}
|
25
|
+
export declare class ImageField extends Field<string> {
|
26
|
+
value: string;
|
27
|
+
constructor(value: string, options?: FieldOptions);
|
28
|
+
get schema(): {
|
29
|
+
type: string;
|
30
|
+
default: string;
|
31
|
+
};
|
32
|
+
}
|
33
|
+
export declare class TextField extends Field<string> {
|
34
|
+
value: string;
|
35
|
+
constructor(value: string, options?: FieldOptions);
|
36
|
+
get schema(): {
|
37
|
+
type: string;
|
38
|
+
default: string;
|
39
|
+
};
|
40
|
+
}
|
41
|
+
export declare class EnumField<T extends Record<string, string>> extends Field<keyof T> {
|
42
|
+
enumValues: T;
|
43
|
+
value: keyof T;
|
44
|
+
constructor(enumValues: T, value: keyof T, options?: FieldOptions);
|
45
|
+
get schema(): {
|
46
|
+
enum: string[];
|
47
|
+
};
|
48
|
+
}
|
49
|
+
export declare class IntegerField extends Field<number> {
|
50
|
+
value: number;
|
51
|
+
constructor(value: number, options?: FieldOptions);
|
52
|
+
get schema(): {
|
53
|
+
type: string;
|
54
|
+
default: number;
|
55
|
+
};
|
56
|
+
}
|
57
|
+
export declare class FloatField extends Field<number> {
|
58
|
+
value: number;
|
59
|
+
constructor(value: number, options?: FieldOptions);
|
60
|
+
get schema(): {
|
61
|
+
type: string;
|
62
|
+
default: number;
|
63
|
+
};
|
64
|
+
}
|
65
|
+
export declare class FormGroup<T extends Record<string, Field<any>>, O extends Record<string, Field<any>>> extends Field<{
|
66
|
+
[key in keyof T]: T[key]["value"];
|
67
|
+
} & Partial<{
|
68
|
+
[key in keyof O]: O[key]["value"];
|
69
|
+
}>> {
|
70
|
+
requiredFields: T;
|
71
|
+
optionalFields: O;
|
72
|
+
constructor(requiredFields: T, optionalFields?: O, options?: FieldOptions);
|
73
|
+
get value(): {
|
74
|
+
[key in keyof T]: T[key]["value"];
|
75
|
+
} & Partial<{
|
76
|
+
[key in keyof O]: O[key]["value"];
|
77
|
+
}>;
|
78
|
+
get schema(): {
|
79
|
+
type: string;
|
80
|
+
properties: any;
|
81
|
+
required: string[];
|
82
|
+
};
|
83
|
+
}
|
84
|
+
export declare class FormArray<T> extends Field<T[]> {
|
85
|
+
private factory;
|
86
|
+
value: Field<T>["value"][];
|
87
|
+
constructor(factory: () => Field<T>, value: Field<T>["value"][], options?: FieldOptions);
|
88
|
+
get schema(): {
|
89
|
+
type: string;
|
90
|
+
items: any;
|
91
|
+
default: T[];
|
92
|
+
};
|
93
|
+
}
|
94
|
+
export declare class Form<R extends Record<string, Field<any>>, O extends Record<string, Field<any>>> extends FormGroup<R, O> {
|
95
|
+
}
|
@@ -0,0 +1,166 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.Form = exports.FormArray = exports.FormGroup = exports.FloatField = exports.IntegerField = exports.EnumField = exports.TextField = exports.ImageField = exports.ConstField = exports.BooleanField = exports.Field = void 0;
|
4
|
+
const defaultFieldOptions = {};
|
5
|
+
class Field {
|
6
|
+
options;
|
7
|
+
constructor(options) {
|
8
|
+
this.options = options;
|
9
|
+
}
|
10
|
+
}
|
11
|
+
exports.Field = Field;
|
12
|
+
class BooleanField extends Field {
|
13
|
+
value;
|
14
|
+
constructor(value, options = defaultFieldOptions) {
|
15
|
+
super(options);
|
16
|
+
this.value = value;
|
17
|
+
}
|
18
|
+
get schema() {
|
19
|
+
return {
|
20
|
+
type: "boolean",
|
21
|
+
default: this.value,
|
22
|
+
};
|
23
|
+
}
|
24
|
+
}
|
25
|
+
exports.BooleanField = BooleanField;
|
26
|
+
class ConstField extends Field {
|
27
|
+
value;
|
28
|
+
constructor(value, options = defaultFieldOptions) {
|
29
|
+
super(options);
|
30
|
+
this.value = value;
|
31
|
+
}
|
32
|
+
get schema() {
|
33
|
+
return {
|
34
|
+
const: this.value,
|
35
|
+
};
|
36
|
+
}
|
37
|
+
}
|
38
|
+
exports.ConstField = ConstField;
|
39
|
+
class ImageField extends Field {
|
40
|
+
value;
|
41
|
+
constructor(value, options = defaultFieldOptions) {
|
42
|
+
super(options);
|
43
|
+
this.value = value;
|
44
|
+
}
|
45
|
+
get schema() {
|
46
|
+
return {
|
47
|
+
type: "string",
|
48
|
+
default: this.value,
|
49
|
+
};
|
50
|
+
}
|
51
|
+
}
|
52
|
+
exports.ImageField = ImageField;
|
53
|
+
class TextField extends Field {
|
54
|
+
value;
|
55
|
+
constructor(value, options = defaultFieldOptions) {
|
56
|
+
super(options);
|
57
|
+
this.value = value;
|
58
|
+
}
|
59
|
+
get schema() {
|
60
|
+
return {
|
61
|
+
type: "string",
|
62
|
+
default: this.value,
|
63
|
+
};
|
64
|
+
}
|
65
|
+
}
|
66
|
+
exports.TextField = TextField;
|
67
|
+
class EnumField extends Field {
|
68
|
+
enumValues;
|
69
|
+
value;
|
70
|
+
constructor(enumValues, value, options = defaultFieldOptions) {
|
71
|
+
super(options);
|
72
|
+
this.enumValues = enumValues;
|
73
|
+
this.value = value;
|
74
|
+
}
|
75
|
+
get schema() {
|
76
|
+
return {
|
77
|
+
enum: Object.keys(this.enumValues),
|
78
|
+
};
|
79
|
+
}
|
80
|
+
}
|
81
|
+
exports.EnumField = EnumField;
|
82
|
+
class IntegerField extends Field {
|
83
|
+
value;
|
84
|
+
constructor(value, options = defaultFieldOptions) {
|
85
|
+
super(options);
|
86
|
+
this.value = value;
|
87
|
+
}
|
88
|
+
get schema() {
|
89
|
+
return {
|
90
|
+
type: "integer",
|
91
|
+
default: this.value,
|
92
|
+
};
|
93
|
+
}
|
94
|
+
}
|
95
|
+
exports.IntegerField = IntegerField;
|
96
|
+
class FloatField extends Field {
|
97
|
+
value;
|
98
|
+
constructor(value, options = defaultFieldOptions) {
|
99
|
+
super(options);
|
100
|
+
this.value = value;
|
101
|
+
}
|
102
|
+
get schema() {
|
103
|
+
return {
|
104
|
+
type: "number",
|
105
|
+
default: this.value,
|
106
|
+
};
|
107
|
+
}
|
108
|
+
}
|
109
|
+
exports.FloatField = FloatField;
|
110
|
+
class FormGroup extends Field {
|
111
|
+
requiredFields;
|
112
|
+
optionalFields;
|
113
|
+
constructor(requiredFields, optionalFields = {}, options = defaultFieldOptions) {
|
114
|
+
super(options);
|
115
|
+
this.requiredFields = requiredFields;
|
116
|
+
this.optionalFields = optionalFields;
|
117
|
+
}
|
118
|
+
get value() {
|
119
|
+
const value = Object.entries(this.requiredFields).reduce((acc, [key, field]) => {
|
120
|
+
acc[key] = field.value;
|
121
|
+
return acc;
|
122
|
+
}, {});
|
123
|
+
Object.entries(this.optionalFields).forEach(([key, field]) => {
|
124
|
+
if (field.value !== undefined) {
|
125
|
+
value[key] = field.value;
|
126
|
+
}
|
127
|
+
});
|
128
|
+
return value;
|
129
|
+
}
|
130
|
+
get schema() {
|
131
|
+
const properties = {};
|
132
|
+
Object.entries(this.requiredFields).forEach(([key, field]) => {
|
133
|
+
properties[key] = field.schema;
|
134
|
+
});
|
135
|
+
Object.entries(this.optionalFields).forEach(([key, field]) => {
|
136
|
+
properties[key] = field.schema;
|
137
|
+
});
|
138
|
+
return {
|
139
|
+
type: "object",
|
140
|
+
properties,
|
141
|
+
required: Object.keys(this.requiredFields),
|
142
|
+
};
|
143
|
+
}
|
144
|
+
}
|
145
|
+
exports.FormGroup = FormGroup;
|
146
|
+
class FormArray extends Field {
|
147
|
+
factory;
|
148
|
+
value;
|
149
|
+
constructor(factory, value, options = defaultFieldOptions) {
|
150
|
+
super(options);
|
151
|
+
this.factory = factory;
|
152
|
+
this.value = value;
|
153
|
+
}
|
154
|
+
get schema() {
|
155
|
+
const field = this.factory();
|
156
|
+
return {
|
157
|
+
type: "array",
|
158
|
+
items: field.schema,
|
159
|
+
default: this.value,
|
160
|
+
};
|
161
|
+
}
|
162
|
+
}
|
163
|
+
exports.FormArray = FormArray;
|
164
|
+
class Form extends FormGroup {
|
165
|
+
}
|
166
|
+
exports.Form = Form;
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare const KOKIMOKI_KIT_VERSION = "1.3.0";
|
package/dist/version.js
ADDED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@kokimoki/kit",
|
3
|
-
"version": "1.0
|
3
|
+
"version": "1.3.0",
|
4
4
|
"description": "",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"types": "dist/index.d.ts",
|
@@ -9,6 +9,7 @@
|
|
9
9
|
],
|
10
10
|
"scripts": {
|
11
11
|
"test": "echo \"Error: no test specified\" && exit 1",
|
12
|
+
"prebuild": "node -p \"'export const KOKIMOKI_KIT_VERSION = ' + JSON.stringify(require('./package.json').version) + ';'\" > src/version.ts",
|
12
13
|
"build": "tsc"
|
13
14
|
},
|
14
15
|
"author": "Loquiz OÜ",
|