@bscotch/yy 0.6.1 → 0.7.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/LICENSE.md +23 -0
- package/dist/Yy.d.ts +6859 -6829
- package/dist/Yy.d.ts.map +1 -1
- package/dist/Yy.js +247 -246
- package/dist/Yy.js.map +1 -1
- package/dist/Yy.parse.d.ts +5 -5
- package/dist/Yy.parse.js +240 -240
- package/dist/Yy.stringify.d.ts +6 -6
- package/dist/Yy.stringify.js +129 -129
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +16 -16
- package/dist/index.d.ts +8 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -8
- package/dist/index.js.map +1 -1
- package/dist/types/YyBase.d.ts +46 -46
- package/dist/types/YyBase.js +37 -37
- package/dist/types/YyObject.d.ts +454 -462
- package/dist/types/YyObject.d.ts.map +1 -1
- package/dist/types/YyObject.js +108 -108
- package/dist/types/YyRoom.d.ts +1474 -1507
- package/dist/types/YyRoom.d.ts.map +1 -1
- package/dist/types/YyRoom.js +155 -155
- package/dist/types/YyScript.d.ts +45 -47
- package/dist/types/YyScript.d.ts.map +1 -1
- package/dist/types/YyScript.js +8 -8
- package/dist/types/YySound.d.ts +107 -115
- package/dist/types/YySound.d.ts.map +1 -1
- package/dist/types/YySound.js +61 -61
- package/dist/types/YySprite.d.ts +5438 -5446
- package/dist/types/YySprite.d.ts.map +1 -1
- package/dist/types/YySprite.js +417 -417
- package/dist/types/YySprite.lib.d.ts +221 -215
- package/dist/types/YySprite.lib.d.ts.map +1 -1
- package/dist/types/YySprite.lib.js +35 -35
- package/dist/types/Yyp.d.ts +604 -604
- package/dist/types/Yyp.js +101 -101
- package/dist/types/utility.d.ts +64 -64
- package/dist/types/utility.js +104 -104
- package/package.json +16 -11
- package/dist/Schema.d.ts +0 -1
- package/dist/Schema.d.ts.map +0 -1
- package/dist/Schema.js +0 -2
- package/dist/Schema.js.map +0 -1
package/dist/types/Yyp.js
CHANGED
|
@@ -1,102 +1,102 @@
|
|
|
1
|
-
// Generated by ts-to-zod
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
import { bigNumber } from './utility.js';
|
|
4
|
-
export const yypResourceIdSchema = z.object({
|
|
5
|
-
name: z.string(),
|
|
6
|
-
path: z.string(),
|
|
7
|
-
});
|
|
8
|
-
const yypResourceSchema = z.object({
|
|
9
|
-
id: yypResourceIdSchema,
|
|
10
|
-
order: z.number().default(0),
|
|
11
|
-
});
|
|
12
|
-
const yypOptionSchema = z.object({
|
|
13
|
-
ConfigValues: z.record(z.record(z.string())).optional(),
|
|
14
|
-
name: z.string(),
|
|
15
|
-
path: z.string(),
|
|
16
|
-
});
|
|
17
|
-
const yypConfigSchema = z.lazy(() => z.object({
|
|
18
|
-
name: z.string(),
|
|
19
|
-
children: z.array(yypConfigSchema),
|
|
20
|
-
}));
|
|
21
|
-
const yypRoomOrderNodeSchema = z.object({
|
|
22
|
-
roomId: z.object({
|
|
23
|
-
name: z.string(),
|
|
24
|
-
/** rooms/{name}/{name}.yy */
|
|
25
|
-
path: z.string(),
|
|
26
|
-
}),
|
|
27
|
-
});
|
|
28
|
-
const yypFolderSchema = z.object({
|
|
29
|
-
name: z.string(),
|
|
30
|
-
tags: z.array(z.string()).optional(),
|
|
31
|
-
folderPath: z.string(),
|
|
32
|
-
order: z.number().default(1),
|
|
33
|
-
resourceType: z.literal('GMFolder').default('GMFolder'),
|
|
34
|
-
resourceVersion: z.literal('1.0').default('1.0'),
|
|
35
|
-
});
|
|
36
|
-
export const yypAudioGroupSchema = z.object({
|
|
37
|
-
ConfigValues: z.record(z.record(z.string())).optional(),
|
|
38
|
-
name: z.string(),
|
|
39
|
-
targets: bigNumber().default(461609314234257646n),
|
|
40
|
-
resourceType: z.literal('GMAudioGroup').default('GMAudioGroup'),
|
|
41
|
-
resourceVersion: z.literal('1.3').default('1.3'),
|
|
42
|
-
});
|
|
43
|
-
export const yypTextureGroupSchema = z.object({
|
|
44
|
-
ConfigValues: z.record(z.record(z.string())).optional(),
|
|
45
|
-
name: z.string(),
|
|
46
|
-
groupParent: z
|
|
47
|
-
.object({
|
|
48
|
-
name: z.string(),
|
|
49
|
-
path: z.string(),
|
|
50
|
-
})
|
|
51
|
-
.nullable()
|
|
52
|
-
.default(null),
|
|
53
|
-
isScaled: z.boolean().default(true),
|
|
54
|
-
compressFormat: z.string().optional(),
|
|
55
|
-
autocrop: z.boolean().default(true),
|
|
56
|
-
border: z.number().default(2),
|
|
57
|
-
mipsToGenerate: z.number().default(0),
|
|
58
|
-
targets: bigNumber().default(-1n),
|
|
59
|
-
loadType: z.enum(['default', 'dynamicpages']).optional(),
|
|
60
|
-
directory: z.string().optional(),
|
|
61
|
-
resourceType: z.literal('GMTextureGroup').default('GMTextureGroup'),
|
|
62
|
-
resourceVersion: z.literal('1.3').default('1.3'),
|
|
63
|
-
});
|
|
64
|
-
const yypIncludedFileSchema = z.object({
|
|
65
|
-
ConfigValues: z
|
|
66
|
-
.record(z.object({
|
|
67
|
-
CopyToMask: z.string(),
|
|
68
|
-
}))
|
|
69
|
-
.optional(),
|
|
70
|
-
/** The name of the file, including extension, without the path */
|
|
71
|
-
name: z.string(),
|
|
72
|
-
CopyToMask: bigNumber().default(-1),
|
|
73
|
-
/** `datafiles/${subdir}` */
|
|
74
|
-
filePath: z.string(),
|
|
75
|
-
resourceType: z.literal('GMIncludedFile').default('GMIncludedFile'),
|
|
76
|
-
resourceVersion: z.literal('1.0').default('1.0'),
|
|
77
|
-
});
|
|
78
|
-
export const yypSchema = z.object({
|
|
79
|
-
name: z.string(),
|
|
80
|
-
resourceType: z.literal('GMProject').default('GMProject'),
|
|
81
|
-
resources: z.array(yypResourceSchema).default([]),
|
|
82
|
-
RoomOrderNodes: z.array(yypRoomOrderNodeSchema).default([]),
|
|
83
|
-
Options: z.array(yypOptionSchema).default([]),
|
|
84
|
-
isDnDProject: z.boolean().optional(),
|
|
85
|
-
defaultScriptType: z.number().default(1),
|
|
86
|
-
isEcma: z.boolean().default(false),
|
|
87
|
-
tutorialPath: z.string().optional(),
|
|
88
|
-
configs: z.object({
|
|
89
|
-
name: z.literal('Default').default('Default'),
|
|
90
|
-
children: z.array(yypConfigSchema).default([]),
|
|
91
|
-
}),
|
|
92
|
-
Folders: z.array(yypFolderSchema).default([]),
|
|
93
|
-
AudioGroups: z.array(yypAudioGroupSchema).default([]),
|
|
94
|
-
TextureGroups: z.array(yypTextureGroupSchema).default([]),
|
|
95
|
-
IncludedFiles: z.array(yypIncludedFileSchema).default([]),
|
|
96
|
-
MetaData: z.object({
|
|
97
|
-
IDEVersion: z.string(),
|
|
98
|
-
}),
|
|
99
|
-
resourceVersion: z.string(),
|
|
100
|
-
tags: z.array(z.string()).optional(),
|
|
101
|
-
});
|
|
1
|
+
// Generated by ts-to-zod
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { bigNumber } from './utility.js';
|
|
4
|
+
export const yypResourceIdSchema = z.object({
|
|
5
|
+
name: z.string(),
|
|
6
|
+
path: z.string(),
|
|
7
|
+
});
|
|
8
|
+
const yypResourceSchema = z.object({
|
|
9
|
+
id: yypResourceIdSchema,
|
|
10
|
+
order: z.number().default(0),
|
|
11
|
+
});
|
|
12
|
+
const yypOptionSchema = z.object({
|
|
13
|
+
ConfigValues: z.record(z.record(z.string())).optional(),
|
|
14
|
+
name: z.string(),
|
|
15
|
+
path: z.string(),
|
|
16
|
+
});
|
|
17
|
+
const yypConfigSchema = z.lazy(() => z.object({
|
|
18
|
+
name: z.string(),
|
|
19
|
+
children: z.array(yypConfigSchema),
|
|
20
|
+
}));
|
|
21
|
+
const yypRoomOrderNodeSchema = z.object({
|
|
22
|
+
roomId: z.object({
|
|
23
|
+
name: z.string(),
|
|
24
|
+
/** rooms/{name}/{name}.yy */
|
|
25
|
+
path: z.string(),
|
|
26
|
+
}),
|
|
27
|
+
});
|
|
28
|
+
const yypFolderSchema = z.object({
|
|
29
|
+
name: z.string(),
|
|
30
|
+
tags: z.array(z.string()).optional(),
|
|
31
|
+
folderPath: z.string(),
|
|
32
|
+
order: z.number().default(1),
|
|
33
|
+
resourceType: z.literal('GMFolder').default('GMFolder'),
|
|
34
|
+
resourceVersion: z.literal('1.0').default('1.0'),
|
|
35
|
+
});
|
|
36
|
+
export const yypAudioGroupSchema = z.object({
|
|
37
|
+
ConfigValues: z.record(z.record(z.string())).optional(),
|
|
38
|
+
name: z.string(),
|
|
39
|
+
targets: bigNumber().default(461609314234257646n),
|
|
40
|
+
resourceType: z.literal('GMAudioGroup').default('GMAudioGroup'),
|
|
41
|
+
resourceVersion: z.literal('1.3').default('1.3'),
|
|
42
|
+
});
|
|
43
|
+
export const yypTextureGroupSchema = z.object({
|
|
44
|
+
ConfigValues: z.record(z.record(z.string())).optional(),
|
|
45
|
+
name: z.string(),
|
|
46
|
+
groupParent: z
|
|
47
|
+
.object({
|
|
48
|
+
name: z.string(),
|
|
49
|
+
path: z.string(),
|
|
50
|
+
})
|
|
51
|
+
.nullable()
|
|
52
|
+
.default(null),
|
|
53
|
+
isScaled: z.boolean().default(true),
|
|
54
|
+
compressFormat: z.string().optional(),
|
|
55
|
+
autocrop: z.boolean().default(true),
|
|
56
|
+
border: z.number().default(2),
|
|
57
|
+
mipsToGenerate: z.number().default(0),
|
|
58
|
+
targets: bigNumber().default(-1n),
|
|
59
|
+
loadType: z.enum(['default', 'dynamicpages']).optional(),
|
|
60
|
+
directory: z.string().optional(),
|
|
61
|
+
resourceType: z.literal('GMTextureGroup').default('GMTextureGroup'),
|
|
62
|
+
resourceVersion: z.literal('1.3').default('1.3'),
|
|
63
|
+
});
|
|
64
|
+
const yypIncludedFileSchema = z.object({
|
|
65
|
+
ConfigValues: z
|
|
66
|
+
.record(z.object({
|
|
67
|
+
CopyToMask: z.string(),
|
|
68
|
+
}))
|
|
69
|
+
.optional(),
|
|
70
|
+
/** The name of the file, including extension, without the path */
|
|
71
|
+
name: z.string(),
|
|
72
|
+
CopyToMask: bigNumber().default(-1),
|
|
73
|
+
/** `datafiles/${subdir}` */
|
|
74
|
+
filePath: z.string(),
|
|
75
|
+
resourceType: z.literal('GMIncludedFile').default('GMIncludedFile'),
|
|
76
|
+
resourceVersion: z.literal('1.0').default('1.0'),
|
|
77
|
+
});
|
|
78
|
+
export const yypSchema = z.object({
|
|
79
|
+
name: z.string(),
|
|
80
|
+
resourceType: z.literal('GMProject').default('GMProject'),
|
|
81
|
+
resources: z.array(yypResourceSchema).default([]),
|
|
82
|
+
RoomOrderNodes: z.array(yypRoomOrderNodeSchema).default([]),
|
|
83
|
+
Options: z.array(yypOptionSchema).default([]),
|
|
84
|
+
isDnDProject: z.boolean().optional(),
|
|
85
|
+
defaultScriptType: z.number().default(1),
|
|
86
|
+
isEcma: z.boolean().default(false),
|
|
87
|
+
tutorialPath: z.string().optional(),
|
|
88
|
+
configs: z.object({
|
|
89
|
+
name: z.literal('Default').default('Default'),
|
|
90
|
+
children: z.array(yypConfigSchema).default([]),
|
|
91
|
+
}),
|
|
92
|
+
Folders: z.array(yypFolderSchema).default([]),
|
|
93
|
+
AudioGroups: z.array(yypAudioGroupSchema).default([]),
|
|
94
|
+
TextureGroups: z.array(yypTextureGroupSchema).default([]),
|
|
95
|
+
IncludedFiles: z.array(yypIncludedFileSchema).default([]),
|
|
96
|
+
MetaData: z.object({
|
|
97
|
+
IDEVersion: z.string(),
|
|
98
|
+
}),
|
|
99
|
+
resourceVersion: z.string(),
|
|
100
|
+
tags: z.array(z.string()).optional(),
|
|
101
|
+
});
|
|
102
102
|
//# sourceMappingURL=Yyp.js.map
|
package/dist/types/utility.d.ts
CHANGED
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { YyResourceType } from './YyBase.js';
|
|
3
|
-
import { YypResourceId } from './Yyp.js';
|
|
4
|
-
export declare function randomString(length?: number): string;
|
|
5
|
-
export declare class FixedNumber extends Number {
|
|
6
|
-
readonly digits: number;
|
|
7
|
-
constructor(value: number | FixedNumber, digits?: number);
|
|
8
|
-
[Symbol.toPrimitive](hint: 'number' | 'default'): number;
|
|
9
|
-
[Symbol.toPrimitive](hint: 'string'): string;
|
|
10
|
-
toString(): string;
|
|
11
|
-
toJSON(): number;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* A wrapper that transforms the wrapped value to `undefined` and marks it as optional.
|
|
15
|
-
* Useful for fields you want to provide for extra
|
|
16
|
-
* information when transforming parents, since the
|
|
17
|
-
* `z.input<>` inferred type will show this field,
|
|
18
|
-
* but that don't normally exist in the source data.
|
|
19
|
-
*/
|
|
20
|
-
export declare function hint<T extends z.ZodTypeAny>(schema: T): z.ZodEffects<z.ZodOptional<T>, undefined, T["_input"] | undefined>;
|
|
21
|
-
export declare function fixedNumber(schema?: z.ZodNumber, digits?: number): z.ZodEffects<z.ZodEffects<z.ZodNumber, number, number | FixedNumber>, FixedNumber, number | FixedNumber>;
|
|
22
|
-
/**
|
|
23
|
-
* Schema for a number or bigint cast to a bigint
|
|
24
|
-
*/
|
|
25
|
-
export declare function bigNumber(): z.ZodEffects<z.ZodUnion<[z.ZodNumber, z.ZodBigInt]>, bigint, number | bigint>;
|
|
26
|
-
/**
|
|
27
|
-
* Ensure that an object is initialized to an empty
|
|
28
|
-
* object, allowing for default fields to be populated.
|
|
29
|
-
*/
|
|
30
|
-
export declare function ensureObject<T extends z.ZodTypeAny>(obj: T): z.ZodEffects<T, T["_output"], unknown>;
|
|
31
|
-
/**
|
|
32
|
-
* Ensure that an array is initialized to an array with
|
|
33
|
-
* at least one element, allowing for defaults to be
|
|
34
|
-
* populated in each element.
|
|
35
|
-
*/
|
|
36
|
-
export declare function ensureObjects<T extends z.AnyZodObject>(obj: T, minItems?: number): z.ZodEffects<z.ZodArray<T, "many">, T["_output"][], unknown>;
|
|
37
|
-
/**
|
|
38
|
-
* Shorthand for a `ZodObject` instance that doesn't strip
|
|
39
|
-
* out any unknown keys, and that logs unexpected keys to
|
|
40
|
-
* the console.
|
|
41
|
-
*/
|
|
42
|
-
export declare function unstable<T extends z.ZodRawShape>(shape: T): z.ZodObject<T>;
|
|
43
|
-
export declare function getYyResourceId(yyType: YyResourceType, name: string): YypResourceId;
|
|
44
|
-
export declare function yyResourceIdSchemaGenerator(yyType: YyResourceType): z.ZodEffects<z.ZodEffects<z.ZodObject<{
|
|
45
|
-
/** Object name */
|
|
46
|
-
name: z.ZodString;
|
|
47
|
-
/** Object resource path, e.g. "objects/{name}/{name}.yy" */
|
|
48
|
-
path: z.ZodString;
|
|
49
|
-
}, "strip", z.ZodTypeAny, {
|
|
50
|
-
path: string;
|
|
51
|
-
name: string;
|
|
52
|
-
}, {
|
|
53
|
-
path: string;
|
|
54
|
-
name: string;
|
|
55
|
-
}>, {
|
|
56
|
-
path: string;
|
|
57
|
-
name: string;
|
|
58
|
-
}, {
|
|
59
|
-
path: string;
|
|
60
|
-
name: string;
|
|
61
|
-
}>, {
|
|
62
|
-
path: string;
|
|
63
|
-
name: string;
|
|
64
|
-
}, unknown>;
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { YyResourceType } from './YyBase.js';
|
|
3
|
+
import { YypResourceId } from './Yyp.js';
|
|
4
|
+
export declare function randomString(length?: number): string;
|
|
5
|
+
export declare class FixedNumber extends Number {
|
|
6
|
+
readonly digits: number;
|
|
7
|
+
constructor(value: number | FixedNumber, digits?: number);
|
|
8
|
+
[Symbol.toPrimitive](hint: 'number' | 'default'): number;
|
|
9
|
+
[Symbol.toPrimitive](hint: 'string'): string;
|
|
10
|
+
toString(): string;
|
|
11
|
+
toJSON(): number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* A wrapper that transforms the wrapped value to `undefined` and marks it as optional.
|
|
15
|
+
* Useful for fields you want to provide for extra
|
|
16
|
+
* information when transforming parents, since the
|
|
17
|
+
* `z.input<>` inferred type will show this field,
|
|
18
|
+
* but that don't normally exist in the source data.
|
|
19
|
+
*/
|
|
20
|
+
export declare function hint<T extends z.ZodTypeAny>(schema: T): z.ZodEffects<z.ZodOptional<T>, undefined, T["_input"] | undefined>;
|
|
21
|
+
export declare function fixedNumber(schema?: z.ZodNumber, digits?: number): z.ZodEffects<z.ZodEffects<z.ZodNumber, number, number | FixedNumber>, FixedNumber, number | FixedNumber>;
|
|
22
|
+
/**
|
|
23
|
+
* Schema for a number or bigint cast to a bigint
|
|
24
|
+
*/
|
|
25
|
+
export declare function bigNumber(): z.ZodEffects<z.ZodUnion<[z.ZodNumber, z.ZodBigInt]>, bigint, number | bigint>;
|
|
26
|
+
/**
|
|
27
|
+
* Ensure that an object is initialized to an empty
|
|
28
|
+
* object, allowing for default fields to be populated.
|
|
29
|
+
*/
|
|
30
|
+
export declare function ensureObject<T extends z.ZodTypeAny>(obj: T): z.ZodEffects<T, T["_output"], unknown>;
|
|
31
|
+
/**
|
|
32
|
+
* Ensure that an array is initialized to an array with
|
|
33
|
+
* at least one element, allowing for defaults to be
|
|
34
|
+
* populated in each element.
|
|
35
|
+
*/
|
|
36
|
+
export declare function ensureObjects<T extends z.AnyZodObject>(obj: T, minItems?: number): z.ZodEffects<z.ZodArray<T, "many">, T["_output"][], unknown>;
|
|
37
|
+
/**
|
|
38
|
+
* Shorthand for a `ZodObject` instance that doesn't strip
|
|
39
|
+
* out any unknown keys, and that logs unexpected keys to
|
|
40
|
+
* the console.
|
|
41
|
+
*/
|
|
42
|
+
export declare function unstable<T extends z.ZodRawShape>(shape: T): z.ZodObject<T>;
|
|
43
|
+
export declare function getYyResourceId(yyType: YyResourceType, name: string): YypResourceId;
|
|
44
|
+
export declare function yyResourceIdSchemaGenerator(yyType: YyResourceType): z.ZodEffects<z.ZodEffects<z.ZodObject<{
|
|
45
|
+
/** Object name */
|
|
46
|
+
name: z.ZodString;
|
|
47
|
+
/** Object resource path, e.g. "objects/{name}/{name}.yy" */
|
|
48
|
+
path: z.ZodString;
|
|
49
|
+
}, "strip", z.ZodTypeAny, {
|
|
50
|
+
path: string;
|
|
51
|
+
name: string;
|
|
52
|
+
}, {
|
|
53
|
+
path: string;
|
|
54
|
+
name: string;
|
|
55
|
+
}>, {
|
|
56
|
+
path: string;
|
|
57
|
+
name: string;
|
|
58
|
+
}, {
|
|
59
|
+
path: string;
|
|
60
|
+
name: string;
|
|
61
|
+
}>, {
|
|
62
|
+
path: string;
|
|
63
|
+
name: string;
|
|
64
|
+
}, unknown>;
|
|
65
65
|
//# sourceMappingURL=utility.d.ts.map
|
package/dist/types/utility.js
CHANGED
|
@@ -1,105 +1,105 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
export function randomString(length = 32) {
|
|
3
|
-
let a = '';
|
|
4
|
-
for (let i = 0; i < length; i++) {
|
|
5
|
-
a += '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz'[(Math.random() * 60) | 0];
|
|
6
|
-
}
|
|
7
|
-
return a;
|
|
8
|
-
}
|
|
9
|
-
export class FixedNumber extends Number {
|
|
10
|
-
digits;
|
|
11
|
-
constructor(value, digits = 1) {
|
|
12
|
-
super(value.valueOf());
|
|
13
|
-
this.digits = digits;
|
|
14
|
-
}
|
|
15
|
-
[Symbol.toPrimitive](hint) {
|
|
16
|
-
return hint === 'string' ? this.toString() : this.valueOf();
|
|
17
|
-
}
|
|
18
|
-
toString() {
|
|
19
|
-
return this.toFixed(this.digits);
|
|
20
|
-
}
|
|
21
|
-
toJSON() {
|
|
22
|
-
return this.valueOf();
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* A wrapper that transforms the wrapped value to `undefined` and marks it as optional.
|
|
27
|
-
* Useful for fields you want to provide for extra
|
|
28
|
-
* information when transforming parents, since the
|
|
29
|
-
* `z.input<>` inferred type will show this field,
|
|
30
|
-
* but that don't normally exist in the source data.
|
|
31
|
-
*/
|
|
32
|
-
export function hint(schema) {
|
|
33
|
-
return schema.optional().transform(() => undefined);
|
|
34
|
-
}
|
|
35
|
-
export function fixedNumber(schema = z.number(), digits = 1) {
|
|
36
|
-
const coercedToNumber = z.preprocess((arg) => arg instanceof FixedNumber || typeof arg === 'number' ? +arg : arg, schema);
|
|
37
|
-
return coercedToNumber.transform((value) => new FixedNumber(value, digits));
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Schema for a number or bigint cast to a bigint
|
|
41
|
-
*/
|
|
42
|
-
export function bigNumber() {
|
|
43
|
-
return z
|
|
44
|
-
.union([z.number(), z.bigint()])
|
|
45
|
-
.transform((value) => (typeof value === 'bigint' ? value : BigInt(value)));
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Ensure that an object is initialized to an empty
|
|
49
|
-
* object, allowing for default fields to be populated.
|
|
50
|
-
*/
|
|
51
|
-
export function ensureObject(obj) {
|
|
52
|
-
return z.preprocess((arg) => arg || {}, obj);
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Ensure that an array is initialized to an array with
|
|
56
|
-
* at least one element, allowing for defaults to be
|
|
57
|
-
* populated in each element.
|
|
58
|
-
*/
|
|
59
|
-
export function ensureObjects(obj, minItems = 1) {
|
|
60
|
-
return z.preprocess((arg) => {
|
|
61
|
-
arg = typeof arg === 'undefined' ? [] : arg;
|
|
62
|
-
if (Array.isArray(arg) && arg.length < minItems) {
|
|
63
|
-
const newItems = [...Array(Math.max(minItems - arg.length, 0))].map(() => ({}));
|
|
64
|
-
arg.push(...newItems);
|
|
65
|
-
}
|
|
66
|
-
return arg;
|
|
67
|
-
}, z.array(obj));
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Shorthand for a `ZodObject` instance that doesn't strip
|
|
71
|
-
* out any unknown keys, and that logs unexpected keys to
|
|
72
|
-
* the console.
|
|
73
|
-
*/
|
|
74
|
-
export function unstable(shape) {
|
|
75
|
-
return z.object(shape).catchall(z.unknown().superRefine((_arg, ctx) => {
|
|
76
|
-
console.log(`WARNING: Unexpected Key "${ctx.path.join('/')}"`);
|
|
77
|
-
}));
|
|
78
|
-
}
|
|
79
|
-
export function getYyResourceId(yyType, name) {
|
|
80
|
-
return {
|
|
81
|
-
name,
|
|
82
|
-
path: `${yyType}/${name}/${name}.yy`,
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
export function yyResourceIdSchemaGenerator(yyType) {
|
|
86
|
-
const pathFromName = (name) => `${yyType}/${name}/${name}.yy`;
|
|
87
|
-
return z.preprocess((arg) => {
|
|
88
|
-
if (arg === null || !['undefined', 'object'].includes(typeof arg)) {
|
|
89
|
-
return arg;
|
|
90
|
-
}
|
|
91
|
-
const objectId = arg === undefined ? {} : arg;
|
|
92
|
-
if (objectId.name && !objectId.path) {
|
|
93
|
-
objectId.path = pathFromName(objectId.name);
|
|
94
|
-
}
|
|
95
|
-
return objectId;
|
|
96
|
-
}, z
|
|
97
|
-
.object({
|
|
98
|
-
/** Object name */
|
|
99
|
-
name: z.string(),
|
|
100
|
-
/** Object resource path, e.g. "objects/{name}/{name}.yy" */
|
|
101
|
-
path: z.string(),
|
|
102
|
-
})
|
|
103
|
-
.refine((arg) => arg.path === pathFromName(arg.name)));
|
|
104
|
-
}
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export function randomString(length = 32) {
|
|
3
|
+
let a = '';
|
|
4
|
+
for (let i = 0; i < length; i++) {
|
|
5
|
+
a += '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz'[(Math.random() * 60) | 0];
|
|
6
|
+
}
|
|
7
|
+
return a;
|
|
8
|
+
}
|
|
9
|
+
export class FixedNumber extends Number {
|
|
10
|
+
digits;
|
|
11
|
+
constructor(value, digits = 1) {
|
|
12
|
+
super(value.valueOf());
|
|
13
|
+
this.digits = digits;
|
|
14
|
+
}
|
|
15
|
+
[Symbol.toPrimitive](hint) {
|
|
16
|
+
return hint === 'string' ? this.toString() : this.valueOf();
|
|
17
|
+
}
|
|
18
|
+
toString() {
|
|
19
|
+
return this.toFixed(this.digits);
|
|
20
|
+
}
|
|
21
|
+
toJSON() {
|
|
22
|
+
return this.valueOf();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* A wrapper that transforms the wrapped value to `undefined` and marks it as optional.
|
|
27
|
+
* Useful for fields you want to provide for extra
|
|
28
|
+
* information when transforming parents, since the
|
|
29
|
+
* `z.input<>` inferred type will show this field,
|
|
30
|
+
* but that don't normally exist in the source data.
|
|
31
|
+
*/
|
|
32
|
+
export function hint(schema) {
|
|
33
|
+
return schema.optional().transform(() => undefined);
|
|
34
|
+
}
|
|
35
|
+
export function fixedNumber(schema = z.number(), digits = 1) {
|
|
36
|
+
const coercedToNumber = z.preprocess((arg) => arg instanceof FixedNumber || typeof arg === 'number' ? +arg : arg, schema);
|
|
37
|
+
return coercedToNumber.transform((value) => new FixedNumber(value, digits));
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Schema for a number or bigint cast to a bigint
|
|
41
|
+
*/
|
|
42
|
+
export function bigNumber() {
|
|
43
|
+
return z
|
|
44
|
+
.union([z.number(), z.bigint()])
|
|
45
|
+
.transform((value) => (typeof value === 'bigint' ? value : BigInt(value)));
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Ensure that an object is initialized to an empty
|
|
49
|
+
* object, allowing for default fields to be populated.
|
|
50
|
+
*/
|
|
51
|
+
export function ensureObject(obj) {
|
|
52
|
+
return z.preprocess((arg) => arg || {}, obj);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Ensure that an array is initialized to an array with
|
|
56
|
+
* at least one element, allowing for defaults to be
|
|
57
|
+
* populated in each element.
|
|
58
|
+
*/
|
|
59
|
+
export function ensureObjects(obj, minItems = 1) {
|
|
60
|
+
return z.preprocess((arg) => {
|
|
61
|
+
arg = typeof arg === 'undefined' ? [] : arg;
|
|
62
|
+
if (Array.isArray(arg) && arg.length < minItems) {
|
|
63
|
+
const newItems = [...Array(Math.max(minItems - arg.length, 0))].map(() => ({}));
|
|
64
|
+
arg.push(...newItems);
|
|
65
|
+
}
|
|
66
|
+
return arg;
|
|
67
|
+
}, z.array(obj));
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Shorthand for a `ZodObject` instance that doesn't strip
|
|
71
|
+
* out any unknown keys, and that logs unexpected keys to
|
|
72
|
+
* the console.
|
|
73
|
+
*/
|
|
74
|
+
export function unstable(shape) {
|
|
75
|
+
return z.object(shape).catchall(z.unknown().superRefine((_arg, ctx) => {
|
|
76
|
+
console.log(`WARNING: Unexpected Key "${ctx.path.join('/')}"`);
|
|
77
|
+
}));
|
|
78
|
+
}
|
|
79
|
+
export function getYyResourceId(yyType, name) {
|
|
80
|
+
return {
|
|
81
|
+
name,
|
|
82
|
+
path: `${yyType}/${name}/${name}.yy`,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
export function yyResourceIdSchemaGenerator(yyType) {
|
|
86
|
+
const pathFromName = (name) => `${yyType}/${name}/${name}.yy`;
|
|
87
|
+
return z.preprocess((arg) => {
|
|
88
|
+
if (arg === null || !['undefined', 'object'].includes(typeof arg)) {
|
|
89
|
+
return arg;
|
|
90
|
+
}
|
|
91
|
+
const objectId = arg === undefined ? {} : arg;
|
|
92
|
+
if (objectId.name && !objectId.path) {
|
|
93
|
+
objectId.path = pathFromName(objectId.name);
|
|
94
|
+
}
|
|
95
|
+
return objectId;
|
|
96
|
+
}, z
|
|
97
|
+
.object({
|
|
98
|
+
/** Object name */
|
|
99
|
+
name: z.string(),
|
|
100
|
+
/** Object resource path, e.g. "objects/{name}/{name}.yy" */
|
|
101
|
+
path: z.string(),
|
|
102
|
+
})
|
|
103
|
+
.refine((arg) => arg.path === pathFromName(arg.name)));
|
|
104
|
+
}
|
|
105
105
|
//# sourceMappingURL=utility.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bscotch/yy",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Stringify, parse, read, and write GameMaker yy and yyp files.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"yy",
|
|
@@ -15,6 +15,12 @@
|
|
|
15
15
|
"read",
|
|
16
16
|
"write"
|
|
17
17
|
],
|
|
18
|
+
"homepage": "https://github.com/bscotch/stitch/tree/develop/packages/yy#readme",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "https://github.com/bscotch/stitch.git",
|
|
22
|
+
"directory": "packages/yy"
|
|
23
|
+
},
|
|
18
24
|
"type": "module",
|
|
19
25
|
"exports": {
|
|
20
26
|
".": {
|
|
@@ -28,30 +34,29 @@
|
|
|
28
34
|
"yy": "./dist/cli.js"
|
|
29
35
|
},
|
|
30
36
|
"dependencies": {
|
|
31
|
-
"
|
|
32
|
-
"
|
|
37
|
+
"@bscotch/utility": "^6.8.0",
|
|
38
|
+
"tslib": "^2.5.0",
|
|
39
|
+
"type-fest": "^3.6.1",
|
|
33
40
|
"uuid": "^9.0.0",
|
|
34
|
-
"zod": "^3.
|
|
35
|
-
"@bscotch/utility": "6.8.0"
|
|
41
|
+
"zod": "^3.21.2"
|
|
36
42
|
},
|
|
37
43
|
"devDependencies": {
|
|
38
44
|
"@types/chai": "^4.3.4",
|
|
39
45
|
"@types/mocha": "^10.0.1",
|
|
40
|
-
"@types/uuid": "^9.0.
|
|
46
|
+
"@types/uuid": "^9.0.1",
|
|
41
47
|
"chai": "^4.3.7",
|
|
42
48
|
"mocha": "^10.2.0",
|
|
43
|
-
"rimraf": "^4.1
|
|
44
|
-
"typescript": "
|
|
45
|
-
"@local/helpers": "0.0.0"
|
|
49
|
+
"rimraf": "^4.3.1",
|
|
50
|
+
"typescript": "5.0.1-rc"
|
|
46
51
|
},
|
|
47
52
|
"publishConfig": {
|
|
48
53
|
"access": "public"
|
|
49
54
|
},
|
|
50
55
|
"scripts": {
|
|
51
|
-
"build": "tsc
|
|
56
|
+
"build": "tsc --build",
|
|
52
57
|
"clean": "rimraf build dist *.tsbuildinfo **/*.tsbuildinfo",
|
|
53
58
|
"test": "mocha --config ../../config/.mocharc.cjs",
|
|
54
59
|
"test:dev": "mocha --config ../../config/.mocharc.cjs --forbid-only=false --parallel=false --timeout=9999999999",
|
|
55
|
-
"watch": "tsc
|
|
60
|
+
"watch": "tsc --build --watch"
|
|
56
61
|
}
|
|
57
62
|
}
|
package/dist/Schema.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=Schema.d.ts.map
|
package/dist/Schema.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../src/Schema.ts"],"names":[],"mappings":""}
|
package/dist/Schema.js
DELETED
package/dist/Schema.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Schema.js","sourceRoot":"","sources":["../src/Schema.ts"],"names":[],"mappings":""}
|