Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"type": "module",
"workspaces": [
"packages/schema-dts-gen",
"packages/schema-dts-lib",
"packages/schema-dts"
]
}
68 changes: 44 additions & 24 deletions packages/schema-dts-gen/src/ts/helper_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,8 @@ import {arrayOf} from './util/arrayof.js';
import {withComments} from './util/comments.js';
import {typeUnion} from './util/union.js';

function IdPropertyNode() {
return withComments(
'IRI identifying the canonical address of this object.',
factory.createPropertySignature(
/* modifiers= */ [],
factory.createStringLiteral('@id'),
/* questionToken= */ undefined,
/* typeNode= */
factory.createTypeReferenceNode('string', /*typeArguments=*/ []),
),
);
}

function WithContextType(context: Context) {
// export type WithContext<T extends Thing> = T & { "@context": TYPE_NODE }
// export interface WithContext<T extends JsonLdObject | string> extends Exclude<T, string> { "@context": TYPE_NODE }
return withComments(
'Used at the top-level node to indicate the context for the JSON-LD ' +
'objects used. The context provided in this type is compatible ' +
Expand All @@ -39,10 +26,13 @@ function WithContextType(context: Context) {
factory.createTypeParameterDeclaration(
/*modifiers=*/ [],
'T' /*constraint=*/,
factory.createTypeReferenceNode(
'Thing',
/*typeArguments=*/ undefined,
),
factory.createUnionTypeNode([
factory.createTypeReferenceNode(
'JsonLdObject',
/*typeArguments=*/ undefined,
),
factory.createKeywordTypeNode(SyntaxKind.StringKeyword),
]),
),
],
factory.createIntersectionTypeNode([
Expand Down Expand Up @@ -105,6 +95,42 @@ export function SchemaValueReference(

export function HelperTypes(context: Context, {hasRole}: {hasRole: boolean}) {
return [
factory.createImportDeclaration(
/*modifiers=*/ [],
factory.createImportClause(
SyntaxKind.TypeKeyword,
/*name=*/ undefined,
factory.createNamedImports([
factory.createImportSpecifier(
/*isTypeOnly=*/ false,
/*propertyName=*/ undefined,
/*name=*/ factory.createIdentifier('JsonLdObject'),
),
factory.createImportSpecifier(
/*isTypeOnly=*/ false,
/*propertyName=*/ undefined,
/*name=*/ factory.createIdentifier('IdReference'),
),
]),
),
factory.createStringLiteral('schema-dts-lib'),
),
factory.createExportDeclaration(
/*modifiers=*/ [],
/*isTypeOnly=*/ true,
factory.createNamedExports([
factory.createExportSpecifier(
/*isTypeOnly=*/ false,
/*propertyName=*/ undefined,
/*name=*/ factory.createIdentifier('JsonLdObject'),
),
factory.createExportSpecifier(
/*isTypeOnly=*/ false,
/*propertyName=*/ undefined,
/*name=*/ factory.createIdentifier('IdReference'),
),
]),
),
WithContextType(context),
GraphType(context),
factory.createTypeAliasDeclaration(
Expand Down Expand Up @@ -143,12 +169,6 @@ export function HelperTypes(context: Context, {hasRole}: {hasRole: boolean}) {
),
),
),
factory.createTypeAliasDeclaration(
/*modifiers=*/ [],
IdReferenceName,
/*typeParameters=*/ [],
factory.createTypeLiteralNode([IdPropertyNode()]),
),
InputActionConstraintsType,
OutputActionConstraintsType,
WithActionConstraintsType,
Expand Down
10 changes: 4 additions & 6 deletions packages/schema-dts-gen/test/baselines/category_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,17 @@ test(`baseline_${basename(import.meta.url)}`, async () => {
);

expect(actual).toMatchInlineSnapshot(`
"/** Used at the top-level node to indicate the context for the JSON-LD objects used. The context provided in this type is compatible with the keys and URLs in the rest of this generated file. */
export type WithContext<T extends Thing> = T & {
"import type { JsonLdObject, IdReference } from "schema-dts-lib";
export type { JsonLdObject, IdReference };
/** Used at the top-level node to indicate the context for the JSON-LD objects used. The context provided in this type is compatible with the keys and URLs in the rest of this generated file. */
export type WithContext<T extends JsonLdObject | string> = T & {
"@context": "https://schema.org";
};
export interface Graph {
"@context": "https://schema.org";
"@graph": readonly Thing[];
}
type SchemaValue<T> = T | readonly T[];
type IdReference = {
/** IRI identifying the canonical address of this object. */
"@id": string;
};
type InputActionConstraints<T extends ActionBase> = Partial<{
[K in Exclude<keyof T, \`@\${string}\`> as \`\${string & K}-input\`]: PropertyValueSpecification | string;
}>;
Expand Down
10 changes: 4 additions & 6 deletions packages/schema-dts-gen/test/baselines/comments_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,17 @@ test(`baseline_${basename(import.meta.url)}`, async () => {
);

expect(actual).toMatchInlineSnapshot(`
"/** Used at the top-level node to indicate the context for the JSON-LD objects used. The context provided in this type is compatible with the keys and URLs in the rest of this generated file. */
export type WithContext<T extends Thing> = T & {
"import type { JsonLdObject, IdReference } from "schema-dts-lib";
export type { JsonLdObject, IdReference };
/** Used at the top-level node to indicate the context for the JSON-LD objects used. The context provided in this type is compatible with the keys and URLs in the rest of this generated file. */
export type WithContext<T extends JsonLdObject | string> = T & {
"@context": "https://schema.org";
};
export interface Graph {
"@context": "https://schema.org";
"@graph": readonly Thing[];
}
type SchemaValue<T> = T | readonly T[];
type IdReference = {
/** IRI identifying the canonical address of this object. */
"@id": string;
};
type InputActionConstraints<T extends ActionBase> = Partial<{
[K in Exclude<keyof T, \`@\${string}\`> as \`\${string & K}-input\`]: PropertyValueSpecification | string;
}>;
Expand Down
10 changes: 4 additions & 6 deletions packages/schema-dts-gen/test/baselines/data_type_union_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,17 @@ test(`baseline_${basename(import.meta.url)}`, async () => {
);

expect(actual).toMatchInlineSnapshot(`
"/** Used at the top-level node to indicate the context for the JSON-LD objects used. The context provided in this type is compatible with the keys and URLs in the rest of this generated file. */
export type WithContext<T extends Thing> = T & {
"import type { JsonLdObject, IdReference } from "schema-dts-lib";
export type { JsonLdObject, IdReference };
/** Used at the top-level node to indicate the context for the JSON-LD objects used. The context provided in this type is compatible with the keys and URLs in the rest of this generated file. */
export type WithContext<T extends JsonLdObject | string> = T & {
"@context": "https://schema.org";
};
export interface Graph {
"@context": "https://schema.org";
"@graph": readonly Thing[];
}
type SchemaValue<T> = T | readonly T[];
type IdReference = {
/** IRI identifying the canonical address of this object. */
"@id": string;
};
type InputActionConstraints<T extends ActionBase> = Partial<{
[K in Exclude<keyof T, \`@\${string}\`> as \`\${string & K}-input\`]: PropertyValueSpecification | string;
}>;
Expand Down
10 changes: 4 additions & 6 deletions packages/schema-dts-gen/test/baselines/default_ontology_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,17 @@ test(`baseline_${basename(import.meta.url)}`, async () => {
);

expect(actual).toMatchInlineSnapshot(`
"/** Used at the top-level node to indicate the context for the JSON-LD objects used. The context provided in this type is compatible with the keys and URLs in the rest of this generated file. */
export type WithContext<T extends Thing> = T & {
"import type { JsonLdObject, IdReference } from "schema-dts-lib";
export type { JsonLdObject, IdReference };
/** Used at the top-level node to indicate the context for the JSON-LD objects used. The context provided in this type is compatible with the keys and URLs in the rest of this generated file. */
export type WithContext<T extends JsonLdObject | string> = T & {
"@context": "https://schema.org";
};
export interface Graph {
"@context": "https://schema.org";
"@graph": readonly Thing[];
}
type SchemaValue<T> = T | readonly T[];
type IdReference = {
/** IRI identifying the canonical address of this object. */
"@id": string;
};
type InputActionConstraints<T extends ActionBase> = Partial<{
[K in Exclude<keyof T, \`@\${string}\`> as \`\${string & K}-input\`]: PropertyValueSpecification | string;
}>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,17 @@ test(`baseline_${basename(import.meta.url)}`, async () => {
);

expect(actual).toMatchInlineSnapshot(`
"/** Used at the top-level node to indicate the context for the JSON-LD objects used. The context provided in this type is compatible with the keys and URLs in the rest of this generated file. */
export type WithContext<T extends Thing> = T & {
"import type { JsonLdObject, IdReference } from "schema-dts-lib";
export type { JsonLdObject, IdReference };
/** Used at the top-level node to indicate the context for the JSON-LD objects used. The context provided in this type is compatible with the keys and URLs in the rest of this generated file. */
export type WithContext<T extends JsonLdObject | string> = T & {
"@context": "https://schema.org";
};
export interface Graph {
"@context": "https://schema.org";
"@graph": readonly Thing[];
}
type SchemaValue<T> = T | readonly T[];
type IdReference = {
/** IRI identifying the canonical address of this object. */
"@id": string;
};
type InputActionConstraints<T extends ActionBase> = Partial<{
[K in Exclude<keyof T, \`@\${string}\`> as \`\${string & K}-input\`]: PropertyValueSpecification | string;
}>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,17 @@ test(`baseline_${basename(import.meta.url)}`, async () => {
);

expect(actual).toMatchInlineSnapshot(`
"/** Used at the top-level node to indicate the context for the JSON-LD objects used. The context provided in this type is compatible with the keys and URLs in the rest of this generated file. */
export type WithContext<T extends Thing> = T & {
"import type { JsonLdObject, IdReference } from "schema-dts-lib";
export type { JsonLdObject, IdReference };
/** Used at the top-level node to indicate the context for the JSON-LD objects used. The context provided in this type is compatible with the keys and URLs in the rest of this generated file. */
export type WithContext<T extends JsonLdObject | string> = T & {
"@context": "https://schema.org";
};
export interface Graph {
"@context": "https://schema.org";
"@graph": readonly Thing[];
}
type SchemaValue<T> = T | readonly T[];
type IdReference = {
/** IRI identifying the canonical address of this object. */
"@id": string;
};
type InputActionConstraints<T extends ActionBase> = Partial<{
[K in Exclude<keyof T, \`@\${string}\`> as \`\${string & K}-input\`]: PropertyValueSpecification | string;
}>;
Expand Down
10 changes: 4 additions & 6 deletions packages/schema-dts-gen/test/baselines/enum_skipped_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,17 @@ test(`baseline_${basename(import.meta.url)}`, async () => {
);

expect(actual).toMatchInlineSnapshot(`
"/** Used at the top-level node to indicate the context for the JSON-LD objects used. The context provided in this type is compatible with the keys and URLs in the rest of this generated file. */
export type WithContext<T extends Thing> = T & {
"import type { JsonLdObject, IdReference } from "schema-dts-lib";
export type { JsonLdObject, IdReference };
/** Used at the top-level node to indicate the context for the JSON-LD objects used. The context provided in this type is compatible with the keys and URLs in the rest of this generated file. */
export type WithContext<T extends JsonLdObject | string> = T & {
"@context": "https://schema.org";
};
export interface Graph {
"@context": "https://schema.org";
"@graph": readonly Thing[];
}
type SchemaValue<T> = T | readonly T[];
type IdReference = {
/** IRI identifying the canonical address of this object. */
"@id": string;
};
type InputActionConstraints<T extends ActionBase> = Partial<{
[K in Exclude<keyof T, \`@\${string}\`> as \`\${string & K}-input\`]: PropertyValueSpecification | string;
}>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,17 @@ test(`baseline_${basename(import.meta.url)}`, async () => {
);

expect(actual).toMatchInlineSnapshot(`
"/** Used at the top-level node to indicate the context for the JSON-LD objects used. The context provided in this type is compatible with the keys and URLs in the rest of this generated file. */
export type WithContext<T extends Thing> = T & {
"import type { JsonLdObject, IdReference } from "schema-dts-lib";
export type { JsonLdObject, IdReference };
/** Used at the top-level node to indicate the context for the JSON-LD objects used. The context provided in this type is compatible with the keys and URLs in the rest of this generated file. */
export type WithContext<T extends JsonLdObject | string> = T & {
"@context": "https://schema.org";
};
export interface Graph {
"@context": "https://schema.org";
"@graph": readonly Thing[];
}
type SchemaValue<T> = T | readonly T[];
type IdReference = {
/** IRI identifying the canonical address of this object. */
"@id": string;
};
type InputActionConstraints<T extends ActionBase> = Partial<{
[K in Exclude<keyof T, \`@\${string}\`> as \`\${string & K}-input\`]: PropertyValueSpecification | string;
}>;
Expand Down
10 changes: 4 additions & 6 deletions packages/schema-dts-gen/test/baselines/inheritance_one_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,17 @@ test(`baseline_${basename(import.meta.url)}`, async () => {
);

expect(actual).toMatchInlineSnapshot(`
"/** Used at the top-level node to indicate the context for the JSON-LD objects used. The context provided in this type is compatible with the keys and URLs in the rest of this generated file. */
export type WithContext<T extends Thing> = T & {
"import type { JsonLdObject, IdReference } from "schema-dts-lib";
export type { JsonLdObject, IdReference };
/** Used at the top-level node to indicate the context for the JSON-LD objects used. The context provided in this type is compatible with the keys and URLs in the rest of this generated file. */
export type WithContext<T extends JsonLdObject | string> = T & {
"@context": "https://schema.org";
};
export interface Graph {
"@context": "https://schema.org";
"@graph": readonly Thing[];
}
type SchemaValue<T> = T | readonly T[];
type IdReference = {
/** IRI identifying the canonical address of this object. */
"@id": string;
};
type InputActionConstraints<T extends ActionBase> = Partial<{
[K in Exclude<keyof T, \`@\${string}\`> as \`\${string & K}-input\`]: PropertyValueSpecification | string;
}>;
Expand Down
10 changes: 4 additions & 6 deletions packages/schema-dts-gen/test/baselines/nested_datatype_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,17 @@ test(`baseline_${basename(import.meta.url)}`, async () => {
);

expect(actual).toMatchInlineSnapshot(`
"/** Used at the top-level node to indicate the context for the JSON-LD objects used. The context provided in this type is compatible with the keys and URLs in the rest of this generated file. */
export type WithContext<T extends Thing> = T & {
"import type { JsonLdObject, IdReference } from "schema-dts-lib";
export type { JsonLdObject, IdReference };
/** Used at the top-level node to indicate the context for the JSON-LD objects used. The context provided in this type is compatible with the keys and URLs in the rest of this generated file. */
export type WithContext<T extends JsonLdObject | string> = T & {
"@context": "https://schema.org";
};
export interface Graph {
"@context": "https://schema.org";
"@graph": readonly Thing[];
}
type SchemaValue<T> = T | readonly T[];
type IdReference = {
/** IRI identifying the canonical address of this object. */
"@id": string;
};
type InputActionConstraints<T extends ActionBase> = Partial<{
[K in Exclude<keyof T, \`@\${string}\`> as \`\${string & K}-input\`]: PropertyValueSpecification | string;
}>;
Expand Down
Loading
Loading