@go-mondo/identity-sdk 0.0.2-beta.21 → 0.0.2-beta.23
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/.release-please-manifest.json +1 -1
- package/.tsbuildinfo/cjs.json +1 -1
- package/.tsbuildinfo/esm.json +1 -1
- package/CHANGELOG.md +14 -0
- package/dist/cjs/app/authorization/schema.d.ts +6 -6
- package/dist/cjs/app/authorization/schema.d.ts.map +1 -1
- package/dist/cjs/app/authorization/schema.js +8 -26
- package/dist/cjs/authentication/sessions/schema.d.ts +1 -3
- package/dist/cjs/authentication/sessions/schema.d.ts.map +1 -1
- package/dist/cjs/authentication/sessions/schema.js +13 -6
- package/dist/cjs/authorization/permissions/schema.d.ts +1 -1
- package/dist/cjs/authorization/permissions/schema.d.ts.map +1 -1
- package/dist/cjs/authorization/permissions/schema.js +1 -1
- package/dist/cjs/authorization/roles/schema.d.ts +1 -1
- package/dist/cjs/authorization/roles/schema.d.ts.map +1 -1
- package/dist/cjs/authorization/roles/schema.js +1 -1
- package/dist/cjs/common/schema/sets.d.ts +4 -2
- package/dist/cjs/common/schema/sets.d.ts.map +1 -1
- package/dist/cjs/common/schema/sets.js +22 -9
- package/dist/cjs/oauth/authorize/schema/grants/authorization-code.d.ts +1 -0
- package/dist/cjs/oauth/authorize/schema/grants/authorization-code.d.ts.map +1 -1
- package/dist/cjs/oauth/authorize/schema/grants/authorization-code.js +3 -3
- package/dist/esm/app/authorization/schema.d.ts +6 -6
- package/dist/esm/app/authorization/schema.d.ts.map +1 -1
- package/dist/esm/app/authorization/schema.js +8 -26
- package/dist/esm/authentication/sessions/schema.d.ts +1 -3
- package/dist/esm/authentication/sessions/schema.d.ts.map +1 -1
- package/dist/esm/authentication/sessions/schema.js +12 -5
- package/dist/esm/authorization/permissions/schema.d.ts +1 -1
- package/dist/esm/authorization/permissions/schema.d.ts.map +1 -1
- package/dist/esm/authorization/permissions/schema.js +2 -2
- package/dist/esm/authorization/roles/schema.d.ts +1 -1
- package/dist/esm/authorization/roles/schema.d.ts.map +1 -1
- package/dist/esm/authorization/roles/schema.js +2 -2
- package/dist/esm/common/schema/sets.d.ts +4 -2
- package/dist/esm/common/schema/sets.d.ts.map +1 -1
- package/dist/esm/common/schema/sets.js +21 -8
- package/dist/esm/oauth/authorize/schema/grants/authorization-code.d.ts +1 -0
- package/dist/esm/oauth/authorize/schema/grants/authorization-code.d.ts.map +1 -1
- package/dist/esm/oauth/authorize/schema/grants/authorization-code.js +1 -1
- package/package.json +1 -1
- package/dist/cjs/common/schema/sets.test.d.ts +0 -2
- package/dist/cjs/common/schema/sets.test.d.ts.map +0 -1
- package/dist/cjs/common/schema/sets.test.js +0 -93
- package/dist/esm/common/schema/sets.test.d.ts +0 -2
- package/dist/esm/common/schema/sets.test.d.ts.map +0 -1
- package/dist/esm/common/schema/sets.test.js +0 -91
- package/src/common/schema/sets.test.ts.bak +0 -108
|
@@ -77,7 +77,7 @@ export declare const InsertRolePayloadSchema: z.ZodObject<{
|
|
|
77
77
|
apps: z.ZodOptional<z.ZodUnion<[z.ZodUndefined, z.ZodArray<z.ZodString>]>>;
|
|
78
78
|
permissions: z.ZodOptional<z.ZodUnion<readonly [z.ZodUndefined, z.ZodArray<z.ZodString>]>>;
|
|
79
79
|
users: z.ZodOptional<z.ZodUnion<readonly [z.ZodUndefined, z.ZodArray<z.ZodString>]>>;
|
|
80
|
-
id: z.
|
|
80
|
+
id: z.ZodOptional<z.ZodString>;
|
|
81
81
|
name: z.ZodString;
|
|
82
82
|
status: z.ZodDefault<z.ZodEnum<{
|
|
83
83
|
enabled: "enabled";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../src/authorization/roles/schema.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../src/authorization/roles/schema.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAWxB,eAAO,MAAM,UAAU;;;CAGb,CAAC;AAEX,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,OAAO,UAAU,CAAC,CAAC;AAEzE,eAAO,MAAM,oBAAoB;;iBAE/B,CAAC;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAInE,eAAO,MAAM,sBAAsB;;;;iBAIjC,CAAC;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAYvE,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;iBAOrB,CAAC;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,UAAU,CAAC,CAAC;AACxD,MAAM,MAAM,IAAI,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,UAAU,CAAC,CAAC;AAE/C,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;iBAO5B,CAAC;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAE7D;;GAEG;AACH,eAAO,MAAM,uBAAuB;;;;;;;;;;;;iBAOlC,CAAC;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AACtE,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAEzE;;GAEG;AACH,eAAO,MAAM,uBAAuB;;;;;;;;iBAKlC,CAAC;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AACtE,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAEzE;;GAEG;AACH,eAAO,MAAM,8BAA8B;;;;;;;;iBAKzC,CAAC;AACH,MAAM,MAAM,wBAAwB,GAAG,CAAC,CAAC,MAAM,CAC7C,OAAO,8BAA8B,CACtC,CAAC"}
|
|
@@ -4,7 +4,7 @@ import { AppIdAssociationsSchema } from '../../app/schema.js';
|
|
|
4
4
|
import { AggregateSchema } from '../../common/schema/aggregate.js';
|
|
5
5
|
import { MetadataMapPropertySchema, MetadataPayloadPropertySchema, UpsertMetadataPropertyPayloadSchema, } from '../../common/schema/metadata.js';
|
|
6
6
|
import { UserIdAssociationsSchema } from '../../customer/schema.js';
|
|
7
|
-
import { PermissionIdAssociationsSchema, RoleIdSchema
|
|
7
|
+
import { PermissionIdAssociationsSchema, RoleIdSchema } from '../schema.js';
|
|
8
8
|
export const RoleStatus = {
|
|
9
9
|
ENABLED: 'enabled',
|
|
10
10
|
DISABLED: 'disabled',
|
|
@@ -47,7 +47,7 @@ export const RolePayloadSchema = z.object({
|
|
|
47
47
|
* Insert
|
|
48
48
|
*/
|
|
49
49
|
export const InsertRolePayloadSchema = z.object({
|
|
50
|
-
id: RoleIdSchema.
|
|
50
|
+
id: RoleIdSchema.optional(),
|
|
51
51
|
name: z.string(),
|
|
52
52
|
status: StatusSchema.default(RoleStatus.ENABLED),
|
|
53
53
|
description: z.string().optional(),
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const
|
|
2
|
+
export declare const UniqueStringArraySchema: z.ZodPipe<z.ZodUnion<readonly [z.ZodUndefined, z.ZodPipe<z.ZodArray<z.ZodString>, z.ZodTransform<string[], string[]>>, z.ZodSet<z.ZodString>]>, z.ZodTransform<string[] | undefined, Set<string> | string[] | undefined>>;
|
|
3
|
+
export declare const UniqueStringSetSchema: z.ZodPipe<z.ZodUnion<readonly [z.ZodUndefined, z.ZodPipe<z.ZodArray<z.ZodString>, z.ZodTransform<string[], string[]>>, z.ZodSet<z.ZodString>]>, z.ZodTransform<Set<string> | undefined, Set<string> | string[] | undefined>>;
|
|
4
|
+
export declare const UniqueUrlArraySchema: z.ZodPipe<z.ZodUnion<readonly [z.ZodUndefined, z.ZodPipe<z.ZodArray<z.ZodPipe<z.ZodURL, z.ZodTransform<URL, string>>>, z.ZodTransform<URL[], URL[]>>, z.ZodCustom<Set<URL>, Set<URL>>]>, z.ZodTransform<URL[] | undefined, Set<URL> | URL[] | undefined>>;
|
|
5
|
+
export declare const UniqueUrlSetSchema: z.ZodPipe<z.ZodUnion<readonly [z.ZodUndefined, z.ZodPipe<z.ZodArray<z.ZodPipe<z.ZodURL, z.ZodTransform<URL, string>>>, z.ZodTransform<URL[], URL[]>>, z.ZodCustom<Set<URL>, Set<URL>>]>, z.ZodTransform<Set<URL> | undefined, Set<URL> | URL[] | undefined>>;
|
|
4
6
|
//# sourceMappingURL=sets.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sets.d.ts","sourceRoot":"","sources":["../../../../src/common/schema/sets.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"sets.d.ts","sourceRoot":"","sources":["../../../../src/common/schema/sets.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAQxB,eAAO,MAAM,uBAAuB,2NAEwC,CAAC;AAE7E,eAAO,MAAM,qBAAqB,8NAEoC,CAAC;AAOvE,eAAO,MAAM,oBAAoB,2PAE2C,CAAC;AAE7E,eAAO,MAAM,kBAAkB,8PAEuC,CAAC"}
|
|
@@ -1,9 +1,22 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
])
|
|
9
|
-
|
|
2
|
+
const StringSetTypeSchema = z.set(z.string());
|
|
3
|
+
// const UrlStringSchema = type('string.url[]').pipe((v) => v?.filter((i) => !!i));
|
|
4
|
+
const StringArrayTypeSchema = z
|
|
5
|
+
.array(z.string())
|
|
6
|
+
.pipe(z.transform((v) => v?.filter((i) => !!i)));
|
|
7
|
+
export const UniqueStringArraySchema = z
|
|
8
|
+
.union([z.undefined(), StringArrayTypeSchema, StringSetTypeSchema])
|
|
9
|
+
.pipe(z.transform((v) => (v instanceof Set ? Array.from(v.values()) : v)));
|
|
10
|
+
export const UniqueStringSetSchema = z
|
|
11
|
+
.union([z.undefined(), StringArrayTypeSchema, StringSetTypeSchema])
|
|
12
|
+
.pipe(z.transform((v) => (!v || v instanceof Set ? v : new Set(v))));
|
|
13
|
+
const UrlSetTypeSchema = z.instanceof((Set));
|
|
14
|
+
const UrlArrayTypeScheama = z
|
|
15
|
+
.array(z.url().pipe(z.transform((url) => new URL(url))))
|
|
16
|
+
.pipe(z.transform((v) => v?.filter((i) => !!i)));
|
|
17
|
+
export const UniqueUrlArraySchema = z
|
|
18
|
+
.union([z.undefined(), UrlArrayTypeScheama, UrlSetTypeSchema])
|
|
19
|
+
.pipe(z.transform((v) => (v instanceof Set ? Array.from(v.values()) : v)));
|
|
20
|
+
export const UniqueUrlSetSchema = z
|
|
21
|
+
.union([z.undefined(), UrlArrayTypeScheama, UrlSetTypeSchema])
|
|
22
|
+
.pipe(z.transform((v) => (!v || v instanceof Set ? v : new Set(v))));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authorization-code.d.ts","sourceRoot":"","sources":["../../../../../../src/oauth/authorize/schema/grants/authorization-code.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"authorization-code.d.ts","sourceRoot":"","sources":["../../../../../../src/oauth/authorize/schema/grants/authorization-code.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAiBxB,eAAO,MAAM,mBAAmB,aAKmC,CAAC;AAmCpE,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAyBhC,CAAC;AACL,MAAM,MAAM,wBAAwB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,uBAAuB,CAAC,CAAC"}
|
|
@@ -6,7 +6,7 @@ import { AuthorizationDisplaySchema, AuthorizationPromptSchema, CodeChallengeMet
|
|
|
6
6
|
* @see https://openid.net/specs/openid-connect-core-1_0.html#rfc.section.3.1.2.1
|
|
7
7
|
*/
|
|
8
8
|
const ResponseTypeSchema = z.enum([ResponseType.CODE]);
|
|
9
|
-
const CodeChallengeSchema = z
|
|
9
|
+
export const CodeChallengeSchema = z
|
|
10
10
|
.string()
|
|
11
11
|
.min(43, 'Code challenge must be at least 43 characters long.')
|
|
12
12
|
.max(128, 'Code challenge must be at most 128 characters long.')
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sets.test.d.ts","sourceRoot":"","sources":["../../../../src/common/schema/sets.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const vitest_1 = require("vitest");
|
|
4
|
-
const sets_js_1 = require("./sets.js");
|
|
5
|
-
(0, vitest_1.describe)('Common Schema - Sets', () => {
|
|
6
|
-
(0, vitest_1.describe)('UniqueStringSetPayloadSchema', () => {
|
|
7
|
-
(0, vitest_1.test)('should accept Set of strings', () => {
|
|
8
|
-
const stringSet = new Set(['a', 'b', 'c']);
|
|
9
|
-
const result = sets_js_1.UniqueStringSetPayloadSchema.safeParse(stringSet);
|
|
10
|
-
// Parse succeeds for valid data
|
|
11
|
-
(0, vitest_1.expect)(result.data).toBeInstanceOf(Set);
|
|
12
|
-
(0, vitest_1.expect)(Array.from(result.data).sort()).toEqual([
|
|
13
|
-
'a',
|
|
14
|
-
'b',
|
|
15
|
-
'c',
|
|
16
|
-
]);
|
|
17
|
-
});
|
|
18
|
-
(0, vitest_1.test)('should accept array of strings and convert to Set', () => {
|
|
19
|
-
const stringArray = ['x', 'y', 'z'];
|
|
20
|
-
const result = sets_js_1.UniqueStringSetPayloadSchema.safeParse(stringArray);
|
|
21
|
-
// Parse succeeds for valid data
|
|
22
|
-
(0, vitest_1.expect)(result.data).toBeInstanceOf(Set);
|
|
23
|
-
(0, vitest_1.expect)(Array.from(result.data).sort()).toEqual([
|
|
24
|
-
'x',
|
|
25
|
-
'y',
|
|
26
|
-
'z',
|
|
27
|
-
]);
|
|
28
|
-
});
|
|
29
|
-
(0, vitest_1.test)('should handle duplicate strings in array', () => {
|
|
30
|
-
const stringArray = ['a', 'b', 'a', 'c', 'b'];
|
|
31
|
-
const result = sets_js_1.UniqueStringSetPayloadSchema.safeParse(stringArray);
|
|
32
|
-
// Parse succeeds for valid data
|
|
33
|
-
(0, vitest_1.expect)(result.data).toBeInstanceOf(Set);
|
|
34
|
-
(0, vitest_1.expect)(Array.from(result.data).sort()).toEqual([
|
|
35
|
-
'a',
|
|
36
|
-
'b',
|
|
37
|
-
'c',
|
|
38
|
-
]);
|
|
39
|
-
});
|
|
40
|
-
(0, vitest_1.test)('should accept empty array', () => {
|
|
41
|
-
const result = sets_js_1.UniqueStringSetPayloadSchema.safeParse([]);
|
|
42
|
-
// Parse succeeds for valid data
|
|
43
|
-
(0, vitest_1.expect)(result.data).toBeInstanceOf(Set);
|
|
44
|
-
(0, vitest_1.expect)(result.data.size).toBe(0);
|
|
45
|
-
});
|
|
46
|
-
(0, vitest_1.test)('should accept empty Set', () => {
|
|
47
|
-
const emptySet = new Set();
|
|
48
|
-
const result = sets_js_1.UniqueStringSetPayloadSchema.safeParse(emptySet);
|
|
49
|
-
// Parse succeeds for valid data
|
|
50
|
-
(0, vitest_1.expect)(result.data).toBeInstanceOf(Set);
|
|
51
|
-
(0, vitest_1.expect)(result.data.size).toBe(0);
|
|
52
|
-
});
|
|
53
|
-
(0, vitest_1.test)('should reject non-string array elements', () => {
|
|
54
|
-
const result = sets_js_1.UniqueStringSetPayloadSchema.safeParse(['a', 123, 'b']);
|
|
55
|
-
(0, vitest_1.expect)(result.success).toBe(false);
|
|
56
|
-
});
|
|
57
|
-
(0, vitest_1.test)('should reject non-array, non-Set values', () => {
|
|
58
|
-
(0, vitest_1.expect)(sets_js_1.UniqueStringSetPayloadSchema.safeParse('string').success).toBe(false);
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
(0, vitest_1.describe)('UniqueStringPayloadSchema', () => {
|
|
62
|
-
(0, vitest_1.test)('should convert Set to array', () => {
|
|
63
|
-
const stringSet = new Set(['x', 'y', 'z']);
|
|
64
|
-
const result = sets_js_1.UniqueStringPayloadSchema.safeParse(stringSet);
|
|
65
|
-
// Parse succeeds for valid data
|
|
66
|
-
(0, vitest_1.expect)(Array.isArray(result.data)).toBe(true);
|
|
67
|
-
(0, vitest_1.expect)(result.data.sort()).toEqual(['x', 'y', 'z']);
|
|
68
|
-
});
|
|
69
|
-
(0, vitest_1.test)('should convert array to unique array', () => {
|
|
70
|
-
const stringArray = ['a', 'b', 'a', 'c', 'b'];
|
|
71
|
-
const result = sets_js_1.UniqueStringPayloadSchema.safeParse(stringArray);
|
|
72
|
-
// Parse succeeds for valid data
|
|
73
|
-
(0, vitest_1.expect)(Array.isArray(result.data)).toBe(true);
|
|
74
|
-
(0, vitest_1.expect)(result.data.sort()).toEqual(['a', 'b', 'c']);
|
|
75
|
-
});
|
|
76
|
-
(0, vitest_1.test)('should handle empty inputs', () => {
|
|
77
|
-
const emptySet = new Set();
|
|
78
|
-
const emptyArray = [];
|
|
79
|
-
const setResult = sets_js_1.UniqueStringPayloadSchema.safeParse(emptySet);
|
|
80
|
-
const arrayResult = sets_js_1.UniqueStringPayloadSchema.safeParse(emptyArray);
|
|
81
|
-
// Parse succeeds for valid data
|
|
82
|
-
// Parse succeeds for valid data
|
|
83
|
-
(0, vitest_1.expect)(setResult.data.length).toBe(0);
|
|
84
|
-
(0, vitest_1.expect)(arrayResult.data.length).toBe(0);
|
|
85
|
-
});
|
|
86
|
-
(0, vitest_1.test)('should maintain order from original Set', () => {
|
|
87
|
-
const orderedSet = new Set(['first', 'second', 'third']);
|
|
88
|
-
const result = sets_js_1.UniqueStringPayloadSchema.safeParse(orderedSet);
|
|
89
|
-
// Parse succeeds for valid data
|
|
90
|
-
(0, vitest_1.expect)(result.data).toEqual(['first', 'second', 'third']);
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sets.test.d.ts","sourceRoot":"","sources":["../../../../src/common/schema/sets.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'vitest';
|
|
2
|
-
import { UniqueStringPayloadSchema, UniqueStringSetPayloadSchema, } from './sets.js';
|
|
3
|
-
describe('Common Schema - Sets', () => {
|
|
4
|
-
describe('UniqueStringSetPayloadSchema', () => {
|
|
5
|
-
test('should accept Set of strings', () => {
|
|
6
|
-
const stringSet = new Set(['a', 'b', 'c']);
|
|
7
|
-
const result = UniqueStringSetPayloadSchema.safeParse(stringSet);
|
|
8
|
-
// Parse succeeds for valid data
|
|
9
|
-
expect(result.data).toBeInstanceOf(Set);
|
|
10
|
-
expect(Array.from(result.data).sort()).toEqual([
|
|
11
|
-
'a',
|
|
12
|
-
'b',
|
|
13
|
-
'c',
|
|
14
|
-
]);
|
|
15
|
-
});
|
|
16
|
-
test('should accept array of strings and convert to Set', () => {
|
|
17
|
-
const stringArray = ['x', 'y', 'z'];
|
|
18
|
-
const result = UniqueStringSetPayloadSchema.safeParse(stringArray);
|
|
19
|
-
// Parse succeeds for valid data
|
|
20
|
-
expect(result.data).toBeInstanceOf(Set);
|
|
21
|
-
expect(Array.from(result.data).sort()).toEqual([
|
|
22
|
-
'x',
|
|
23
|
-
'y',
|
|
24
|
-
'z',
|
|
25
|
-
]);
|
|
26
|
-
});
|
|
27
|
-
test('should handle duplicate strings in array', () => {
|
|
28
|
-
const stringArray = ['a', 'b', 'a', 'c', 'b'];
|
|
29
|
-
const result = UniqueStringSetPayloadSchema.safeParse(stringArray);
|
|
30
|
-
// Parse succeeds for valid data
|
|
31
|
-
expect(result.data).toBeInstanceOf(Set);
|
|
32
|
-
expect(Array.from(result.data).sort()).toEqual([
|
|
33
|
-
'a',
|
|
34
|
-
'b',
|
|
35
|
-
'c',
|
|
36
|
-
]);
|
|
37
|
-
});
|
|
38
|
-
test('should accept empty array', () => {
|
|
39
|
-
const result = UniqueStringSetPayloadSchema.safeParse([]);
|
|
40
|
-
// Parse succeeds for valid data
|
|
41
|
-
expect(result.data).toBeInstanceOf(Set);
|
|
42
|
-
expect(result.data.size).toBe(0);
|
|
43
|
-
});
|
|
44
|
-
test('should accept empty Set', () => {
|
|
45
|
-
const emptySet = new Set();
|
|
46
|
-
const result = UniqueStringSetPayloadSchema.safeParse(emptySet);
|
|
47
|
-
// Parse succeeds for valid data
|
|
48
|
-
expect(result.data).toBeInstanceOf(Set);
|
|
49
|
-
expect(result.data.size).toBe(0);
|
|
50
|
-
});
|
|
51
|
-
test('should reject non-string array elements', () => {
|
|
52
|
-
const result = UniqueStringSetPayloadSchema.safeParse(['a', 123, 'b']);
|
|
53
|
-
expect(result.success).toBe(false);
|
|
54
|
-
});
|
|
55
|
-
test('should reject non-array, non-Set values', () => {
|
|
56
|
-
expect(UniqueStringSetPayloadSchema.safeParse('string').success).toBe(false);
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
describe('UniqueStringPayloadSchema', () => {
|
|
60
|
-
test('should convert Set to array', () => {
|
|
61
|
-
const stringSet = new Set(['x', 'y', 'z']);
|
|
62
|
-
const result = UniqueStringPayloadSchema.safeParse(stringSet);
|
|
63
|
-
// Parse succeeds for valid data
|
|
64
|
-
expect(Array.isArray(result.data)).toBe(true);
|
|
65
|
-
expect(result.data.sort()).toEqual(['x', 'y', 'z']);
|
|
66
|
-
});
|
|
67
|
-
test('should convert array to unique array', () => {
|
|
68
|
-
const stringArray = ['a', 'b', 'a', 'c', 'b'];
|
|
69
|
-
const result = UniqueStringPayloadSchema.safeParse(stringArray);
|
|
70
|
-
// Parse succeeds for valid data
|
|
71
|
-
expect(Array.isArray(result.data)).toBe(true);
|
|
72
|
-
expect(result.data.sort()).toEqual(['a', 'b', 'c']);
|
|
73
|
-
});
|
|
74
|
-
test('should handle empty inputs', () => {
|
|
75
|
-
const emptySet = new Set();
|
|
76
|
-
const emptyArray = [];
|
|
77
|
-
const setResult = UniqueStringPayloadSchema.safeParse(emptySet);
|
|
78
|
-
const arrayResult = UniqueStringPayloadSchema.safeParse(emptyArray);
|
|
79
|
-
// Parse succeeds for valid data
|
|
80
|
-
// Parse succeeds for valid data
|
|
81
|
-
expect(setResult.data.length).toBe(0);
|
|
82
|
-
expect(arrayResult.data.length).toBe(0);
|
|
83
|
-
});
|
|
84
|
-
test('should maintain order from original Set', () => {
|
|
85
|
-
const orderedSet = new Set(['first', 'second', 'third']);
|
|
86
|
-
const result = UniqueStringPayloadSchema.safeParse(orderedSet);
|
|
87
|
-
// Parse succeeds for valid data
|
|
88
|
-
expect(result.data).toEqual(['first', 'second', 'third']);
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
});
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import { type } from 'arktype';
|
|
2
|
-
import { describe, expect, test } from 'vitest';
|
|
3
|
-
import {
|
|
4
|
-
UniqueStringSetPayloadSchema,
|
|
5
|
-
UniqueStringPayloadSchema,
|
|
6
|
-
} from './sets.js';
|
|
7
|
-
|
|
8
|
-
describe('Common Schema - Sets', () => {
|
|
9
|
-
describe('UniqueStringSetPayloadSchema', () => {
|
|
10
|
-
test('should accept Set of strings', () => {
|
|
11
|
-
const stringSet = new Set(['a', 'b', 'c']);
|
|
12
|
-
const result = UniqueStringSetPayloadSchema(stringSet);
|
|
13
|
-
|
|
14
|
-
expect(result).not.toBeInstanceOf(type.errors);
|
|
15
|
-
expect(result).toBeInstanceOf(Set);
|
|
16
|
-
expect(Array.from(result as Set<string>).sort()).toEqual(['a', 'b', 'c']);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
test('should accept array of strings and convert to Set', () => {
|
|
20
|
-
const stringArray = ['x', 'y', 'z'];
|
|
21
|
-
const result = UniqueStringSetPayloadSchema(stringArray);
|
|
22
|
-
|
|
23
|
-
expect(result).not.toBeInstanceOf(type.errors);
|
|
24
|
-
expect(result).toBeInstanceOf(Set);
|
|
25
|
-
expect(Array.from(result as Set<string>).sort()).toEqual(['x', 'y', 'z']);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
test('should handle duplicate strings in array', () => {
|
|
29
|
-
const stringArray = ['a', 'b', 'a', 'c', 'b'];
|
|
30
|
-
const result = UniqueStringSetPayloadSchema(stringArray);
|
|
31
|
-
|
|
32
|
-
expect(result).not.toBeInstanceOf(type.errors);
|
|
33
|
-
expect(result).toBeInstanceOf(Set);
|
|
34
|
-
expect(Array.from(result as Set<string>).sort()).toEqual(['a', 'b', 'c']);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
test('should accept empty array', () => {
|
|
38
|
-
const result = UniqueStringSetPayloadSchema([]);
|
|
39
|
-
|
|
40
|
-
expect(result).not.toBeInstanceOf(type.errors);
|
|
41
|
-
expect(result).toBeInstanceOf(Set);
|
|
42
|
-
expect((result as Set<string>).size).toBe(0);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
test('should accept empty Set', () => {
|
|
46
|
-
const emptySet = new Set<string>();
|
|
47
|
-
const result = UniqueStringSetPayloadSchema(emptySet);
|
|
48
|
-
|
|
49
|
-
expect(result).not.toBeInstanceOf(type.errors);
|
|
50
|
-
expect(result).toBeInstanceOf(Set);
|
|
51
|
-
expect((result as Set<string>).size).toBe(0);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
test('should reject non-string array elements', () => {
|
|
55
|
-
const result = UniqueStringSetPayloadSchema(['a', 123, 'b']);
|
|
56
|
-
expect(result).toBeInstanceOf(type.errors);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
test('should reject non-array, non-Set values', () => {
|
|
60
|
-
expect(UniqueStringSetPayloadSchema('string')).toBeInstanceOf(
|
|
61
|
-
type.errors
|
|
62
|
-
);
|
|
63
|
-
expect(UniqueStringSetPayloadSchema(123)).toBeInstanceOf(type.errors);
|
|
64
|
-
expect(UniqueStringSetPayloadSchema({})).toBeInstanceOf(type.errors);
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
describe('UniqueStringPayloadSchema', () => {
|
|
69
|
-
test('should convert Set to array', () => {
|
|
70
|
-
const stringSet = new Set(['x', 'y', 'z']);
|
|
71
|
-
const result = UniqueStringPayloadSchema(stringSet);
|
|
72
|
-
|
|
73
|
-
expect(result).not.toBeInstanceOf(type.errors);
|
|
74
|
-
expect(Array.isArray(result)).toBe(true);
|
|
75
|
-
expect((result as string[]).sort()).toEqual(['x', 'y', 'z']);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
test('should convert array to unique array', () => {
|
|
79
|
-
const stringArray = ['a', 'b', 'a', 'c', 'b'];
|
|
80
|
-
const result = UniqueStringPayloadSchema(stringArray);
|
|
81
|
-
|
|
82
|
-
expect(result).not.toBeInstanceOf(type.errors);
|
|
83
|
-
expect(Array.isArray(result)).toBe(true);
|
|
84
|
-
expect((result as string[]).sort()).toEqual(['a', 'b', 'c']);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
test('should handle empty inputs', () => {
|
|
88
|
-
const emptySet = new Set<string>();
|
|
89
|
-
const emptyArray: string[] = [];
|
|
90
|
-
|
|
91
|
-
const setResult = UniqueStringPayloadSchema(emptySet);
|
|
92
|
-
const arrayResult = UniqueStringPayloadSchema(emptyArray);
|
|
93
|
-
|
|
94
|
-
expect(setResult).not.toBeInstanceOf(type.errors);
|
|
95
|
-
expect(arrayResult).not.toBeInstanceOf(type.errors);
|
|
96
|
-
expect((setResult as string[]).length).toBe(0);
|
|
97
|
-
expect((arrayResult as string[]).length).toBe(0);
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
test('should maintain order from original Set', () => {
|
|
101
|
-
const orderedSet = new Set(['first', 'second', 'third']);
|
|
102
|
-
const result = UniqueStringPayloadSchema(orderedSet);
|
|
103
|
-
|
|
104
|
-
expect(result).not.toBeInstanceOf(type.errors);
|
|
105
|
-
expect(result).toEqual(['first', 'second', 'third']);
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
});
|