Skip to content

Commit de5145f

Browse files
committed
Unfreeze and refreeze
1 parent a60d016 commit de5145f

16 files changed

Lines changed: 342 additions & 109 deletions

package-lock.json

Lines changed: 17 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/core-json-ld/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"@msinternal/botframework-webchat-tsconfig": "development"
5353
},
5454
"devDependencies": {
55-
"@msinternal/botframework-webchat-tsconfig": "^0.0.0-0"
55+
"@msinternal/botframework-webchat-tsconfig": "^0.0.0-0",
56+
"type-fest": "^5.6.0"
5657
}
5758
}

packages/core-json-ld/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,4 @@ export {
4747

4848
export { default as isOfType } from './isOfType.js';
4949
export { jsonLinkedDataSchema, type JSONLinkedDataInput, type JSONLinkedDataOutput } from './JSONLinkedData.js';
50+
export { default as deepFreeze } from './private/deepFreeze.js';

packages/core-json-ld/src/orgSchema/Action.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { intersect, lazy, object, parser, string, type GenericSchema } from 'valibot';
2-
import { actionStatusSchema, type ActionStatusInput, type ActionStatusOutput } from './ActionStatus';
1+
import { intersect, lazy, object, parser, pipe, readonly, string, transform, type GenericSchema } from 'valibot';
32
import jsonLinkedDataProperty from '../private/jsonLinkedDataProperty';
3+
import { actionStatusSchema, type ActionStatusInput, type ActionStatusOutput } from './ActionStatus';
44
import { projectSchema, type ProjectInput, type ProjectOutput } from './Project';
55
import { thingSchema, type ThingInput, type ThingOutput } from './Thing';
66
import { userReviewSchema, type UserReviewInput, type UserReviewOutput } from './UserReview';
@@ -75,15 +75,24 @@ type ActionOutput = ThingOutput & {
7575
readonly result: readonly (ThingOutput | UserReviewOutput)[];
7676
};
7777

78-
const actionSchema: GenericSchema<ActionInput, ActionOutput> = intersect([
79-
lazy(() => thingSchema),
80-
object({
81-
actionOption: jsonLinkedDataProperty(string()),
82-
actionStatus: jsonLinkedDataProperty(actionStatusSchema),
83-
provider: jsonLinkedDataProperty(lazy(() => projectSchema)),
84-
result: jsonLinkedDataProperty(userReviewSchema)
85-
})
86-
]);
78+
const actionSchema: GenericSchema<ActionInput, ActionOutput> = pipe(
79+
intersect([
80+
pipe(
81+
lazy(() => thingSchema),
82+
// TODO: `intersect()` seems doesn't like frozen objects.
83+
// Related to https://github.com/open-circle/valibot/pull/1463.
84+
transform(value => ({ ...value }))
85+
),
86+
object({
87+
actionOption: jsonLinkedDataProperty(string()),
88+
actionStatus: jsonLinkedDataProperty(actionStatusSchema),
89+
provider: jsonLinkedDataProperty(lazy(() => projectSchema)),
90+
result: jsonLinkedDataProperty(userReviewSchema)
91+
})
92+
]),
93+
readonly(),
94+
transform(value => Object.freeze({ ...value }))
95+
);
8796

8897
/** @deprecated Use Valibot.parse(actionSchema) instead. Will be removed on or after 2028-04-23. */
8998
const parseAction: (action: ActionInput) => ActionOutput = parser(actionSchema);

packages/core-json-ld/src/orgSchema/Claim.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { intersect, lazy, object, parser, type GenericSchema } from 'valibot';
1+
import { intersect, lazy, object, parser, pipe, readonly, transform, type GenericSchema } from 'valibot';
2+
import jsonLinkedDataProperty from '../private/jsonLinkedDataProperty';
23
import { creativeWorkSchema, type CreativeWorkInput, type CreativeWorkOutput } from './CreativeWork';
34
import { projectSchema, type ProjectInput, type ProjectOutput } from './Project';
4-
import jsonLinkedDataProperty from '../private/jsonLinkedDataProperty';
55

66
/**
77
* A [Claim](https://schema.org/Claim) in Schema.org represents a specific, factually-oriented claim that could be the [itemReviewed](https://schema.org/itemReviewed) in a [ClaimReview](https://schema.org/ClaimReview). The content of a claim can be summarized with the [text](https://schema.org/text) property. Variations on well known claims can have their common identity indicated via [sameAs](https://schema.org/sameAs) links, and summarized with a name. Ideally, a [Claim](https://schema.org/Claim) description includes enough contextual information to minimize the risk of ambiguity or inclarity. In practice, many claims are better understood in the context in which they appear or the interpretations provided by claim reviews.
@@ -53,13 +53,22 @@ type ClaimOutput = CreativeWorkOutput & {
5353
readonly claimInterpreter: readonly ProjectOutput[];
5454
};
5555

56-
const claimSchema: GenericSchema<ClaimInput, ClaimOutput> = intersect([
57-
lazy(() => creativeWorkSchema),
58-
object({
59-
appearance: jsonLinkedDataProperty(lazy(() => creativeWorkSchema)),
60-
claimInterpreter: jsonLinkedDataProperty(lazy(() => projectSchema))
61-
})
62-
]);
56+
const claimSchema: GenericSchema<ClaimInput, ClaimOutput> = pipe(
57+
intersect([
58+
pipe(
59+
lazy(() => creativeWorkSchema),
60+
// TODO: `intersect()` seems doesn't like frozen objects.
61+
// Related to https://github.com/open-circle/valibot/pull/1463.
62+
transform(value => ({ ...value }))
63+
),
64+
object({
65+
appearance: jsonLinkedDataProperty(lazy(() => creativeWorkSchema)),
66+
claimInterpreter: jsonLinkedDataProperty(lazy(() => projectSchema))
67+
})
68+
]),
69+
readonly(),
70+
transform(value => Object.freeze({ ...value }))
71+
);
6372

6473
/** @deprecated Use Valibot.parse(claimSchema) instead. Will be removed on or after 2028-04-23. */
6574
const parseClaim: (claim: ClaimInput) => ClaimOutput = parser(claimSchema);

packages/core-json-ld/src/orgSchema/CreativeWork.ts

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
1-
import { intersect, lazy, number, object, parser, string, union, type GenericSchema } from 'valibot';
1+
import {
2+
intersect,
3+
lazy,
4+
number,
5+
object,
6+
parser,
7+
pipe,
8+
readonly,
9+
string,
10+
transform,
11+
union,
12+
type GenericSchema
13+
} from 'valibot';
14+
import jsonLinkedDataProperty from '../private/jsonLinkedDataProperty';
215
import { claimSchema } from './Claim';
316
import {
417
creativeWorkStatusSchema,
@@ -7,7 +20,6 @@ import {
720
} from './CreativeWorkStatus';
821
import { definedTermSchema, type DefinedTermInput, type DefinedTermOutput } from './DefinedTerm';
922
import { personSchema, type PersonInput, type PersonOutput } from './Person';
10-
import jsonLinkedDataProperty from '../private/jsonLinkedDataProperty';
1123
import {
1224
softwareSourceCodeSchema,
1325
type SoftwareSourceCodeInput,
@@ -187,22 +199,31 @@ let creativeWorkSchema_: GenericSchema<CreativeWorkInput, CreativeWorkOutput>;
187199

188200
// This is for cyclic dependency.
189201
// eslint-disable-next-line prefer-const
190-
creativeWorkSchema_ = intersect([
191-
lazy(() => thingSchema),
192-
object({
193-
abstract: jsonLinkedDataProperty(string()),
194-
author: jsonLinkedDataProperty(union([lazy(() => personSchema), string()])),
195-
citation: jsonLinkedDataProperty(lazy(() => claimSchema)),
196-
creativeWorkStatus: jsonLinkedDataProperty(creativeWorkStatusSchema),
197-
isBasedOn: jsonLinkedDataProperty(lazy(() => softwareSourceCodeSchema)),
198-
isPartOf: jsonLinkedDataProperty(lazy(() => creativeWorkSchema_)),
199-
keywords: jsonLinkedDataProperty(union([lazy(() => definedTermSchema), string()])),
200-
pattern: jsonLinkedDataProperty(lazy(() => definedTermSchema)),
201-
position: jsonLinkedDataProperty(union([number(), string()])),
202-
text: jsonLinkedDataProperty(string()),
203-
usageInfo: jsonLinkedDataProperty(lazy(() => creativeWorkSchema_))
204-
})
205-
]);
202+
creativeWorkSchema_ = pipe(
203+
intersect([
204+
pipe(
205+
lazy(() => thingSchema),
206+
// TODO: `intersect()` seems doesn't like frozen objects.
207+
// Related to https://github.com/open-circle/valibot/pull/1463.
208+
transform(value => ({ ...value }))
209+
),
210+
object({
211+
abstract: jsonLinkedDataProperty(string()),
212+
author: jsonLinkedDataProperty(union([lazy(() => personSchema), string()])),
213+
citation: jsonLinkedDataProperty(lazy(() => claimSchema)),
214+
creativeWorkStatus: jsonLinkedDataProperty(creativeWorkStatusSchema),
215+
isBasedOn: jsonLinkedDataProperty(lazy(() => softwareSourceCodeSchema)),
216+
isPartOf: jsonLinkedDataProperty(lazy(() => creativeWorkSchema_)),
217+
keywords: jsonLinkedDataProperty(union([lazy(() => definedTermSchema), string()])),
218+
pattern: jsonLinkedDataProperty(lazy(() => definedTermSchema)),
219+
position: jsonLinkedDataProperty(union([number(), string()])),
220+
text: jsonLinkedDataProperty(string()),
221+
usageInfo: jsonLinkedDataProperty(lazy(() => creativeWorkSchema_))
222+
})
223+
]),
224+
readonly(),
225+
transform(value => Object.freeze({ ...value }))
226+
);
206227

207228
// Constantize here, so we are exporting a const than a let.
208229
const creativeWorkSchema = creativeWorkSchema_;

packages/core-json-ld/src/orgSchema/DefinedTerm.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { intersect, lazy, object, parser, string, type GenericSchema } from 'valibot';
2-
import { thingSchema, type ThingInput, type ThingOutput } from './Thing';
1+
import { intersect, lazy, object, parser, pipe, readonly, string, transform, type GenericSchema } from 'valibot';
32
import jsonLinkedDataProperty from '../private/jsonLinkedDataProperty';
3+
import { thingSchema, type ThingInput, type ThingOutput } from './Thing';
44

55
/**
66
* A word, name, acronym, phrase, etc. with a formal definition. Often used in the context of category or subject classification, glossaries or dictionaries, product or creative work types, etc. Use the name property for the term being defined, use termCode if the term has an alpha-numeric code allocated, use description to provide the definition of the term.
@@ -48,13 +48,22 @@ type DefinedTermOutput = ThingOutput & {
4848
readonly termCode: readonly string[];
4949
};
5050

51-
const definedTermSchema: GenericSchema<DefinedTermInput, DefinedTermOutput> = intersect([
52-
lazy(() => thingSchema),
53-
object({
54-
inDefinedTermSet: jsonLinkedDataProperty(string()),
55-
termCode: jsonLinkedDataProperty(string())
56-
})
57-
]);
51+
const definedTermSchema: GenericSchema<DefinedTermInput, DefinedTermOutput> = pipe(
52+
intersect([
53+
pipe(
54+
lazy(() => thingSchema),
55+
// TODO: `intersect()` seems doesn't like frozen objects.
56+
// Related to https://github.com/open-circle/valibot/pull/1463.
57+
transform(value => ({ ...value }))
58+
),
59+
object({
60+
inDefinedTermSet: jsonLinkedDataProperty(string()),
61+
termCode: jsonLinkedDataProperty(string())
62+
})
63+
]),
64+
readonly(),
65+
transform(value => Object.freeze({ ...value }))
66+
);
5867

5968
/** @deprecated Use Valibot.parse(definedTermSchema) instead. Will be removed on or after 2028-04-23. */
6069
const parseDefinedTerm: (definedTerm: DefinedTermInput) => DefinedTermOutput = parser(definedTermSchema);

packages/core-json-ld/src/orgSchema/Person.ts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { intersect, lazy, object, parser, string, type GenericSchema } from 'valibot';
2-
import { thingSchema, type ThingInput, type ThingOutput } from './Thing';
1+
import { intersect, lazy, object, parser, pipe, readonly, string, transform, type GenericSchema } from 'valibot';
32
import jsonLinkedDataProperty from '../private/jsonLinkedDataProperty';
3+
import { thingSchema, type ThingInput, type ThingOutput } from './Thing';
44

55
/**
66
* A person (alive, dead, undead, or fictional).
@@ -38,14 +38,23 @@ type PersonOutput = ThingOutput & {
3838
readonly image: readonly string[];
3939
};
4040

41-
const personSchema: GenericSchema<PersonInput, PersonOutput> = intersect([
42-
lazy(() => thingSchema),
43-
object({
44-
description: jsonLinkedDataProperty(string()),
45-
image: jsonLinkedDataProperty(string()),
46-
name: jsonLinkedDataProperty(string())
47-
})
48-
]);
41+
const personSchema: GenericSchema<PersonInput, PersonOutput> = pipe(
42+
intersect([
43+
pipe(
44+
lazy(() => thingSchema),
45+
// TODO: `intersect()` seems doesn't like frozen objects.
46+
// Related to https://github.com/open-circle/valibot/pull/1463.
47+
transform(value => ({ ...value }))
48+
),
49+
object({
50+
description: jsonLinkedDataProperty(string()),
51+
image: jsonLinkedDataProperty(string()),
52+
name: jsonLinkedDataProperty(string())
53+
})
54+
]),
55+
readonly(),
56+
transform(value => Object.freeze({ ...value }))
57+
);
4958

5059
/** @deprecated Use Valibot.parse(personSchema) instead. Will be removed on or after 2028-04-23. */
5160
const parsePerson: (person: PersonInput) => PersonOutput = parser(personSchema);

packages/core-json-ld/src/orgSchema/Project.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { intersect, lazy, object, parser, string, type GenericSchema } from 'valibot';
1+
import { intersect, lazy, object, parser, pipe, readonly, string, transform, type GenericSchema } from 'valibot';
22
import jsonLinkedDataProperty from '../private/jsonLinkedDataProperty';
33
import { thingSchema, type ThingInput, type ThingOutput } from './Thing';
44

@@ -34,12 +34,21 @@ type ProjectOutput = ThingOutput & {
3434
readonly slogan: readonly string[];
3535
};
3636

37-
const projectSchema: GenericSchema<ProjectInput, ProjectOutput> = intersect([
38-
lazy(() => thingSchema),
39-
object({
40-
slogan: jsonLinkedDataProperty(string())
41-
})
42-
]);
37+
const projectSchema: GenericSchema<ProjectInput, ProjectOutput> = pipe(
38+
intersect([
39+
pipe(
40+
lazy(() => thingSchema),
41+
// TODO: `intersect()` seems doesn't like frozen objects.
42+
// Related to https://github.com/open-circle/valibot/pull/1463.
43+
transform(value => ({ ...value }))
44+
),
45+
object({
46+
slogan: jsonLinkedDataProperty(string())
47+
})
48+
]),
49+
readonly(),
50+
transform(value => Object.freeze({ ...value }))
51+
);
4352

4453
/** @deprecated Use Valibot.parse(projectSchema) instead. Will be removed on or after 2028-04-23. */
4554
const parseProject: (project: ProjectInput) => ProjectOutput = parser(projectSchema);

packages/core-json-ld/src/orgSchema/SoftwareSourceCode.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { intersect, lazy, object, string, type GenericSchema } from 'valibot';
2-
import { creativeWorkSchema, type CreativeWorkInput, type CreativeWorkOutput } from './CreativeWork';
1+
import { intersect, lazy, object, pipe, readonly, string, transform, type GenericSchema } from 'valibot';
32
import jsonLinkedDataProperty from '../private/jsonLinkedDataProperty';
3+
import { creativeWorkSchema, type CreativeWorkInput, type CreativeWorkOutput } from './CreativeWork';
44

55
/**
66
* Computer programming source code. Example: Full (compile ready) solutions, code snippet samples, scripts, templates.
@@ -34,11 +34,20 @@ type SoftwareSourceCodeOutput = CreativeWorkOutput & {
3434
readonly programmingLanguage: readonly string[];
3535
};
3636

37-
const softwareSourceCodeSchema: GenericSchema<SoftwareSourceCodeInput, SoftwareSourceCodeOutput> = intersect([
38-
lazy(() => creativeWorkSchema),
39-
object({
40-
programmingLanguage: jsonLinkedDataProperty(string())
41-
})
42-
]);
37+
const softwareSourceCodeSchema: GenericSchema<SoftwareSourceCodeInput, SoftwareSourceCodeOutput> = pipe(
38+
intersect([
39+
pipe(
40+
lazy(() => creativeWorkSchema),
41+
// TODO: `intersect()` seems doesn't like frozen objects.
42+
// Related to https://github.com/open-circle/valibot/pull/1463.
43+
transform(value => ({ ...value }))
44+
),
45+
object({
46+
programmingLanguage: jsonLinkedDataProperty(string())
47+
})
48+
]),
49+
readonly(),
50+
transform(value => Object.freeze({ ...value }))
51+
);
4352

4453
export { softwareSourceCodeSchema, type SoftwareSourceCodeInput, type SoftwareSourceCodeOutput };

0 commit comments

Comments
 (0)