Skip to content

Commit 7a3851a

Browse files
committed
Add allowOther support to enum string type
1 parent b1d988d commit 7a3851a

File tree

4 files changed

+26
-28
lines changed

4 files changed

+26
-28
lines changed

packages/data-core/lib/schema/types.ts

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,30 @@
1-
export interface SchemaFieldString {
2-
type: 'string';
1+
interface FieldBase<T> {
2+
type: T;
33
'ui:widget'?: string;
44
label?: string | string[];
5-
enum?: [string, string][];
65
}
76

8-
export interface SchemaFieldNumber {
9-
type: 'number';
10-
'ui:widget'?: string;
11-
label?: string | string[];
12-
}
7+
export type SchemaFieldString =
8+
| (FieldBase<'string'> & { enum?: never; allowOther?: never })
9+
| (FieldBase<'string'> & {
10+
allowOther?: {
11+
type: 'string';
12+
};
13+
enum: [string, string][];
14+
});
1315

14-
export interface SchemaFieldJson {
15-
type: 'json';
16-
'ui:widget'?: string;
17-
label?: string;
18-
}
16+
export type SchemaFieldNumber = FieldBase<'number'>;
1917

20-
export interface SchemaFieldArray<I extends SchemaField = SchemaField> {
21-
type: 'array';
22-
'ui:widget'?: string;
23-
label?: string | string[];
18+
export type SchemaFieldJson = FieldBase<'json'>;
19+
20+
export interface SchemaFieldArray<I extends SchemaField = SchemaField>
21+
extends FieldBase<'array'> {
2422
minItems?: number;
2523
maxItems?: number;
2624
items: I;
2725
}
2826

29-
export interface SchemaFieldObject {
30-
type: 'object' | 'root';
31-
'ui:widget'?: string;
32-
label?: string | string[];
27+
export interface SchemaFieldObject extends FieldBase<'object' | 'root'> {
3328
properties: Record<string, SchemaField>;
3429
additionalProperties?: boolean;
3530
required?: string[];

packages/data-plugins/lib/collections/core.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Plugin, SchemaFieldObject } from '@stac-manager/data-core';
1+
import { Plugin, PluginEditSchema } from '@stac-manager/data-core';
22
import { emptyString2Null, fieldIf, null2EmptyString } from '../utils';
33

44
export class PluginCore extends Plugin {
@@ -10,7 +10,7 @@ export class PluginCore extends Plugin {
1010
this.isNew = !data?.id;
1111
}
1212

13-
editSchema(): SchemaFieldObject {
13+
editSchema(): PluginEditSchema {
1414
return {
1515
type: 'root',
1616
required: [
@@ -47,6 +47,9 @@ export class PluginCore extends Plugin {
4747
label: 'License',
4848
type: 'string',
4949
'ui:widget': 'tagger',
50+
allowOther: {
51+
type: 'string'
52+
},
5053
enum: [
5154
['Apache-2.0', 'Apache License 2.0'],
5255
['MIT', 'MIT License'],
@@ -136,7 +139,7 @@ export class PluginCore extends Plugin {
136139
minItems: 1,
137140
items: {
138141
type: 'object',
139-
required: ['rel', 'href'],
142+
required: ['rel', 'href', 'type'],
140143
properties: {
141144
href: {
142145
label: 'URL',

packages/data-plugins/lib/collections/kitchen-sink.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { Plugin, SchemaFieldObject } from '@stac-manager/data-core';
1+
import { Plugin, PluginEditSchema } from '@stac-manager/data-core';
22

33
export class PluginKitchenSink extends Plugin {
44
name = 'Kitchen Sink';
55

6-
editSchema(): SchemaFieldObject {
6+
editSchema(): PluginEditSchema {
77
return {
88
type: 'root',
99
properties: {

packages/data-plugins/lib/collections/meta.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Plugin, SchemaFieldObject } from '@stac-manager/data-core';
1+
import { Plugin, PluginEditSchema } from '@stac-manager/data-core';
22

33
export class PluginMeta extends Plugin {
44
name = 'CollectionsMeta';
@@ -7,7 +7,7 @@ export class PluginMeta extends Plugin {
77
// await new Promise((resolve) => setTimeout(resolve, 100));
88
// }
99

10-
editSchema(): SchemaFieldObject {
10+
editSchema(): PluginEditSchema {
1111
return {
1212
type: 'root',
1313
properties: {

0 commit comments

Comments
 (0)