@arcote.tech/arc 0.1.7 → 0.1.8
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/command/command.d.ts +1 -0
- package/dist/context/context.d.ts +1 -0
- package/dist/elements/abstract.d.ts +2 -0
- package/dist/elements/any.d.ts +1 -1
- package/dist/elements/array.d.ts +1 -4
- package/dist/elements/blob.d.ts +1 -5
- package/dist/elements/boolean.d.ts +1 -3
- package/dist/elements/date.d.ts +1 -4
- package/dist/elements/file.d.ts +1 -5
- package/dist/elements/number.d.ts +1 -3
- package/dist/elements/object.d.ts +4 -1
- package/dist/elements/record.d.ts +1 -5
- package/dist/elements/string-enum.d.ts +1 -4
- package/dist/elements/string.d.ts +1 -3
- package/dist/index.js +74 -12
- package/package.json +1 -1
|
@@ -37,6 +37,7 @@ export declare class ArcCommand<Name extends string, Params extends ArcObjectAny
|
|
|
37
37
|
name: Name;
|
|
38
38
|
description: string | undefined;
|
|
39
39
|
parameters: any;
|
|
40
|
+
strict: boolean;
|
|
40
41
|
};
|
|
41
42
|
}
|
|
42
43
|
export declare function command<Name extends string>(name: Name): ArcCommand<Name, null, any[], any[]>;
|
|
@@ -24,6 +24,7 @@ export type RemoveFalseAndResolvedPromiseFromArray<T extends any[]> = T extends
|
|
|
24
24
|
export declare class ArcContext<const E extends ArcContextElementAny[]> {
|
|
25
25
|
readonly elements: E;
|
|
26
26
|
constructor(elements: E);
|
|
27
|
+
get<Element extends E[number]>(name: Element["name"]): Element;
|
|
27
28
|
getSyncListeners(eventType: string, authContext: AuthContext): EventListener<any>[];
|
|
28
29
|
getAsyncListeners(eventType: string, authContext: AuthContext): EventListener<any>[];
|
|
29
30
|
pipe<const NewElements extends (ArcContextElementAny | false | Promise<{
|
|
@@ -11,10 +11,12 @@ export type Validators = Validator<any>[];
|
|
|
11
11
|
export type GetValidator<A extends ArcAbstract<any>> = A extends ArcAbstract<infer T> ? T : [];
|
|
12
12
|
export declare abstract class ArcAbstract<V extends Validators> implements ArcElement {
|
|
13
13
|
protected validations: V;
|
|
14
|
+
protected _description?: string;
|
|
14
15
|
constructor(validations?: V);
|
|
15
16
|
abstract serialize(value: any): any;
|
|
16
17
|
abstract deserialize(value: any): any;
|
|
17
18
|
abstract parse(value: any): any;
|
|
19
|
+
description(description: string): this;
|
|
18
20
|
default(defaultValueOrCallback: (() => ReturnType<this["deserialize"]>) | ReturnType<this["deserialize"]>): ArcDefault<this>;
|
|
19
21
|
optional(): ArcOptional<this>;
|
|
20
22
|
branded<Brand extends string | symbol>(name: Brand): ArcBranded<this, Brand>;
|
package/dist/elements/any.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export declare class ArcAny<T, V extends Validators = []> extends ArcAbstract<V>
|
|
|
4
4
|
parse(value: T): any;
|
|
5
5
|
serialize(value: T): any;
|
|
6
6
|
deserialize(value: any): T;
|
|
7
|
-
toJsonSchema():
|
|
7
|
+
toJsonSchema(): any;
|
|
8
8
|
}
|
|
9
9
|
export declare function any<T extends any>(): ArcAny<T, any>;
|
|
10
10
|
//# sourceMappingURL=any.d.ts.map
|
package/dist/elements/array.d.ts
CHANGED
|
@@ -54,10 +54,7 @@ export declare class ArcArray<E extends ArcElement, V extends Validators = [
|
|
|
54
54
|
name: Name;
|
|
55
55
|
validator: Fn;
|
|
56
56
|
}]>>>;
|
|
57
|
-
toJsonSchema():
|
|
58
|
-
type: string;
|
|
59
|
-
items: any;
|
|
60
|
-
};
|
|
57
|
+
toJsonSchema(): any;
|
|
61
58
|
}
|
|
62
59
|
export type ArcArrayAny = ArcArray<any>;
|
|
63
60
|
export declare function array<E extends ArcElement>(element: E): ArcArray<E, [{
|
package/dist/elements/blob.d.ts
CHANGED
|
@@ -67,11 +67,7 @@ export declare class ArcBlob<V extends Validators = [typeof blobValidator]> exte
|
|
|
67
67
|
* Override parse to validate blob objects
|
|
68
68
|
*/
|
|
69
69
|
parse(value: any): Blob;
|
|
70
|
-
toJsonSchema():
|
|
71
|
-
type: string;
|
|
72
|
-
contentEncoding: string;
|
|
73
|
-
contentMediaType: string;
|
|
74
|
-
};
|
|
70
|
+
toJsonSchema(): any;
|
|
75
71
|
}
|
|
76
72
|
export declare function blob(): ArcBlob<[{
|
|
77
73
|
readonly name: "blob";
|
|
@@ -11,9 +11,7 @@ export declare class ArcBoolean<V extends Validators> extends ArcPrimitive<V, bo
|
|
|
11
11
|
name: Name;
|
|
12
12
|
validator: Fn;
|
|
13
13
|
}]>>>;
|
|
14
|
-
toJsonSchema():
|
|
15
|
-
type: string;
|
|
16
|
-
};
|
|
14
|
+
toJsonSchema(): any;
|
|
17
15
|
}
|
|
18
16
|
export declare function boolean(): ArcBoolean<Validators>;
|
|
19
17
|
//# sourceMappingURL=boolean.d.ts.map
|
package/dist/elements/date.d.ts
CHANGED
|
@@ -30,10 +30,7 @@ export declare class ArcDate<V extends Validators = [typeof dateValidator]> exte
|
|
|
30
30
|
name: Name;
|
|
31
31
|
validator: Fn;
|
|
32
32
|
}]>>>;
|
|
33
|
-
toJsonSchema():
|
|
34
|
-
type: string;
|
|
35
|
-
format: string;
|
|
36
|
-
};
|
|
33
|
+
toJsonSchema(): any;
|
|
37
34
|
}
|
|
38
35
|
export declare function date(): ArcDate<[{
|
|
39
36
|
name: "type";
|
package/dist/elements/file.d.ts
CHANGED
|
@@ -127,11 +127,7 @@ export declare class ArcFile<V extends Validators = [typeof fileValidator]> exte
|
|
|
127
127
|
* Override parse to validate file objects
|
|
128
128
|
*/
|
|
129
129
|
parse(value: any): File;
|
|
130
|
-
toJsonSchema():
|
|
131
|
-
type: string;
|
|
132
|
-
contentEncoding: string;
|
|
133
|
-
contentMediaType: string;
|
|
134
|
-
};
|
|
130
|
+
toJsonSchema(): any;
|
|
135
131
|
}
|
|
136
132
|
export declare function file(): ArcFile<[{
|
|
137
133
|
readonly name: "file";
|
|
@@ -27,9 +27,7 @@ export declare class ArcNumber<V extends Validators = [typeof numberValidator]>
|
|
|
27
27
|
name: Name;
|
|
28
28
|
validator: Fn;
|
|
29
29
|
}]>>>;
|
|
30
|
-
toJsonSchema():
|
|
31
|
-
type: string;
|
|
32
|
-
};
|
|
30
|
+
toJsonSchema(): any;
|
|
33
31
|
}
|
|
34
32
|
export declare function number(): ArcNumber<[{
|
|
35
33
|
name: "type";
|
|
@@ -81,7 +81,10 @@ export declare function object<E extends ArcRawShape>(element: E): ArcObject<E,
|
|
|
81
81
|
name: "schema";
|
|
82
82
|
validator: (value: any) => false | { [key in keyof E]: ReturnType<E[key]["validate"]>; };
|
|
83
83
|
}]>;
|
|
84
|
-
export type ArcObjectMerge<A extends ArcObjectAny, B extends ArcObjectAny> = [
|
|
84
|
+
export type ArcObjectMerge<A extends ArcObjectAny, B extends ArcObjectAny> = [
|
|
85
|
+
A,
|
|
86
|
+
B
|
|
87
|
+
] extends [
|
|
85
88
|
ArcObject<infer AShape, infer AValidators>,
|
|
86
89
|
ArcObject<infer BShape, infer BValidators>
|
|
87
90
|
] ? ArcObject<AShape & BShape, [...AValidators, ...BValidators]> : never;
|
|
@@ -19,11 +19,7 @@ export declare class ArcRecord<Key extends ArcKey, E extends ArcElement, V exten
|
|
|
19
19
|
parse(value: Record<util.FirstArgument<Key["parse"]>, util.FirstArgument<E["parse"]>>): Record<ReturnType<Key["parse"]>, ReturnType<E["parse"]>>;
|
|
20
20
|
serialize(value: Record<ReturnType<Key["serialize"]>, ReturnType<E["serialize"]>>): Record<ReturnType<Key["serialize"]>, ReturnType<E["serialize"]>>;
|
|
21
21
|
deserialize(value: Record<ReturnType<Key["deserialize"]>, ReturnType<E["deserialize"]>>): Record<ReturnType<Key["deserialize"]>, ReturnType<E["deserialize"]>>;
|
|
22
|
-
toJsonSchema():
|
|
23
|
-
type: string;
|
|
24
|
-
propertyNames: any;
|
|
25
|
-
additionalProperties: any;
|
|
26
|
-
};
|
|
22
|
+
toJsonSchema(): any;
|
|
27
23
|
}
|
|
28
24
|
export type ArcRecordAny = ArcRecord<any, any>;
|
|
29
25
|
export declare function record<Key extends ArcKey, E extends ArcElement>(key: Key, element: E): ArcRecord<Key, E, [{
|
|
@@ -13,10 +13,7 @@ export declare class ArcStringEnum<const T extends string[], V extends Validator
|
|
|
13
13
|
parse<Value extends T[number]>(value: Value): Value;
|
|
14
14
|
serialize<Value extends T[number]>(value: Value): Value;
|
|
15
15
|
deserialize<Value extends T[number]>(value: Value): Value;
|
|
16
|
-
toJsonSchema():
|
|
17
|
-
readonly type: "string";
|
|
18
|
-
readonly enum: T;
|
|
19
|
-
};
|
|
16
|
+
toJsonSchema(): any;
|
|
20
17
|
getEnumerators(): T;
|
|
21
18
|
}
|
|
22
19
|
export type ArcStringEnumAny = ArcStringEnum<any>;
|
|
@@ -64,9 +64,7 @@ export declare class ArcString<V extends Validators = [typeof stringValidator]>
|
|
|
64
64
|
currentEmail: string;
|
|
65
65
|
} | undefined;
|
|
66
66
|
}]>;
|
|
67
|
-
toJsonSchema():
|
|
68
|
-
type: string;
|
|
69
|
-
};
|
|
67
|
+
toJsonSchema(): any;
|
|
70
68
|
url(): ArcString<[...V, {
|
|
71
69
|
name: "url";
|
|
72
70
|
validator: (value: string) => {
|
package/dist/index.js
CHANGED
|
@@ -116,9 +116,15 @@ class ArcDefault {
|
|
|
116
116
|
// elements/abstract.ts
|
|
117
117
|
class ArcAbstract {
|
|
118
118
|
validations;
|
|
119
|
+
_description;
|
|
119
120
|
constructor(validations = []) {
|
|
120
121
|
this.validations = validations;
|
|
121
122
|
}
|
|
123
|
+
description(description) {
|
|
124
|
+
const clone = this.clone();
|
|
125
|
+
clone._description = description;
|
|
126
|
+
return clone;
|
|
127
|
+
}
|
|
122
128
|
default(defaultValueOrCallback) {
|
|
123
129
|
return new ArcDefault(this, defaultValueOrCallback);
|
|
124
130
|
}
|
|
@@ -131,6 +137,7 @@ class ArcAbstract {
|
|
|
131
137
|
clone() {
|
|
132
138
|
const Constructor = this.constructor;
|
|
133
139
|
const newInstance = Object.assign(new Constructor, this);
|
|
140
|
+
newInstance._description = this._description;
|
|
134
141
|
return newInstance;
|
|
135
142
|
}
|
|
136
143
|
validate(value) {
|
|
@@ -153,7 +160,11 @@ class ArcAbstract {
|
|
|
153
160
|
return newInstance;
|
|
154
161
|
}
|
|
155
162
|
toJsonSchema() {
|
|
156
|
-
|
|
163
|
+
const schema = {};
|
|
164
|
+
if (this._description) {
|
|
165
|
+
schema.description = this._description;
|
|
166
|
+
}
|
|
167
|
+
return schema;
|
|
157
168
|
}
|
|
158
169
|
getValidations() {
|
|
159
170
|
return this.validations;
|
|
@@ -276,7 +287,11 @@ class ArcString extends ArcPrimitive {
|
|
|
276
287
|
});
|
|
277
288
|
}
|
|
278
289
|
toJsonSchema() {
|
|
279
|
-
|
|
290
|
+
const schema = { type: "string" };
|
|
291
|
+
if (this._description) {
|
|
292
|
+
schema.description = this._description;
|
|
293
|
+
}
|
|
294
|
+
return schema;
|
|
280
295
|
}
|
|
281
296
|
url() {
|
|
282
297
|
const regex = /^(https?):\/\/(?![-0-9])(?!www\.[0-9])(?:[a-zA-Z0-9-]+(?::[a-zA-Z0-9-]+)?@)?(?:localhost|\b(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b|[a-zA-Z0-9-]+\.)?[a-zA-Z0-9-]+\.(?:[a-zA-Z]{2,}|[a-zA-Z]{2}\.[a-zA-Z]{2})(?::\d{1,5})?(?!\/\/)(?:\/[a-zA-Z0-9-._~:?#\[\]@!$&'()*+,;=]*)*(?!\/{2})(?:;[a-zA-Z0-9-._~:?#\[\]@!$&'()*+,;=]*)*(\?(?!=)[a-zA-Z0-9&=;]*)?(\#[a-zA-Z0-9-]*)?$|^(https?):\/\/(localhost|\b(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b)(?::\d{1,5})?(?!\/\/)(?:\/[a-zA-Z0-9-._~:?#\[\]@!$&'()*+,;=]*)*(?!\/{2})(?:;[a-zA-Z0-9-._~:?#\[\]@!$&'()*+,;=]*)*(\?(?!=)[a-zA-Z0-9&=;]*)?(\#[a-zA-Z0-9-]*)?$/;
|
|
@@ -358,7 +373,11 @@ class ArcAny extends ArcAbstract {
|
|
|
358
373
|
return value;
|
|
359
374
|
}
|
|
360
375
|
toJsonSchema() {
|
|
361
|
-
|
|
376
|
+
const schema = {};
|
|
377
|
+
if (this._description) {
|
|
378
|
+
schema.description = this._description;
|
|
379
|
+
}
|
|
380
|
+
return schema;
|
|
362
381
|
}
|
|
363
382
|
}
|
|
364
383
|
function any() {
|
|
@@ -442,6 +461,10 @@ class ArcObject extends ArcAbstract {
|
|
|
442
461
|
}
|
|
443
462
|
serializePartial(value) {
|
|
444
463
|
return Object.entries(value).reduce((acc, [key, value2]) => {
|
|
464
|
+
if (!this.rawShape[key]) {
|
|
465
|
+
console.warn(`No element found for key: ${key}`);
|
|
466
|
+
return acc;
|
|
467
|
+
}
|
|
445
468
|
acc[key] = this.rawShape[key].serialize(value2);
|
|
446
469
|
return acc;
|
|
447
470
|
}, {});
|
|
@@ -486,6 +509,9 @@ class ArcObject extends ArcAbstract {
|
|
|
486
509
|
};
|
|
487
510
|
if (required.length)
|
|
488
511
|
schema.required = required;
|
|
512
|
+
if (this._description) {
|
|
513
|
+
schema.description = this._description;
|
|
514
|
+
}
|
|
489
515
|
return schema;
|
|
490
516
|
}
|
|
491
517
|
}
|
|
@@ -578,10 +604,14 @@ class ArcArray extends ArcAbstract {
|
|
|
578
604
|
return instance;
|
|
579
605
|
}
|
|
580
606
|
toJsonSchema() {
|
|
581
|
-
|
|
607
|
+
const schema = {
|
|
582
608
|
type: "array",
|
|
583
609
|
items: this.parent.toJsonSchema?.() ?? {}
|
|
584
610
|
};
|
|
611
|
+
if (this._description) {
|
|
612
|
+
schema.description = this._description;
|
|
613
|
+
}
|
|
614
|
+
return schema;
|
|
585
615
|
}
|
|
586
616
|
}
|
|
587
617
|
function array(element) {
|
|
@@ -675,11 +705,15 @@ class ArcBlob extends ArcPrimitive {
|
|
|
675
705
|
throw new Error("Expected Blob object");
|
|
676
706
|
}
|
|
677
707
|
toJsonSchema() {
|
|
678
|
-
|
|
708
|
+
const schema = {
|
|
679
709
|
type: "string",
|
|
680
710
|
contentEncoding: "base64",
|
|
681
711
|
contentMediaType: "application/octet-stream"
|
|
682
712
|
};
|
|
713
|
+
if (this._description) {
|
|
714
|
+
schema.description = this._description;
|
|
715
|
+
}
|
|
716
|
+
return schema;
|
|
683
717
|
}
|
|
684
718
|
}
|
|
685
719
|
function blob() {
|
|
@@ -700,7 +734,11 @@ class ArcBoolean extends ArcPrimitive {
|
|
|
700
734
|
return instance;
|
|
701
735
|
}
|
|
702
736
|
toJsonSchema() {
|
|
703
|
-
|
|
737
|
+
const schema = { type: "boolean" };
|
|
738
|
+
if (this._description) {
|
|
739
|
+
schema.description = this._description;
|
|
740
|
+
}
|
|
741
|
+
return schema;
|
|
704
742
|
}
|
|
705
743
|
}
|
|
706
744
|
function boolean() {
|
|
@@ -742,10 +780,14 @@ class ArcDate extends ArcAbstract {
|
|
|
742
780
|
return instance;
|
|
743
781
|
}
|
|
744
782
|
toJsonSchema() {
|
|
745
|
-
|
|
783
|
+
const schema = {
|
|
746
784
|
type: "string",
|
|
747
785
|
format: "date-time"
|
|
748
786
|
};
|
|
787
|
+
if (this._description) {
|
|
788
|
+
schema.description = this._description;
|
|
789
|
+
}
|
|
790
|
+
return schema;
|
|
749
791
|
}
|
|
750
792
|
}
|
|
751
793
|
function date() {
|
|
@@ -915,11 +957,15 @@ class ArcFile extends ArcPrimitive {
|
|
|
915
957
|
throw new Error("Expected File object");
|
|
916
958
|
}
|
|
917
959
|
toJsonSchema() {
|
|
918
|
-
|
|
960
|
+
const schema = {
|
|
919
961
|
type: "string",
|
|
920
962
|
contentEncoding: "base64",
|
|
921
963
|
contentMediaType: "application/octet-stream"
|
|
922
964
|
};
|
|
965
|
+
if (this._description) {
|
|
966
|
+
schema.description = this._description;
|
|
967
|
+
}
|
|
968
|
+
return schema;
|
|
923
969
|
}
|
|
924
970
|
}
|
|
925
971
|
function file() {
|
|
@@ -949,7 +995,11 @@ class ArcNumber extends ArcPrimitive {
|
|
|
949
995
|
return instance;
|
|
950
996
|
}
|
|
951
997
|
toJsonSchema() {
|
|
952
|
-
|
|
998
|
+
const schema = { type: "number" };
|
|
999
|
+
if (this._description) {
|
|
1000
|
+
schema.description = this._description;
|
|
1001
|
+
}
|
|
1002
|
+
return schema;
|
|
953
1003
|
}
|
|
954
1004
|
}
|
|
955
1005
|
function number() {
|
|
@@ -1058,11 +1108,15 @@ class ArcRecord extends ArcAbstract {
|
|
|
1058
1108
|
}, {});
|
|
1059
1109
|
}
|
|
1060
1110
|
toJsonSchema() {
|
|
1061
|
-
|
|
1111
|
+
const schema = {
|
|
1062
1112
|
type: "object",
|
|
1063
1113
|
propertyNames: this.key.toJsonSchema?.() ?? {},
|
|
1064
1114
|
additionalProperties: this.element.toJsonSchema?.() ?? {}
|
|
1065
1115
|
};
|
|
1116
|
+
if (this._description) {
|
|
1117
|
+
schema.description = this._description;
|
|
1118
|
+
}
|
|
1119
|
+
return schema;
|
|
1066
1120
|
}
|
|
1067
1121
|
}
|
|
1068
1122
|
function record(key, element) {
|
|
@@ -1094,10 +1148,14 @@ class ArcStringEnum extends ArcAbstract {
|
|
|
1094
1148
|
return value;
|
|
1095
1149
|
}
|
|
1096
1150
|
toJsonSchema() {
|
|
1097
|
-
|
|
1151
|
+
const schema = {
|
|
1098
1152
|
type: "string",
|
|
1099
1153
|
enum: this.values
|
|
1100
1154
|
};
|
|
1155
|
+
if (this._description) {
|
|
1156
|
+
schema.description = this._description;
|
|
1157
|
+
}
|
|
1158
|
+
return schema;
|
|
1101
1159
|
}
|
|
1102
1160
|
getEnumerators() {
|
|
1103
1161
|
return this.values;
|
|
@@ -1521,7 +1579,8 @@ class ArcCommand extends ArcContextElement {
|
|
|
1521
1579
|
type: "function",
|
|
1522
1580
|
name: this.name,
|
|
1523
1581
|
description: this._description ?? undefined,
|
|
1524
|
-
parameters: parametersSchema
|
|
1582
|
+
parameters: parametersSchema,
|
|
1583
|
+
strict: true
|
|
1525
1584
|
};
|
|
1526
1585
|
}
|
|
1527
1586
|
}
|
|
@@ -1534,6 +1593,9 @@ class ArcContext {
|
|
|
1534
1593
|
constructor(elements) {
|
|
1535
1594
|
this.elements = elements;
|
|
1536
1595
|
}
|
|
1596
|
+
get(name) {
|
|
1597
|
+
return this.elements.find((element2) => element2.name === name);
|
|
1598
|
+
}
|
|
1537
1599
|
getSyncListeners(eventType, authContext) {
|
|
1538
1600
|
const listeners = [];
|
|
1539
1601
|
this.elements.forEach((element2) => {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcote.tech/arc",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.8",
|
|
5
5
|
"private": false,
|
|
6
6
|
"author": "Przemysław Krasiński [arcote.tech]",
|
|
7
7
|
"description": "Arc is a framework designed to align code closely with business logic, streamlining development and enhancing productivity.",
|